Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script field in cloud build trigger #12841

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6701.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudbuild: added `script` field to `google_cloudbuild_trigger` resource
```
22 changes: 22 additions & 0 deletions google/resource_cloudbuild_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ The elements are of the form "KEY=VALUE" for the environment variable
Optional: true,
Description: `Unique identifier for this build step, used in 'wait_for' to
reference this build step as a dependency.`,
},
"script": {
Type: schema.TypeString,
Optional: true,
Description: `A shell script to be executed in the step.
When script is provided, the user cannot specify the entrypoint or args.`,
},
"secret_env": {
Type: schema.TypeList,
Expand Down Expand Up @@ -2172,6 +2178,7 @@ func flattenCloudBuildTriggerBuildStep(v interface{}, d *schema.ResourceData, co
"timing": flattenCloudBuildTriggerBuildStepTiming(original["timing"], d, config),
"volumes": flattenCloudBuildTriggerBuildStepVolumes(original["volumes"], d, config),
"wait_for": flattenCloudBuildTriggerBuildStepWaitFor(original["waitFor"], d, config),
"script": flattenCloudBuildTriggerBuildStepScript(original["script"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -2243,6 +2250,10 @@ func flattenCloudBuildTriggerBuildStepWaitFor(v interface{}, d *schema.ResourceD
return v
}

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

func flattenCloudBuildTriggerBuildArtifacts(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -3413,6 +3424,13 @@ func expandCloudBuildTriggerBuildStep(v interface{}, d TerraformResourceData, co
transformed["waitFor"] = transformedWaitFor
}

transformedScript, err := expandCloudBuildTriggerBuildStepScript(original["script"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedScript); val.IsValid() && !isEmptyValue(val) {
transformed["script"] = transformedScript
}

req = append(req, transformed)
}
return req, nil
Expand Down Expand Up @@ -3495,6 +3513,10 @@ func expandCloudBuildTriggerBuildStepWaitFor(v interface{}, d TerraformResourceD
return v, nil
}

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

func expandCloudBuildTriggerBuildArtifacts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
5 changes: 5 additions & 0 deletions google/resource_cloudbuild_trigger_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ resource "google_cloudbuild_trigger" "build-trigger" {
secret_env = ["MY_SECRET"]
}

step {
name = "ubuntu"
script = "echo hello" # using script field
}

source {
storage_source {
bucket = "mybucket"
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/cloudbuild_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ resource "google_cloudbuild_trigger" "build-trigger" {
secret_env = ["MY_SECRET"]
}

step {
name = "ubuntu"
script = "echo hello" # using script field
}

source {
storage_source {
bucket = "mybucket"
Expand Down Expand Up @@ -908,6 +913,11 @@ The following arguments are supported:
will start when all previous build steps in the `Build.Steps` list
have completed successfully.

* `script` -
(Optional)
A shell script to be executed in the step.
When script is provided, the user cannot specify the entrypoint or args.


<a name="nested_volumes"></a>The `volumes` block supports:

Expand Down