Skip to content

Commit

Permalink
Optimize Destroy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinbuss committed Jan 22, 2025
1 parent 7034e91 commit 52b4efc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/_terraformDestroyTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ on:
required: true
type: string
description: "Specifies the subscription id of the deployment."
databricks_account_id:
required: true
type: string
description: "Specifies the account id of Databricks."
databricks_network_connectivity_config_id:
required: true
type: string
description: "Specifies the network connectivity config id of Databricks."
secrets:
CLIENT_ID:
required: true
Expand Down Expand Up @@ -96,23 +104,17 @@ jobs:
run: |
terraform init -backend-config="azurerm.tfbackend"
# Terraform Init
- name: Terraform Init
# Terraform State Remove
- name: Terraform State Remove
id: terraform_state_remove
continue-on-error: true
working-directory: ${{ inputs.working_directory }}
run: |
# Remove config from state
echo "Remove config from state"
terraform state rm "module.data_landing_zone.module.databricks_account_configuration.databricks_mws_network_connectivity_config.network_connectivity_config"
terraform state rm "module.data_landing_zone.module.databricks_workspace_configuration.databricks_workspace_conf.workspace_conf"
# Get Terraform output
echo "Get Terraform output"
databricks_account_id=$(terraform output -raw databricks_account_id)
databricks_network_connectivity_config_id=$(terraform output -raw databricks_network_connectivity_config_id)
echo "databricks_account_id=$databricks_account_id" >> "$GITHUB_OUTPUT"
echo "databricks_network_connectivity_config_id=$databricks_network_connectivity_config_id" >> "$GITHUB_OUTPUT"
# Terraform Destroy
- name: Terraform Destroy
id: terraform_destroy
Expand All @@ -126,8 +128,8 @@ jobs:
run: |
# Login
echo "Login"
databricks auth login --host "https://accounts.azuredatabricks.net" --account-id "${{ steps.terraform_state_remove.outputs.databricks_account_id }}"
databricks auth login --host "https://accounts.azuredatabricks.net" --account-id "${{ inputs.databricks_account_id }}"
# Remove network connectivity config
echo "Remove network connectivity config"
databricks account network-connectivity delete-network-connectivity-configuration "${{ steps.terraform_state_remove.outputs.databricks_network_connectivity_config_id }}"
databricks account network-connectivity delete-network-connectivity-configuration "${{ inputs.databricks_network_connectivity_config_id }}"
24 changes: 24 additions & 0 deletions .github/workflows/_terraformEnvironmentTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ on:
CLIENT_ID:
required: true
description: "Specifies the client id."
outputs:
databricks_account_id:
description: "Specifies the account id of Databricks."
value: ${{ jobs.apply.outputs.databricks_account_id }}
databricks_network_connectivity_config_id:
description: "Specifies the network connectivity config id of Databricks."
value: ${{ jobs.apply.outputs.databricks_network_connectivity_config_id }}

permissions:
id-token: write
Expand Down Expand Up @@ -194,6 +201,9 @@ jobs:
concurrency:
group: terraform-${{ inputs.environment }}
cancel-in-progress: false
outputs:
databricks_account_id: ${{ steps.terraform_outputs.outputs.databricks_account_id }}
databricks_network_connectivity_config_id: ${{ steps.terraform_outputs.outputs.databricks_network_connectivity_config_id }}

env:
ARM_TENANT_ID: ${{ inputs.tenant_id }}
Expand Down Expand Up @@ -244,3 +254,17 @@ jobs:
working-directory: ${{ inputs.working_directory }}
run: |
terraform apply -var-file="vars.tfvars" -auto-approve -input=false
# Terraform Export Outputs
- name: Terraform Export Outputs
id: terraform_outputs
working-directory: ${{ inputs.working_directory }}
run: |
# Get Terraform output
echo "Get Terraform output"
databricks_account_id=$(terraform output -raw databricks_account_id)
echo "databricks_account_id=$databricks_account_id" >> "$GITHUB_OUTPUT"
databricks_network_connectivity_config_id=$(terraform output -raw databricks_network_connectivity_config_id)
echo "databricks_network_connectivity_config_id=$databricks_network_connectivity_config_id" >> "$GITHUB_OUTPUT"
2 changes: 2 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ jobs:
working_directory: "./tests/e2e"
tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452"
subscription_id: "9842be63-c8c0-4647-a5d1-0c5e7f8bbb25"
databricks_account_id: ${{ needs.terraform.outputs.databricks_account_id }}
databricks_network_connectivity_config_id: ${{ needs.terraform.outputs.databricks_network_connectivity_config_id }}
secrets:
CLIENT_ID: ${{ secrets.CLIENT_ID }}

0 comments on commit 52b4efc

Please sign in to comment.