Skip to content

Commit

Permalink
Add include_build_logs to google_cloudbuild_trigger (#6111) (#11866)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jun 10, 2022
1 parent f361293 commit b5cd00f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudbuild: Added `include_build_logs` to `google_cloudbuild_trigger`
```
31 changes: 31 additions & 0 deletions google/resource_cloudbuild_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ of the ignoredFiles globs, then we do not trigger a build.`,
Type: schema.TypeString,
},
},
"include_build_logs": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateEnum([]string{"INCLUDE_BUILD_LOGS_UNSPECIFIED", "INCLUDE_BUILD_LOGS_WITH_STATUS", ""}),
Description: `Build logs will be sent back to GitHub as part of the checkrun
result. Values can be INCLUDE_BUILD_LOGS_UNSPECIFIED or
INCLUDE_BUILD_LOGS_WITH_STATUS Possible values: ["INCLUDE_BUILD_LOGS_UNSPECIFIED", "INCLUDE_BUILD_LOGS_WITH_STATUS"]`,
},
"included_files": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1105,6 +1113,12 @@ func resourceCloudBuildTriggerCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("service_account"); !isEmptyValue(reflect.ValueOf(serviceAccountProp)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) {
obj["serviceAccount"] = serviceAccountProp
}
includeBuildLogsProp, err := expandCloudBuildTriggerIncludeBuildLogs(d.Get("include_build_logs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("include_build_logs"); !isEmptyValue(reflect.ValueOf(includeBuildLogsProp)) && (ok || !reflect.DeepEqual(v, includeBuildLogsProp)) {
obj["includeBuildLogs"] = includeBuildLogsProp
}
filenameProp, err := expandCloudBuildTriggerFilename(d.Get("filename"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1289,6 +1303,9 @@ func resourceCloudBuildTriggerRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("service_account", flattenCloudBuildTriggerServiceAccount(res["serviceAccount"], d, config)); err != nil {
return fmt.Errorf("Error reading Trigger: %s", err)
}
if err := d.Set("include_build_logs", flattenCloudBuildTriggerIncludeBuildLogs(res["includeBuildLogs"], d, config)); err != nil {
return fmt.Errorf("Error reading Trigger: %s", err)
}
if err := d.Set("filename", flattenCloudBuildTriggerFilename(res["filename"], d, config)); err != nil {
return fmt.Errorf("Error reading Trigger: %s", err)
}
Expand Down Expand Up @@ -1381,6 +1398,12 @@ func resourceCloudBuildTriggerUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("service_account"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) {
obj["serviceAccount"] = serviceAccountProp
}
includeBuildLogsProp, err := expandCloudBuildTriggerIncludeBuildLogs(d.Get("include_build_logs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("include_build_logs"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, includeBuildLogsProp)) {
obj["includeBuildLogs"] = includeBuildLogsProp
}
filenameProp, err := expandCloudBuildTriggerFilename(d.Get("filename"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1567,6 +1590,10 @@ func flattenCloudBuildTriggerServiceAccount(v interface{}, d *schema.ResourceDat
return v
}

func flattenCloudBuildTriggerIncludeBuildLogs(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudBuildTriggerFilename(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -2397,6 +2424,10 @@ func expandCloudBuildTriggerServiceAccount(v interface{}, d TerraformResourceDat
return v, nil
}

func expandCloudBuildTriggerIncludeBuildLogs(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCloudBuildTriggerFilename(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
26 changes: 26 additions & 0 deletions website/docs/r/cloudbuild_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ resource "google_project_iam_member" "logs_writer" {
member = "serviceAccount:${google_service_account.cloudbuild_service_account.email}"
}
```
## Example Usage - Cloudbuild Trigger Include Build Logs


```hcl
resource "google_cloudbuild_trigger" "include-build-logs-trigger" {
name = "include-build-logs-trigger"
filename = "cloudbuild.yaml"
github {
owner = "hashicorp"
name = "terraform-provider-google-beta"
push {
branch = "^main$"
}
}
include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=cloudbuild_trigger_pubsub_config&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -356,6 +375,13 @@ The following arguments are supported:
([PROJECT_NUM]@system.gserviceaccount.com) will be used instead.
Format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT_ID_OR_EMAIL}

* `include_build_logs` -
(Optional)
Build logs will be sent back to GitHub as part of the checkrun
result. Values can be INCLUDE_BUILD_LOGS_UNSPECIFIED or
INCLUDE_BUILD_LOGS_WITH_STATUS
Possible values are `INCLUDE_BUILD_LOGS_UNSPECIFIED` and `INCLUDE_BUILD_LOGS_WITH_STATUS`.

* `filename` -
(Optional)
Path, from the source root, to a file whose contents is used for the template.
Expand Down

0 comments on commit b5cd00f

Please sign in to comment.