Skip to content

Commit 3a3b14a

Browse files
committed
change workflow
1 parent e8955a2 commit 3a3b14a

File tree

5 files changed

+122
-154
lines changed

5 files changed

+122
-154
lines changed

.github/workflows/develop.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: DEV DEPLOY
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
jobs:
13+
terraform:
14+
uses: "./.github/workflows/terraform.yml"
15+
with:
16+
aws-assume-role-arn: "arn:aws:iam::179916804929:role/github-actions-brunograna-pipeline-test"
17+
environment: "dev"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "brunograna-sa-east-1-terraform-statefile"
20+
aws-lock-dynamodb-table: "buildrun-terraform-state-lock"

.github/workflows/main.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: PROD DEPLOY
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
jobs:
13+
terraform:
14+
uses: "./.github/workflows/terraform.yml"
15+
with:
16+
aws-assume-role-arn: "arn:aws:iam::179916804929:role/github-actions-brunograna-pipeline-test"
17+
environment: "prod"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "brunograna-sa-east-1-terraform-statefile"
20+
aws-lock-dynamodb-table: "buildrun-terraform-state-lock"

.github/workflows/terraform-dev.yml

-77
This file was deleted.

.github/workflows/terraform-prod.yml

-77
This file was deleted.

.github/workflows/terraform.yml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Terraform Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
aws-assume-role-arn:
7+
required: true
8+
type: string
9+
environment:
10+
required: true
11+
type: string
12+
aws-region:
13+
required: true
14+
type: string
15+
aws-statefile-s3-bucket:
16+
required: true
17+
type: string
18+
aws-lock-dynamodb-table:
19+
required: true
20+
type: string
21+
22+
jobs:
23+
terraform:
24+
runs-on: ubuntu-latest
25+
26+
defaults:
27+
run:
28+
shell: bash
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Terraform
35+
uses: hashicorp/setup-terraform@v3
36+
with:
37+
terraform_version: 1.8.3
38+
39+
- name: Configure AWS credentials
40+
uses: aws-actions/configure-aws-credentials@v4
41+
with:
42+
role-to-assume: ${{ inputs.aws-assume-role-arn }}
43+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
44+
aws-region: ${{ inputs.aws-region }}
45+
46+
- name: Read destroy configuration
47+
id: read-destroy-config
48+
run: |
49+
DESTROY="$(jq -r '.${{ inputs.environment }}' ./infra/destroy_config.json)"
50+
echo "destroy=$(echo $DESTROY)" >> $GITHUB_OUTPUT
51+
52+
- name: Terraform Init
53+
run: |
54+
cd infra && terraform init \
55+
-backend-config="bucket=${{ inputs.aws-statefile-s3-bucket }}" \
56+
-backend-config="key=${{ github.event.repository.name }}" \
57+
-backend-config="region=${{ inputs.aws-region }}" \
58+
-backend-config="dynamodb_table=${{ inputs.aws-lock-dynamodb-table }}"
59+
60+
- name: Terraform Validate
61+
run: terraform validate
62+
63+
- name: Terraform Destroy
64+
if: steps.read-destroy-config.outputs.destroy == 'true'
65+
id: terraform-destroy
66+
run: cd infra &&
67+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
68+
terraform destroy -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -auto-approve
69+
70+
- name: Terraform Plan
71+
if: steps.read-destroy-config.outputs.destroy != 'true'
72+
id: terraform-plan
73+
run: cd infra &&
74+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
75+
terraform plan -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -out="${{ inputs.environment }}.plan"
76+
77+
- name: Terraform Apply
78+
id: terraform-apply
79+
if: steps.read-destroy-config.outputs.destroy != 'true'
80+
run: cd infra &&
81+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
82+
terraform apply "${{ inputs.environment }}.plan"

0 commit comments

Comments
 (0)