Skip to content

Commit 3cce522

Browse files
committed
updated workflows to segment out destruction of resources
1 parent 2039a33 commit 3cce522

3 files changed

Lines changed: 86 additions & 52 deletions

File tree

.github/workflows/destroy.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: OpenAI Workshop Infrastructure Destruction
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
type: string
8+
required: true
9+
iac-tool:
10+
type: string
11+
required: false
12+
default: tf
13+
14+
workflow_dispatch:
15+
inputs:
16+
environment:
17+
description: Target environment
18+
default: dev
19+
required: true
20+
iac-tool:
21+
description: "Choose your infrastructure as code tool"
22+
type: choice
23+
options:
24+
- tf
25+
- bicep
26+
default: tf
27+
required: true
28+
29+
terraform_destroy:
30+
name: Terraform Destroy
31+
needs: [tf, test_prep]
32+
runs-on: ubuntu-latest
33+
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev' }}
34+
permissions:
35+
id-token: write
36+
contents: read
37+
38+
steps:
39+
- uses: actions/checkout@v6
40+
41+
- name: Azure OIDC Login
42+
uses: azure/login@v2
43+
with:
44+
client-id: ${{ vars.AZURE_CLIENT_ID }}
45+
tenant-id: ${{ vars.AZURE_TENANT_ID }}
46+
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
47+
48+
- name: Terraform Setup
49+
uses: hashicorp/setup-terraform@v3
50+
51+
- name: Terraform Destroy
52+
run: |
53+
cd infra/terraform
54+
export ARM_USE_OIDC=true
55+
export ARM_CLIENT_ID="${{ vars.AZURE_CLIENT_ID }}"
56+
export ARM_TENANT_ID="${{ vars.AZURE_TENANT_ID }}"
57+
export ARM_SUBSCRIPTION_ID="${{ vars.AZURE_SUBSCRIPTION_ID }}"
58+
59+
terraform init -backend-config="resource_group_name=${TFSTATE_RG}" \
60+
-backend-config="key=${TFSTATE_KEY}" -backend-config="storage_account_name=${TFSTATE_ACCOUNT}" \
61+
-backend-config="container_name=${TFSTATE_CONTAINER}"
62+
63+
terraform destroy -auto-approve \
64+
-var project_name=${{ github.event.repository.name }} \
65+
-var tenant_id=${{ vars.AZURE_TENANT_ID }} \
66+
-var subscription_id=${{ vars.AZURE_SUBSCRIPTION_ID }} \
67+
-var acr_name=${{ vars.ACR_NAME }} \
68+
-var location=${{ vars.AZ_REGION }} \
69+
-var environment=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev' }} \
70+
-var docker_image_mcp=${{ vars.DOCKER_IMAGE_MCP }} \
71+
-var docker_image_backend=${{ vars.DOCKER_IMAGE_BACKEND }} \
72+
-var iteration=${{ (github.event_name != 'workflow_dispatch' && github.base_ref != 'main' && github.base_ref != 'int-agentic') && '${GITHUB_SHA:0:7}' || vars.ITERATION }}
73+
env:
74+
TFSTATE_RG: ${{ vars.TFSTATE_RG }}
75+
TFSTATE_ACCOUNT: ${{ vars.TFSTATE_ACCOUNT }}
76+
TFSTATE_CONTAINER: ${{ vars.TFSTATE_CONTAINER }}
77+
TFSTATE_KEY: "${{ github.event.repository.name }}-${{ github.ref_name }}.tfstate"
78+

