Skip to content

Commit

Permalink
Change cloudbuild trigger's args field to be a list.
Browse files Browse the repository at this point in the history
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
hashicorp/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.
  • Loading branch information
paddycarver committed Nov 27, 2018
1 parent f6a2ac4 commit 6d7b1ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."]
}
}
}
Expand Down Expand Up @@ -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"]
}
}
}
Expand Down

0 comments on commit 6d7b1ab

Please sign in to comment.