From 6d7b1abacea506f802773cf47e4cd40a282ff24b Mon Sep 17 00:00:00 2001 From: Paddy Carver Date: Tue, 27 Nov 2018 02:04:30 -0800 Subject: [PATCH] Change cloudbuild trigger's args field to be a list. Right now, cloudbuild trigger's args field expects a string, then splits that string on spaces to get the list the API wants. This doesn't do proper quote escaping, however, and creates problems, which led to terraform-providers/terraform-provider-google#2101. This change turns it into a list instead of a string, so the user can take care of the parsing and escaping themselves. This is a breaking change, and should only go out with 2.0.0. We talked about the transition paths available to us, and this seemed the most reasonable. --- .../resources/resource_cloudbuild_build_trigger.go | 9 ++++++--- .../resource_cloudbuild_build_trigger_test.go | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/third_party/terraform/resources/resource_cloudbuild_build_trigger.go b/third_party/terraform/resources/resource_cloudbuild_build_trigger.go index 7b5daf704bdd..9f85e9dbf99f 100644 --- a/third_party/terraform/resources/resource_cloudbuild_build_trigger.go +++ b/third_party/terraform/resources/resource_cloudbuild_build_trigger.go @@ -64,8 +64,11 @@ func resourceCloudBuildTrigger() *schema.Resource { Optional: true, }, "args": &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeList, Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, }, }, }, @@ -294,7 +297,7 @@ func expandCloudbuildBuildTriggerBuild(d *schema.ResourceData) *cloudbuild.Build Name: d.Get(fmt.Sprintf("build.0.step.%d.name", s)).(string), } if v, ok := d.GetOk(fmt.Sprintf("build.0.step.%d.args", s)); ok { - step.Args = strings.Split(v.(string), " ") + step.Args = convertStringArr(v.([]interface{})) } build.Steps = append(build.Steps, step) } @@ -317,7 +320,7 @@ func flattenCloudbuildBuildTriggerBuild(d *schema.ResourceData, config *Config, for i, step := range b.Steps { steps[i] = map[string]interface{}{} steps[i]["name"] = step.Name - steps[i]["args"] = strings.Join(step.Args, " ") + steps[i]["args"] = convertStringArrToInterface(step.Args) } flattened[0]["step"] = steps } diff --git a/third_party/terraform/tests/resource_cloudbuild_build_trigger_test.go b/third_party/terraform/tests/resource_cloudbuild_build_trigger_test.go index 2489a8d4be0a..7a230c1bf34e 100644 --- a/third_party/terraform/tests/resource_cloudbuild_build_trigger_test.go +++ b/third_party/terraform/tests/resource_cloudbuild_build_trigger_test.go @@ -204,15 +204,15 @@ resource "google_cloudbuild_trigger" "build_trigger" { tags = ["team-a", "service-b"] step { name = "gcr.io/cloud-builders/gsutil" - args = "cp gs://mybucket/remotefile.zip localfile.zip " + args = ["cp", "gs://mybucket/remotefile.zip", "localfile.zip"] } step { name = "gcr.io/cloud-builders/go" - args = "build my_package" + args = ["build", "my_package"] } step { name = "gcr.io/cloud-builders/docker" - args = "build -t gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA -f Dockerfile ." + args = ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA", "-f", "Dockerfile ."] } } } @@ -253,19 +253,19 @@ resource "google_cloudbuild_trigger" "build_trigger" { tags = ["team-a", "service-b", "updated"] step { name = "gcr.io/cloud-builders/gsutil" - args = "cp gs://mybucket/remotefile.zip localfile-updated.zip " + args = ["cp", "gs://mybucket/remotefile.zip", "localfile-updated.zip "] } step { name = "gcr.io/cloud-builders/go" - args = "build my_package_updated" + args = ["build", "my_package_updated"] } step { name = "gcr.io/cloud-builders/docker" - args = "build -t gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA -f Dockerfile ." + args = ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA", "-f", "Dockerfile ."] } step { name = "gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA" - args = "test" + args = ["test"] } } }