.github/workflows/infrastructure.yml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -168,55 +168,3 @@ jobs:
168168
BACKEND_API_ENDPOINT: ${{ needs.tf.outputs.BACKEND_API_ENDPOINT }}
169169
KEYVAULT_NAME: ${{ needs.tf.outputs.KEY_VAULT_NAME }}
170170
MODEL_API_KEY_SECRET_NAME: "AZURE-OPENAI-API-KEY"
171-
172-
terraform_destroy:
173-
name: Terraform Destroy
174-
needs: [tf, test_prep]
175-
if: always() && (github.event_name == 'workflow_dispatch' && github.event.inputs.iac-tool || 'tf') == 'tf' && (github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev') == 'dev' && needs.tf.result == 'success' && needs.test_prep.result == 'success'
176-
runs-on: ubuntu-latest
177-
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev' }}
178-
permissions:
179-
id-token: write
180-
contents: read
181-
182-
steps:
183-
- uses: actions/checkout@v6
184-
185-
- name: Azure OIDC Login
186-
uses: azure/login@v2
187-
with:
188-
client-id: ${{ vars.AZURE_CLIENT_ID }}
189-
tenant-id: ${{ vars.AZURE_TENANT_ID }}
190-
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
191-
192-
- name: Terraform Setup
193-
uses: hashicorp/setup-terraform@v3
194-
195-
- name: Terraform Destroy
196-
run: |
197-
cd infra/terraform
198-
export ARM_USE_OIDC=true
199-
export ARM_CLIENT_ID="${{ vars.AZURE_CLIENT_ID }}"
200-
export ARM_TENANT_ID="${{ vars.AZURE_TENANT_ID }}"
201-
export ARM_SUBSCRIPTION_ID="${{ vars.AZURE_SUBSCRIPTION_ID }}"
202-
203-
terraform init -backend-config="resource_group_name=${TFSTATE_RG}" \
204-
-backend-config="key=${TFSTATE_KEY}" -backend-config="storage_account_name=${TFSTATE_ACCOUNT}" \
205-
-backend-config="container_name=${TFSTATE_CONTAINER}"
206-
207-
terraform destroy -auto-approve \
208-
-var project_name=${{ github.event.repository.name }} \
209-
-var tenant_id=${{ vars.AZURE_TENANT_ID }} \
210-
-var subscription_id=${{ vars.AZURE_SUBSCRIPTION_ID }} \
211-
-var acr_name=${{ vars.ACR_NAME }} \
212-
-var location=${{ vars.AZ_REGION }} \
213-
-var environment=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev' }} \
214-
-var docker_image_mcp=${{ vars.DOCKER_IMAGE_MCP }} \
215-
-var docker_image_backend=${{ vars.DOCKER_IMAGE_BACKEND }} \
216-
-var iteration=${{ (github.event_name != 'workflow_dispatch' && github.base_ref != 'main' && github.base_ref != 'int-agentic') && '${GITHUB_SHA:0:7}' || vars.ITERATION }}
217-
env:
218-
TFSTATE_RG: ${{ vars.TFSTATE_RG }}
219-
TFSTATE_ACCOUNT: ${{ vars.TFSTATE_ACCOUNT }}
220-
TFSTATE_CONTAINER: ${{ vars.TFSTATE_CONTAINER }}
221-
TFSTATE_KEY: "${{ github.event.repository.name }}-${{ github.ref_name }}.tfstate"
222-

.github/workflows/orchestrate.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ jobs:
4949
with:
5050
environment: ${{ inputs.target_env || (github.ref_name == 'tjs-test-infra' && 'dev') || (github.ref_name == 'int-agentic' && 'integration') || (github.ref_name == 'main' && 'prod') || 'dev' }}
5151
secrets: inherit
52+
53+
destroy-infrastructure:
54+
needs: [ deploy-infrastructure ]
55+
if: always() && (github.event_name == 'workflow_dispatch' && github.event.inputs.iac-tool || 'tf') == 'tf' && (github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.base_ref == 'main' && 'prod') || (github.base_ref == 'int-agentic' && 'integration') || 'dev') == 'dev' && needs.tf.result == 'success' && needs.test_prep.result == 'success'
56+
uses: ./.github/workflows/destroy.yml
57+
with:
58+
environment: ${{ inputs.target_env || (github.ref_name == 'tjs-test-infra' && 'dev') || (github.ref_name == 'int-agentic' && 'integration') || (github.ref_name == 'main' && 'prod') || 'dev' }}
59+
secrets: inherit

0 commit comments

Comments
 (0)