From cc494be21dbd278a14d44ef50dc22d9cfbfc69de Mon Sep 17 00:00:00 2001 From: Marcus Robinson Date: Tue, 30 Jul 2024 13:56:58 +0100 Subject: [PATCH 1/4] Add `DEPLOY_MODE` variable to deployment scripts and documentation * **.github/workflows/deploy_tre.yml** - Add an input for `DEPLOY_MODE` in the workflow - Pass the `DEPLOY_MODE` input to the deployment script * **docs/tre-admins/setup-instructions/workflows.md** - Add instructions on using the `DEPLOY_MODE` variable for 'plan' mode deployments via the GitHub UI * **devops/scripts/terraform_wrapper.sh** - Add a check for the `DEPLOY_MODE` variable - Execute `terraform plan` without applying if `DEPLOY_MODE` is set to 'plan' - Log the plan output to a file * **docs/tre-admins/setup-instructions/manual-deployment.md** - Add instructions on using the `DEPLOY_MODE` variable for 'plan' mode deployments - Include examples of setting the `DEPLOY_MODE` variable to 'plan' and 'apply' --- .github/workflows/deploy_tre.yml | 6 ++++++ devops/scripts/terraform_wrapper.sh | 20 +++++++++++++++++-- .../setup-instructions/manual-deployment.md | 16 +++++++++++++++ .../setup-instructions/workflows.md | 10 ++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) mode change 100755 => 100644 devops/scripts/terraform_wrapper.sh diff --git a/.github/workflows/deploy_tre.yml b/.github/workflows/deploy_tre.yml index bddea6979f..9557ea256e 100644 --- a/.github/workflows/deploy_tre.yml +++ b/.github/workflows/deploy_tre.yml @@ -16,6 +16,11 @@ on: # yamllint disable-line rule:truthy type: environment default: CICD required: true + DEPLOY_MODE: + description: The deployment mode to use (plan or apply) + type: string + default: apply + required: true # This will prevent multiple runs of this entire workflow. # We should NOT cancel in progress runs as that can destabilize the environment. @@ -38,6 +43,7 @@ jobs: environmentName: ${{ github.event.inputs.environment || 'CICD' }} E2E_TESTS_NUMBER_PROCESSES: 1 DEVCONTAINER_TAG: 'latest' + DEPLOY_MODE: ${{ github.event.inputs.DEPLOY_MODE }} secrets: AAD_TENANT_ID: ${{ secrets.AAD_TENANT_ID }} ACR_NAME: ${{ secrets.ACR_NAME }} diff --git a/devops/scripts/terraform_wrapper.sh b/devops/scripts/terraform_wrapper.sh old mode 100755 new mode 100644 index efa02a8078..121ddc8a20 --- a/devops/scripts/terraform_wrapper.sh +++ b/devops/scripts/terraform_wrapper.sh @@ -5,7 +5,7 @@ set -e function usage() { cat < Date: Wed, 31 Jul 2024 13:01:38 +0100 Subject: [PATCH 2/4] Support plan mode deployment Related to #4029 Add support for 'plan' mode deployments to evaluate the terraform plan before applying it. * **devops/scripts/terraform_wrapper.sh** - Add a check for the `DEPLOY_MODE` variable. - Execute `terraform plan` without applying if `DEPLOY_MODE` is set to 'plan'. - Log the plan output to a file. * **docs/tre-admins/setup-instructions/manual-deployment.md** - Add instructions on using the `DEPLOY_MODE` variable for 'plan' mode deployments. - Include examples of setting the `DEPLOY_MODE` variable to 'plan' and 'apply'. * **.github/workflows/deploy_tre.yml** - Add an input for `DEPLOY_MODE` in the workflow. - Pass the `DEPLOY_MODE` input to the deployment script. * **docs/tre-admins/setup-instructions/workflows.md** - Add instructions on using the `DEPLOY_MODE` variable for 'plan' mode deployments via the GitHub UI. - Include examples of setting the `DEPLOY_MODE` variable to 'plan' and 'apply'. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/AzureTRE/issues/4029?shareId=XXXX-XXXX-XXXX-XXXX). --- .github/workflows/deploy_tre.yml | 6 ++++ devops/scripts/terraform_wrapper.sh | 6 ++-- .../setup-instructions/manual-deployment.md | 34 +++++++++++++++++++ .../setup-instructions/workflows.md | 33 ++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) mode change 100755 => 100644 devops/scripts/terraform_wrapper.sh diff --git a/.github/workflows/deploy_tre.yml b/.github/workflows/deploy_tre.yml index bddea6979f..9557ea256e 100644 --- a/.github/workflows/deploy_tre.yml +++ b/.github/workflows/deploy_tre.yml @@ -16,6 +16,11 @@ on: # yamllint disable-line rule:truthy type: environment default: CICD required: true + DEPLOY_MODE: + description: The deployment mode to use (plan or apply) + type: string + default: apply + required: true # This will prevent multiple runs of this entire workflow. # We should NOT cancel in progress runs as that can destabilize the environment. @@ -38,6 +43,7 @@ jobs: environmentName: ${{ github.event.inputs.environment || 'CICD' }} E2E_TESTS_NUMBER_PROCESSES: 1 DEVCONTAINER_TAG: 'latest' + DEPLOY_MODE: ${{ github.event.inputs.DEPLOY_MODE }} secrets: AAD_TENANT_ID: ${{ secrets.AAD_TENANT_ID }} ACR_NAME: ${{ secrets.ACR_NAME }} diff --git a/devops/scripts/terraform_wrapper.sh b/devops/scripts/terraform_wrapper.sh old mode 100755 new mode 100644 index efa02a8078..35d6643ed9 --- a/devops/scripts/terraform_wrapper.sh +++ b/devops/scripts/terraform_wrapper.sh @@ -97,6 +97,10 @@ terraform init -input=false -backend=true -reconfigure \ -backend-config="container_name=${container_name}" \ -backend-config="key=${key}" +if [[ ${DEPLOY_MODE} == "plan" ]]; then + tf_command="terraform plan -out=tfplan && terraform show -json tfplan > plan_output.json" +fi + RUN_COMMAND=1 while [ $RUN_COMMAND = 1 ] do @@ -126,5 +130,3 @@ do exit 1 fi done - - diff --git a/docs/tre-admins/setup-instructions/manual-deployment.md b/docs/tre-admins/setup-instructions/manual-deployment.md index af62ee17e7..da083b3837 100644 --- a/docs/tre-admins/setup-instructions/manual-deployment.md +++ b/docs/tre-admins/setup-instructions/manual-deployment.md @@ -71,6 +71,40 @@ Open your browser and navigate to the `/api/docs` route of the API: `https:// Date: Fri, 15 Nov 2024 11:16:52 +0000 Subject: [PATCH 3/4] Refactor DEPLOY_MODE documentation for clarity and conciseness --- .../setup-instructions/manual-deployment.md | 46 ------------------- .../setup-instructions/workflows.md | 45 +----------------- docs/tre-admins/upgrading-tre.md | 18 ++++++++ 3 files changed, 19 insertions(+), 90 deletions(-) diff --git a/docs/tre-admins/setup-instructions/manual-deployment.md b/docs/tre-admins/setup-instructions/manual-deployment.md index ece30eac0f..af62ee17e7 100644 --- a/docs/tre-admins/setup-instructions/manual-deployment.md +++ b/docs/tre-admins/setup-instructions/manual-deployment.md @@ -71,52 +71,6 @@ Open your browser and navigate to the `/api/docs` route of the API: `https:// Date: Fri, 15 Nov 2024 11:19:20 +0000 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236f0e2055..859acf3fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,10 @@ FEATURES: ENHANCEMENTS: * Key Vaults should use RBAC instead of access policies for access control ([#4000](https://github.com/microsoft/AzureTRE/issues/4000)) -* Split log entries with [Log chunk X of Y] for better readability. ([[#3992](https://github.com/microsoft/AzureTRE/issues/3992) +* Split log entries with [Log chunk X of Y] for better readability. ([#3992](https://github.com/microsoft/AzureTRE/issues/3992)) * Expose APP_SERVICE_SKU build variable to allow enablement of App Gateway WAF ([#4111](https://github.com/microsoft/AzureTRE/pull/4111)) * Update Terraform to use Azure AD authentication rather than storage account keys ([#4103](https://github.com/microsoft/AzureTRE/issues/4103)) +* Add DEPLOY_MODE environemtn variable to enable Terraform plan ([#4047](https://github.com/microsoft/AzureTRE/pull/4047)) BUG FIXES: - Update KeyVault references in API to use the version so Terraform cascades the update ([#4112](https://github.com/microsoft/AzureTRE/pull/4112))