Skip to content

Commit efa186d

Browse files
committed
Final Code Updated
1 parent d9a1629 commit efa186d

File tree

7 files changed

+99
-56
lines changed

7 files changed

+99
-56
lines changed

.github/workflows/dev.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
with:
3636
environment: dev
3737
tfvars_file: environments/dev.tfvars
38-
rgname: ritkargvdev
39-
saname: ritkasavdev
40-
scname: ritkascvdev
38+
rgname: ritkargv
39+
saname: ritkasav
40+
scname: ritkascv
4141
key: dev.tfstate
4242

4343
# Run toggles
@@ -57,7 +57,6 @@ jobs:
5757

5858
# ✔ Apply approval only during manual trigger
5959
useEnvironmentApply: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_apply == true }}
60-
6160
useEnvironmentDestroy: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_destroy == true }}
6261

6362
secrets:

.github/workflows/terraform-multi.yml

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,29 @@ jobs:
5656
5757
- name: Compute and print inputs + derived toggles
5858
env:
59-
# raw inputs (workflow_dispatch boolean inputs)
60-
input_use_environment_init: ${{ inputs.use_environment_init }}
61-
input_do_init: ${{ inputs.do_init }}
62-
input_use_environment_plan: ${{ inputs.use_environment_plan }}
63-
input_do_plan: ${{ inputs.do_plan }}
64-
input_use_environment_apply: ${{ inputs.use_environment_apply }}
65-
input_do_apply: ${{ inputs.do_apply }}
66-
input_use_environment_destroy: ${{ inputs.use_environment_destroy }}
67-
input_do_destroy: ${{ inputs.do_destroy }}
68-
69-
# Derived run toggles (what your reusable workflow expects)
70-
# run on push OR when corresponding input is true
71-
run_init: ${{ github.event_name == 'push' || inputs.do_init }}
72-
run_plan: ${{ github.event_name == 'push' || inputs.do_plan }}
73-
run_apply: ${{ github.event_name == 'push' || inputs.do_apply }}
74-
run_destroy: ${{ github.event_name == 'workflow_dispatch' && inputs.do_destroy }}
75-
76-
# Derived environment-approval toggles: push should force approval for apply
77-
use_env_init: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_init }}
78-
use_env_plan: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_plan }}
79-
use_env_apply: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.use_environment_apply) }}
80-
use_env_destroy: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_destroy }}
81-
run: |
82-
echo "---- Raw inputs (workflow_dispatch) ----"
83-
echo "use_environment_init: $input_use_environment_init"
84-
echo "do_init: $input_do_init"
85-
echo "use_environment_plan: $input_use_environment_plan"
86-
echo "do_plan: $input_do_plan"
87-
echo "use_environment_apply: $input_use_environment_apply"
88-
echo "do_apply: $input_do_apply"
89-
echo "use_environment_destroy: $input_use_environment_destroy"
90-
echo "do_destroy: $input_do_destroy"
91-
echo ""
59+
# inputs provided by the caller workflow (workflow_call inputs)
60+
input_runInit: ${{ inputs.runInit }}
61+
input_runPlan: ${{ inputs.runPlan }}
62+
input_runApply: ${{ inputs.runApply }}
63+
input_runDestroy: ${{ inputs.runDestroy }}
9264

93-
echo "---- Derived run toggles (will be passed to reusable workflow) ----"
94-
echo "runInit: $run_init"
95-
echo "runPlan: $run_plan"
96-
echo "runApply: $run_apply"
97-
echo "runDestroy: $run_destroy"
98-
echo ""
65+
input_useEnvironmentInit: ${{ inputs.useEnvironmentInit }}
66+
input_useEnvironmentPlan: ${{ inputs.useEnvironmentPlan }}
67+
input_useEnvironmentApply: ${{ inputs.useEnvironmentApply }}
68+
input_useEnvironmentDestroy: ${{ inputs.useEnvironmentDestroy }}
9969

100-
echo "---- Derived environment (approval) toggles ----"
101-
echo "useEnvironmentInit: $use_env_init"
102-
echo "useEnvironmentPlan: $use_env_plan"
103-
echo "useEnvironmentApply: $use_env_apply"
104-
echo "useEnvironmentDestroy: $use_env_destroy"
70+
run: |
71+
echo "---- Actual inputs received (workflow_call inputs) ----"
72+
echo "runInit: $input_runInit"
73+
echo "runPlan: $input_runPlan"
74+
echo "runApply: $input_runApply"
75+
echo "runDestroy: $input_runDestroy"
10576
echo ""
77+
echo "---- Environment approval inputs (caller-controlled) ----"
78+
echo "useEnvironmentInit: $input_useEnvironmentInit"
79+
echo "useEnvironmentPlan: $input_useEnvironmentPlan"
80+
echo "useEnvironmentApply: $input_useEnvironmentApply"
81+
echo "useEnvironmentDestroy: $input_useEnvironmentDestroy"
10682
10783
echo "---- Note ----"
10884
echo "If any job has 'environment: <non-empty>' that job will request approval from that environment's protection rules."
@@ -161,12 +137,12 @@ jobs:
161137
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
162138
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
163139
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
164-
run: terraform plan -var-file="../environments/prod.tfvars" -out="tf-plan-${{ inputs.environment }}.tfplan"
140+
run: terraform plan -var-file="../environments/${{ inputs.environment }}.tfvars" -out="tf-plan-${{ inputs.environment }}.tfplan"
165141
# Yha tak wala block...
166142

