Skip to content

Commit 72f2bd3

Browse files
committed
feat: use workflow dispatch to trigger terraform flow
1 parent 9d8e6e5 commit 72f2bd3

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

.github/workflows/terraform.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: Terraform Plan and Apply
22
on:
3-
workflow_run:
4-
workflows: [ "Build and publish image" ]
5-
types:
6-
- completed
3+
workflow_dispatch:
4+
inputs:
5+
environment:
6+
description: 'The target environment for deployment'
7+
required: true
8+
default: 'Sandbox'
9+
type: choice
10+
options:
11+
- Sandbox
12+
- Production
13+
714

815
jobs:
916
terraform:
10-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
11-
environment: ${{ github.event.workflow_run.head_branch == 'main' && 'Production' || 'Sandbox' }}
17+
environment: ${{ github.event.inputs.environment }}
1218
runs-on: ubuntu-latest
1319
# workaround for "context access might be invalid warning"
1420
env:
@@ -23,7 +29,7 @@ jobs:
2329
- name: Get latest tag
2430
id: tag
2531
run: |
26-
if [ "${{ github.event.workflow_run.head_branch }}" == "main" ]; then
32+
if [ "${{ github.event.inputs.environment }}" == "Production" ]; then
2733
echo "IMAGE_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
2834
else
2935
echo "IMAGE_TAG=dev" >> $GITHUB_ENV
@@ -40,7 +46,7 @@ jobs:
4046
TF_VAR_image_repo=${{ env.IMAGE_REPO }}
4147
EOF
4248
- name: Set sandbox environment variables
43-
if: github.event.workflow_run.head_branch == 'SSOTEAM-2579'
49+
if: github.event.inputs.environment == 'Sandbox'
4450
run: |
4551
cat >> $GITHUB_ENV <<EOF
4652
TF_STATE_BUCKET_NAME=otp-provider-tf-sandbox
@@ -90,7 +96,7 @@ jobs:
9096
EOF
9197
9298
- name: Set production environment variables
93-
if: github.event.workflow_run.head_branch == 'main'
99+
if: github.event.inputs.environment == 'Production'
94100
run: |
95101
cat >> $GITHUB_ENV <<EOF
96102
TF_STATE_BUCKET_NAME=otp-provider-tf-production

0 commit comments

Comments
 (0)