Skip to content

Commit

Permalink
feat: allow configuration of initial terraform version in tf_cloudbui…
Browse files Browse the repository at this point in the history
…ld_builder (#189)

* allow configuration of default terraform version in tf_cloudbuild_builder

* fix split function parameter order
  • Loading branch information
daniel-cit committed Aug 11, 2022
1 parent c2d7b3f commit 4f38396
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/tf_cloudbuild_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
11 changes: 8 additions & 3 deletions modules/tf_cloudbuild_builder/cb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"]

Expand Down
6 changes: 6 additions & 0 deletions modules/tf_cloudbuild_builder/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f38396

Please sign in to comment.