167143
# Use below mentioned with , when in provider.tf > provider "azurerm" > use_oidc = false (ya fir yeh line humne use hi nhi ki ho)
168144
# - name: Terraform Plan
169-
# run: terraform plan -var-file="../environments/prod.tfvars" -out="tf-plan-${{ inputs.environment }}.tfplan"
145+
# run: terraform plan -var-file="../environments/${{ inputs.environment }}" -out="tf-plan-${{ inputs.environment }}.tfplan"
170146
# Yha tak wala block...
171147

172148
- name: Upload plan

.github/workflows/test.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'environments/test.tfvars'
9+
10+
workflow_dispatch:
11+
inputs:
12+
use_environment_init: { type: boolean, default: false, description: "Require approval before Init?" }
13+
do_init: { type: boolean, default: false, description: "Run terraform init + fmt + validate?" }
14+
15+
use_environment_plan: { type: boolean, default: false, description: "Require approval before Plan?" }
16+
do_plan: { type: boolean, default: false, description: "Run terraform plan?" }
17+
18+
use_environment_apply: { type: boolean, default: false, description: "Require approval before Apply?" }
19+
do_apply: { type: boolean, default: false, description: "Run terraform apply?" }
20+
21+
use_environment_destroy: { type: boolean, default: false, description: "Require approval before Destroy?" }
22+
do_destroy: { type: boolean, default: false, description: "Run terraform destroy?" }
23+
24+
permissions:
25+
contents: read
26+
id-token: write
27+
28+
concurrency:
29+
group: test-tf
30+
cancel-in-progress: false
31+
32+
jobs:
33+
call:
34+
uses: ./.github/workflows/terraform-multi.yml
35+
with:
36+
environment: test
37+
tfvars_file: environments/test.tfvars
38+
rgname: ritkargv
39+
saname: ritkasav
40+
scname: ritkascv
41+
key: test.tfstate
42+
43+
# Run toggles
44+
runInit: ${{ github.event_name == 'push' || inputs.do_init == true }}
45+
runPlan: ${{ github.event_name == 'push' || inputs.do_plan == true }}
46+
47+
# ❌ Push par apply nahi chalega
48+
# ✔ Apply sirf manual dispatch ke through chalega
49+
runApply: ${{ github.event_name == 'workflow_dispatch' && inputs.do_apply == true }}
50+
51+
# Destroy only manual
52+
runDestroy: ${{ github.event_name == 'workflow_dispatch' && inputs.do_destroy == true }}
53+
54+
# Approval toggles
55+
useEnvironmentInit: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_init == true }}
56+
useEnvironmentPlan: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_plan == true }}
57+
58+
# ✔ Apply approval only during manual trigger
59+
useEnvironmentApply: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_apply == true }}
60+
useEnvironmentDestroy: ${{ github.event_name == 'workflow_dispatch' && inputs.use_environment_destroy == true }}
61+
62+
secrets:
63+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
64+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
65+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

.github/workflows/uat.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ jobs:
3737
tfvars_file: environments/uat.tfvars
3838

3939
# Storage backend for UAT (change names as per your setup)
40-
rgname: ritkargvuat
41-
saname: ritkasavuat
42-
scname: ritkascvuat
40+
rgname: ritkargv
41+
saname: ritkasav
42+
scname: ritkascv
4343
key: uat.tfstate
4444

4545
# Run toggles

environments/dev.tfvars

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ resource_groups = {
33
name = "rit-hrutviatri"
44
location = "North Europe"
55
}
6+
}
67

78

8-
}
99

1010
######
11-
1211
######
13-
1412
######
1513

1614

environments/test.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ resource_groups = {
55
}
66
}
77

8+
89
vnets = {
910
vnet1 = {
1011
vnet_name = "pahelavnet-test"

environments/uat.tfvars

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ resource_groups = {
55
}
66
}
77

8+
9+
810
vnets = {
911
vnet1 = {
1012
vnet_name = "pahelavnet-uat"
@@ -20,6 +22,8 @@ vnets = {
2022
}
2123
}
2224

25+
26+
2327
nsg = {
2428
web_nsg = {
2529
nsg_name = "pahelansg-uat"

0 commit comments

Comments
 (0)