Skip to content

Commit 0628c0c

Browse files
committed
Remove deprecated GitHub Actions workflows and add new Terraform actions for enhanced deployment and management
1 parent 9e15307 commit 0628c0c

8 files changed

Lines changed: 876 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: 'Storage Firewall Management'
2+
description: 'Add or remove agent IP from storage account firewall'
3+
inputs:
4+
subscription_id:
5+
description: 'Azure subscription ID for storage account'
6+
required: true
7+
storage_account:
8+
description: 'Storage account name'
9+
required: true
10+
resource_group:
11+
description: 'Resource group name'
12+
required: true
13+
mode:
14+
description: 'Mode: on to add IP, off to remove IP'
15+
required: true
16+
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- name: Get Public IP
21+
id: get-ip
22+
shell: bash
23+
run: |
24+
PUBLIC_IP=$(curl -s https://api.ipify.org)
25+
echo "ip=$PUBLIC_IP" >> $GITHUB_OUTPUT
26+
echo "Public IP: $PUBLIC_IP"
27+
28+
- name: Set Azure Subscription
29+
shell: bash
30+
run: |
31+
az account set --subscription ${{ inputs.subscription_id }}
32+
echo "Set subscription to: $(az account show --query name -o tsv)"
33+
34+
- name: Add IP to Storage Firewall
35+
if: inputs.mode == 'on'
36+
shell: bash
37+
run: |
38+
echo "Adding IP ${{ steps.get-ip.outputs.ip }} to storage account firewall..."
39+
az storage account network-rule add \
40+
--resource-group ${{ inputs.resource_group }} \
41+
--account-name ${{ inputs.storage_account }} \
42+
--ip-address ${{ steps.get-ip.outputs.ip }}
43+
44+
echo "IP added to firewall rules"
45+
46+
# Wait for rule to propagate
47+
echo "Waiting 30 seconds for firewall rule to propagate..."
48+
sleep 30
49+
50+
- name: Remove IP from Storage Firewall
51+
if: inputs.mode == 'off'
52+
shell: bash
53+
run: |
54+
echo "Removing IP ${{ steps.get-ip.outputs.ip }} from storage account firewall..."
55+
az storage account network-rule remove \
56+
--resource-group ${{ inputs.resource_group }} \
57+
--account-name ${{ inputs.storage_account }} \
58+
--ip-address ${{ steps.get-ip.outputs.ip }} || true
59+
60+
echo "IP removed from firewall rules"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: 'Terraform Apply'
2+
description: 'Apply Terraform plan'
3+
inputs:
4+
working_directory:
5+
description: 'Working directory for Terraform'
6+
required: true
7+
plan_file:
8+
description: 'Path to the plan file to apply'
9+
required: true
10+
subscription_id:
11+
description: 'Azure subscription ID'
12+
required: true
13+
tf_debug:
14+
description: 'Terraform debug level (e.g., INFO, DEBUG)'
15+
required: false
16+
default: ''
17+
18+
runs:
19+
using: 'composite'
20+
steps:
21+
- name: Verify Plan File
22+
shell: bash
23+
run: |
24+
if [ ! -f "${{ inputs.working_directory }}/${{ inputs.plan_file }}" ]; then
25+
echo "Error: Plan file not found at ${{ inputs.working_directory }}/${{ inputs.plan_file }}"
26+
exit 1
27+
fi
28+
echo "Plan file found: ${{ inputs.working_directory }}/${{ inputs.plan_file }}"
29+
30+
- name: Terraform Version
31+
shell: bash
32+
working-directory: ${{ inputs.working_directory }}
33+
run: |
34+
echo "Terraform version:"
35+
terraform version
36+
37+
- name: Terraform Apply
38+
shell: bash
39+
working-directory: ${{ inputs.working_directory }}
40+
env:
41+
TF_IN_AUTOMATION: 'true'
42+
TF_LOG: ${{ inputs.tf_debug }}
43+
ARM_USE_OIDC: 'true'
44+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
45+
ARM_TENANT_ID: ${{ env.TENANT_ID }}
46+
run: |
47+
echo "Environment variables:"
48+
env | grep -E '^(ARM_|TF_|GITHUB_)' | sort
49+
50+
echo -e "\n\nApplying Terraform plan..."
51+
terraform apply -input=false -auto-approve "${{ inputs.plan_file }}"
52+
53+
exit_code=$?
54+
if [ $exit_code -ne 0 ]; then
55+
echo "Terraform apply failed with exit code: $exit_code"
56+
exit 1
57+
fi
58+
59+
echo "Terraform apply completed successfully"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Terraform Destroy'
2+
description: 'Destroy Terraform-managed infrastructure'
3+
inputs:
4+
working_directory:
5+
description: 'Working directory for Terraform'
6+
required: true
7+
subscription_id:
8+
description: 'Azure subscription ID'
9+
required: true
10+
additional_parameters:
11+
description: 'Additional Terraform destroy parameters'
12+
required: false
13+
default: ''
14+
tf_debug:
15+
description: 'Terraform debug level (e.g., INFO, DEBUG)'
16+
required: false
17+
default: ''
18+
19+
runs:
20+
using: 'composite'
21+
steps:
22+
- name: Terraform Version
23+
shell: bash
24+
working-directory: ${{ inputs.working_directory }}
25+
run: |
26+
echo "Terraform version:"
27+
terraform version
28+
29+
- name: Terraform Destroy
30+
shell: bash
31+
working-directory: ${{ inputs.working_directory }}
32+
env:
33+
TF_IN_AUTOMATION: 'true'
34+
TF_LOG: ${{ inputs.tf_debug }}
35+
ARM_USE_OIDC: 'true'
36+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
37+
ARM_TENANT_ID: ${{ env.TENANT_ID }}
38+
run: |
39+
echo "Environment variables:"
40+
env | grep -E '^(ARM_|TF_|GITHUB_)' | sort
41+
42+
echo -e "\n\nWARNING: Destroying infrastructure..."
43+
terraform destroy ${{ inputs.additional_parameters }} -input=false -auto-approve
44+
45+
exit_code=$?
46+
if [ $exit_code -ne 0 ]; then
47+
echo "Terraform destroy failed with exit code: $exit_code"
48+
exit 1
49+
fi
50+
51+
echo "Terraform destroy completed successfully"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: 'Terraform Init'
2+
description: 'Initialize Terraform with Azure backend'
3+
inputs:
4+
working_directory:
5+
description: 'Working directory for Terraform'
6+
required: true
7+
backend_subscription_id:
8+
description: 'Azure subscription ID for backend storage'
9+
required: true
10+
backend_resource_group:
11+
description: 'Resource group for backend storage'
12+
required: true
13+
backend_storage_account:
14+
description: 'Storage account for backend'
15+
required: true
16+
backend_container:
17+
description: 'Storage container for state files'
18+
required: true
19+
default: 'tfstate'
20+
backend_key:
21+
description: 'State file key/name'
22+
required: true
23+
subscription_id:
24+
description: 'Target Azure subscription ID'
25+
required: true
26+
terraform_version:
27+
description: 'Terraform version to use'
28+
required: false
29+
default: '1.11.2'
30+
31+
runs:
32+
using: 'composite'
33+
steps:
34+
- name: Create backend.tf
35+
shell: bash
36+
working-directory: ${{ inputs.working_directory }}
37+
run: |
38+
cat > backend.tf <<EOF
39+
terraform {
40+
backend "azurerm" {
41+
subscription_id = "${{ inputs.backend_subscription_id }}"
42+
resource_group_name = "${{ inputs.backend_resource_group }}"
43+
storage_account_name = "${{ inputs.backend_storage_account }}"
44+
container_name = "${{ inputs.backend_container }}"
45+
key = "${{ inputs.backend_key }}"
46+
}
47+
}
48+
EOF
49+
echo "Created backend.tf:"
50+
cat backend.tf
51+
52+
- name: Set Terraform Version
53+
shell: bash
54+
working-directory: ${{ inputs.working_directory }}
55+
run: |
56+
if [ -f .terraform-version ]; then
57+
echo "Removing existing .terraform-version file"
58+
rm -f .terraform-version
59+
fi
60+
61+
echo "${{ inputs.terraform_version }}" > .terraform-version
62+
echo "Created .terraform-version:"
63+
cat .terraform-version
64+
65+
echo "Current directory contents:"
66+
ls -la
67+
68+
- name: Check Terraform Version and Lockfile
69+
shell: bash
70+
working-directory: ${{ inputs.working_directory }}
71+
run: |
72+
if [ -f .terraform-version ]; then
73+
echo ".terraform-version file found:"
74+
cat .terraform-version
75+
fi
76+
77+
echo "Terraform version:"
78+
terraform version
79+
80+
if [ -f .terraform.lock.hcl ]; then
81+
echo ".terraform.lock.hcl file found:"
82+
cat .terraform.lock.hcl
83+
else
84+
echo "No .terraform.lock.hcl file found"
85+
fi
86+
87+
- name: Configure Git for Module Access
88+
shell: bash
89+
run: |
90+
git config --global credential.helper store
91+
echo "https://${{ github.actor }}:${{ github.token }}@github.com" > ~/.git-credentials
92+
93+
- name: Terraform Init
94+
shell: bash
95+
working-directory: ${{ inputs.working_directory }}
96+
env:
97+
TF_IN_AUTOMATION: 'true'
98+
ARM_USE_MSI: 'false'
99+
ARM_USE_OIDC: 'true'
100+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
101+
ARM_TENANT_ID: ${{ env.TENANT_ID }}
102+
run: |
103+
echo "All Environment Variables:"
104+
env | sort
105+
106+
echo -e "\n\nSetting Azure subscription: ${{ inputs.backend_subscription_id }}"
107+
az account set -s ${{ inputs.backend_subscription_id }}
108+
az account show
109+
110+
echo -e "\n\nInitializing Terraform..."
111+
terraform init
112+
113+
echo -e "\n\nContents of Terraform Providers Lock File:"
114+
if [ -f .terraform.lock.hcl ]; then
115+
cat .terraform.lock.hcl
116+
fi
117+
118+
echo -e "\n\nList Terraform Providers:"
119+
terraform providers

0 commit comments

Comments
 (0)