I am attempting to dynamically generate blocks within a google_cloudbuild_trigger
resource "google_cloudbuild_trigger" "push_to_production" {
name = "cloudbuild-workers"
location = var.region
build {
dynamic "step" {
for_each = local.workers
id = "deploy-worker-${each.value}"
name = "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint = "gcloud"
args = ["run", "services", "update", each.value, "--platform=managed", "--image=$_WORKER_IMG", "--region=$_REGION", "--quiet"]
}
}
}
which should generate a list of build steps in my trigger for each of my worker configurations in local.workers. But what I'm seeing is errors for every attribute.
An argument named "id" is not expected here.
An argument named "name" is not expected here.
An argument named "entrypoint" is not expected here.
An argument named "args" is not expected here.
Is there something wrong with the way this is structured?
When using dynamic
block, there also has to be the content
, i.e:
resource "google_cloudbuild_trigger" "push_to_production" {
name = "cloudbuild-workers"
location = var.region
build {
dynamic "step" {
for_each = local.workers
content {
id = "deploy-worker-${step.value}"
name = "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint = "gcloud"
args = ["run", "services", "update", step.value, "--platform=managed", "--image=$_WORKER_IMG", "--region=$_REGION", "--quiet"]
}
}
}
}
Additionally, since you are using the dynamic
block, the each
object is basically swapped for an iterator. The iterator name usually corresponds to the name of the dynamic block if you don't provide the name for it.
However, even if this syntax is now correct, I don't think it will work, since the build
block for this resource says that the step
block is required.