diff --git a/modules/tf_cloudbuild_builder/README.md b/modules/tf_cloudbuild_builder/README.md index 00ced6f6..d53d5695 100644 --- a/modules/tf_cloudbuild_builder/README.md +++ b/modules/tf_cloudbuild_builder/README.md @@ -43,6 +43,7 @@ This module creates: | gar\_repo\_name | Name of the Google Artifact Repository where the Terraform builder images are stored. | `string` | `"tf-runners"` | no | | image\_name | Name of the image for the Terraform builder. | `string` | `"terraform"` | no | | project\_id | GCP project for Cloud Build trigger,workflow and scheduler. | `string` | n/a | yes | +| terraform\_version | The initial terraform version in semantic version format. | `string` | `"1.1.0"` | no | | trigger\_name | Name of the Cloud Build trigger building the Terraform builder. | `string` | `"tf-cloud-builder-build"` | no | | workflow\_name | Name of the workflow managing builds. | `string` | `"terraform-runner-workflow"` | no | | workflow\_region | The region of the workflow. | `string` | `"us-central1"` | no | diff --git a/modules/tf_cloudbuild_builder/cb.tf b/modules/tf_cloudbuild_builder/cb.tf index d35a5089..27581157 100644 --- a/modules/tf_cloudbuild_builder/cb.tf +++ b/modules/tf_cloudbuild_builder/cb.tf @@ -18,11 +18,16 @@ locals { gar_uri = "${var.gar_repo_location}-docker.pkg.dev/${var.project_id}/${local.gar_name}/${var.image_name}" cloudbuild_sa = coalesce(var.cloudbuild_sa, google_service_account.cb_sa[0].id) cloudbuild_sa_email = element(split("/", local.cloudbuild_sa), length(split("/", local.cloudbuild_sa)) - 1) + tf_version_parts = split(".", var.terraform_version) + tf_full_version = var.terraform_version + tf_minor_version = "${local.tf_version_parts[0]}.${local.tf_version_parts[1]}" + tf_major_version = local.tf_version_parts[0] + # substitutions available in the CB trigger tags_subst = { - "_TERRAFORM_FULL_VERSION" = "1.1.0", - "_TERRAFORM_MINOR_VERSION" = "1.1", - "_TERRAFORM_MAJOR_VERSION" = "1", + "_TERRAFORM_FULL_VERSION" = "${local.tf_full_version}", + "_TERRAFORM_MINOR_VERSION" = "${local.tf_minor_version}", + "_TERRAFORM_MAJOR_VERSION" = "${local.tf_major_version}", } img_tags_subst = [for tag in keys(local.tags_subst) : "${local.gar_uri}:v$${${tag}}"] diff --git a/modules/tf_cloudbuild_builder/variables.tf b/modules/tf_cloudbuild_builder/variables.tf index 0c72634f..019cefed 100644 --- a/modules/tf_cloudbuild_builder/variables.tf +++ b/modules/tf_cloudbuild_builder/variables.tf @@ -67,6 +67,12 @@ variable "gar_repo_location" { default = "us" } +variable "terraform_version" { + description = "The initial terraform version in semantic version format." + type = string + default = "1.1.0" +} + variable "image_name" { description = "Name of the image for the Terraform builder." type = string