From 50091973deda2357dcdcb506f871ca25b9adc6e1 Mon Sep 17 00:00:00 2001 From: Andrew Newton Date: Thu, 28 Nov 2024 08:11:02 +0000 Subject: [PATCH 1/2] fix: fix null previous image tags being provided to rollback step --- .github/workflows/deploy-environment.yaml | 30 +++++++++++++------- infra/terraform/environments/dev/main.tf | 10 +++++++ infra/terraform/environments/dev/outputs.tf | 19 +++++++++++++ infra/terraform/environments/dev/provider.tf | 8 ++++++ infra/terraform/environments/int/main.tf | 10 +++++++ infra/terraform/environments/int/outputs.tf | 19 +++++++++++++ infra/terraform/environments/int/provider.tf | 8 ++++++ 7 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 infra/terraform/environments/dev/outputs.tf create mode 100644 infra/terraform/environments/int/outputs.tf diff --git a/.github/workflows/deploy-environment.yaml b/.github/workflows/deploy-environment.yaml index 355032e175..fc342ee06f 100644 --- a/.github/workflows/deploy-environment.yaml +++ b/.github/workflows/deploy-environment.yaml @@ -157,6 +157,26 @@ jobs: id: init run: terraform init -no-color -input=false -upgrade + - name: Get Current Versions from Terraform State + id: get_current_versions + run: | + terraform output -json > outputs.json || true + if [ -s outputs.json ] && [ "$(jq -r 'length' outputs.json)" -gt 0 ]; then + jq -r 'to_entries[] | select(.key | startswith("deployed_")) | "\(.key | ltrimstr("deployed_"))=\(.value.value // "")"' outputs.json >> $GITHUB_OUTPUT + else + echo "No outputs found, could be first run" + fi + + - name: Get Current Versions from Terraform State + id: get_current_versions + run: | + terraform output -json > outputs.json || true + if [ -s outputs.json ] && [ "$(jq -r 'length' outputs.json)" -gt 0 ]; then + jq -r 'to_entries[] | select(.key | startswith("deployed_")) | "\(.key | ltrimstr("deployed_"))=\(.value.value // "")"' outputs.json >> $GITHUB_OUTPUT + else + echo "No outputs found, could be first run" + fi + - name: Select workspace if: ${{ inputs.workspace }} run: terraform workspace select -or-create ${{ inputs.workspace }} @@ -277,16 +297,6 @@ jobs: }) } - - name: Get Current Versions from Terraform State - id: get_current_versions - run: | - terraform output -json > outputs.json - echo "api_image_tag=$(jq -r '.api_image_tag.value' outputs.json)" >> $GITHUB_OUTPUT - echo "cli_image_tag=$(jq -r '.cli_image_tag.value' outputs.json)" >> $GITHUB_OUTPUT - echo "selfserve_image_tag=$(jq -r '.selfserve_image_tag.value' outputs.json)" >> $GITHUB_OUTPUT - echo "internal_image_tag=$(jq -r '.internal_image_tag.value' outputs.json)" >> $GITHUB_OUTPUT - echo "assets_version=$(jq -r '.assets_version.value' outputs.json)" >> $GITHUB_OUTPUT - - name: Apply id: apply if: ${{ inputs.apply }} diff --git a/infra/terraform/environments/dev/main.tf b/infra/terraform/environments/dev/main.tf index 16b062e8ef..b5db3609d4 100644 --- a/infra/terraform/environments/dev/main.tf +++ b/infra/terraform/environments/dev/main.tf @@ -506,3 +506,13 @@ module "service" { ] } } + +resource "null_resource" "deployed_versions" { + triggers = { + deployed_api_image_tag = var.api_image_tag + deployed_internal_image_tag = var.internal_image_tag + deployed_selfserve_image_tag = var.selfserve_image_tag + deployed_cli_image_tag = var.cli_image_tag + deployed_assets_version = var.assets_version + } +} diff --git a/infra/terraform/environments/dev/outputs.tf b/infra/terraform/environments/dev/outputs.tf new file mode 100644 index 0000000000..a9b6c46c6a --- /dev/null +++ b/infra/terraform/environments/dev/outputs.tf @@ -0,0 +1,19 @@ +output "deployed_api_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_api_image_tag"] +} + +output "deployed_internal_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_internal_image_tag"] +} + +output "deployed_selfserve_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_selfserve_image_tag"] +} + +output "deployed_cli_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_cli_image_tag"] +} + +output "deployed_assets_version" { + value = null_resource.deployed_versions.triggers["deployed_assets_version"] +} diff --git a/infra/terraform/environments/dev/provider.tf b/infra/terraform/environments/dev/provider.tf index f7929a35cb..56dde57a8f 100644 --- a/infra/terraform/environments/dev/provider.tf +++ b/infra/terraform/environments/dev/provider.tf @@ -4,6 +4,14 @@ terraform { source = "hashicorp/aws" version = ">= 5.72.1" } + null = { + source = "hashicorp/null" + version = "~> 3.2" + } + null = { + source = "hashicorp/null" + version = "~> 3.2" + } } required_version = ">= 1.0" diff --git a/infra/terraform/environments/int/main.tf b/infra/terraform/environments/int/main.tf index 777526ab21..65ca75002f 100644 --- a/infra/terraform/environments/int/main.tf +++ b/infra/terraform/environments/int/main.tf @@ -472,3 +472,13 @@ module "service" { ] } } + +resource "null_resource" "deployed_versions" { + triggers = { + deployed_api_image_tag = var.api_image_tag + deployed_internal_image_tag = var.internal_image_tag + deployed_selfserve_image_tag = var.selfserve_image_tag + deployed_cli_image_tag = var.cli_image_tag + deployed_assets_version = var.assets_version + } +} diff --git a/infra/terraform/environments/int/outputs.tf b/infra/terraform/environments/int/outputs.tf new file mode 100644 index 0000000000..a9b6c46c6a --- /dev/null +++ b/infra/terraform/environments/int/outputs.tf @@ -0,0 +1,19 @@ +output "deployed_api_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_api_image_tag"] +} + +output "deployed_internal_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_internal_image_tag"] +} + +output "deployed_selfserve_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_selfserve_image_tag"] +} + +output "deployed_cli_image_tag" { + value = null_resource.deployed_versions.triggers["deployed_cli_image_tag"] +} + +output "deployed_assets_version" { + value = null_resource.deployed_versions.triggers["deployed_assets_version"] +} diff --git a/infra/terraform/environments/int/provider.tf b/infra/terraform/environments/int/provider.tf index 991da6a8fe..9b3e4a7f5e 100644 --- a/infra/terraform/environments/int/provider.tf +++ b/infra/terraform/environments/int/provider.tf @@ -4,6 +4,14 @@ terraform { source = "hashicorp/aws" version = ">= 5.72.1" } + null = { + source = "hashicorp/null" + version = "~> 3.2" + } + null = { + source = "hashicorp/null" + version = "~> 3.2" + } } required_version = ">= 1.0" From e28a1d7b335c5abf601f4cc20afb787e5bb4e010 Mon Sep 17 00:00:00 2001 From: Andrew Newton Date: Thu, 28 Nov 2024 16:00:48 +0000 Subject: [PATCH 2/2] fix: merge issues addressed --- .github/workflows/deploy-environment.yaml | 10 ---------- infra/terraform/environments/dev/provider.tf | 4 ---- infra/terraform/environments/int/provider.tf | 4 ---- 3 files changed, 18 deletions(-) diff --git a/.github/workflows/deploy-environment.yaml b/.github/workflows/deploy-environment.yaml index fc342ee06f..b5c9004862 100644 --- a/.github/workflows/deploy-environment.yaml +++ b/.github/workflows/deploy-environment.yaml @@ -167,16 +167,6 @@ jobs: echo "No outputs found, could be first run" fi - - name: Get Current Versions from Terraform State - id: get_current_versions - run: | - terraform output -json > outputs.json || true - if [ -s outputs.json ] && [ "$(jq -r 'length' outputs.json)" -gt 0 ]; then - jq -r 'to_entries[] | select(.key | startswith("deployed_")) | "\(.key | ltrimstr("deployed_"))=\(.value.value // "")"' outputs.json >> $GITHUB_OUTPUT - else - echo "No outputs found, could be first run" - fi - - name: Select workspace if: ${{ inputs.workspace }} run: terraform workspace select -or-create ${{ inputs.workspace }} diff --git a/infra/terraform/environments/dev/provider.tf b/infra/terraform/environments/dev/provider.tf index 56dde57a8f..a11c4d228e 100644 --- a/infra/terraform/environments/dev/provider.tf +++ b/infra/terraform/environments/dev/provider.tf @@ -8,10 +8,6 @@ terraform { source = "hashicorp/null" version = "~> 3.2" } - null = { - source = "hashicorp/null" - version = "~> 3.2" - } } required_version = ">= 1.0" diff --git a/infra/terraform/environments/int/provider.tf b/infra/terraform/environments/int/provider.tf index 9b3e4a7f5e..7ac7194c0f 100644 --- a/infra/terraform/environments/int/provider.tf +++ b/infra/terraform/environments/int/provider.tf @@ -8,10 +8,6 @@ terraform { source = "hashicorp/null" version = "~> 3.2" } - null = { - source = "hashicorp/null" - version = "~> 3.2" - } } required_version = ">= 1.0"