diff --git a/.github/workflows/deploy-environment.yaml b/.github/workflows/deploy-environment.yaml index 355032e175..b5c9004862 100644 --- a/.github/workflows/deploy-environment.yaml +++ b/.github/workflows/deploy-environment.yaml @@ -157,6 +157,16 @@ 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: Select workspace if: ${{ inputs.workspace }} run: terraform workspace select -or-create ${{ inputs.workspace }} @@ -277,16 +287,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..a11c4d228e 100644 --- a/infra/terraform/environments/dev/provider.tf +++ b/infra/terraform/environments/dev/provider.tf @@ -4,6 +4,10 @@ terraform { source = "hashicorp/aws" version = ">= 5.72.1" } + 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..7ac7194c0f 100644 --- a/infra/terraform/environments/int/provider.tf +++ b/infra/terraform/environments/int/provider.tf @@ -4,6 +4,10 @@ terraform { source = "hashicorp/aws" version = ">= 5.72.1" } + null = { + source = "hashicorp/null" + version = "~> 3.2" + } } required_version = ">= 1.0"