Skip to content

Commit

Permalink
Add script field in cloud build trigger (#6701) (#12841)
Browse files Browse the repository at this point in the history
* added_support_for_script_attr

* added script field in tests

* fixing the tests

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 19, 2022
1 parent 3069f75 commit 3b5986b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6701.txt
@@ -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
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
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
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

0 comments on commit 3b5986b

Please sign in to comment.