Skip to content

Commit b2f6264

Browse files
committed
add Dockerfile terraform
1 parent e504298 commit b2f6264

29 files changed

Lines changed: 1459 additions & 1445 deletions

.github/workflows/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Você é o code owner de todo o repositório
1+
# Você é o code owner de todo o repositório
22
* @doug2901

.github/workflows/pipeline.yaml

Lines changed: 140 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,141 @@
1-
name: Terraform Apply
2-
on:
3-
push:
4-
branches:
5-
- main
6-
7-
jobs:
8-
Terraform-Plan:
9-
runs-on: ubuntu-latest
10-
environment: pre-prod
11-
outputs:
12-
plan_exitcode: ${{ steps.plan.outputs.exitcode }}
13-
tag: ${{ steps.bump.outputs.new_tag }}
14-
env:
15-
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
16-
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
17-
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
18-
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v4
22-
23-
- name: Bump version and push tag
24-
id: bump
25-
uses: anothrNick/github-tag-action@1.73.0
26-
env:
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28-
WITH_V: true
29-
30-
- name: Versão criada
31-
run: |
32-
echo "Tag criada: ${{ steps.bump.outputs.new_tag }}"
33-
# echo "version_tag=${{ steps.bump.outputs.new_tag }}" >> $GITHUB_OUTPUT
34-
35-
- name: ls files
36-
run: ls -ltr
37-
38-
- name: Install Terraform CLI
39-
uses: hashicorp/setup-terraform@v3
40-
with:
41-
terraform_version: "1.12.2"
42-
43-
- name: Terraform Init
44-
run: terraform init
45-
46-
- name: Terraform Validate
47-
run: terraform validate
48-
49-
- name: Terraform Plan
50-
id: plan
51-
run: terraform plan -detailed-exitcode -out=state_file-${{ steps.bump.outputs.new_tag }} || export exitcode=$? >> $GITHUB_OUTPUT
52-
continue-on-error: true # Allow the step to continue even if -detailed-exitcode returns 2
53-
54-
- name: get value of terraform plan
55-
run: |
56-
echo "The value is: ${{ steps.plan.outputs.exitcode }}"
57-
58-
- name: Check Plan Exit Code
59-
id: check_plan
60-
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
61-
run: |
62-
echo "Terraform plan detected changes. Proceeding with apply (or manual approval)."
63-
# Add logic for manual approval or direct apply here
64-
65-
- name: No Changes Detected
66-
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '0'
67-
run: |
68-
echo "No changes detected by Terraform plan. Skipping apply."
69-
70-
- name: Terraform Plan Failed
71-
if: steps.plan.outcome == 'failure' || steps.plan.outputs.exitcode == '1'
72-
run: |
73-
echo "Terraform plan failed. Review the logs for errors."
74-
exit 1 # Fail the workflow
75-
76-
- name: Send plan via email
77-
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
78-
uses: dawidd6/action-send-mail@v6
79-
with:
80-
server_address: smtp.gmail.com
81-
server_port: 587
82-
username: ${{ secrets.SMTP_USER }}
83-
password: ${{ secrets.SMTP_PASS }}
84-
subject: "O ${{ github.repository }} Inforrrrrma"
85-
to: ${{ secrets.SMTP_USER }}
86-
from: "Terraform <${{ secrets.SMTP_USER }}>"
87-
body: |
88-
Foram detectadas alterações a serem feitas em sua infraestrutura.
89-
90-
Aprove ou rejeite aqui:
91-
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
92-
93-
- name: Remove unnecessary folders
94-
run: |
95-
rm -rf some_examples
96-
rm -rf .github
97-
rm -rf .gitignore
98-
rm -rf .git
99-
100-
- name: ls files
101-
run: ls -ltra
102-
103-
- name: Upload artifacts
104-
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
105-
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: ${{ steps.bump.outputs.new_tag }}
109-
path: .
110-
111-
Terraform-Apply:
112-
runs-on: ubuntu-latest
113-
needs: Terraform-Plan
114-
environment: pre-prod-apply
115-
if: needs.Terraform-Plan.outputs.plan_exitcode == '2'
116-
env:
117-
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
118-
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
119-
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
120-
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
121-
steps:
122-
- name: Get build artifacts
123-
uses: actions/download-artifact@v4
124-
with:
125-
name: ${{ needs.Terraform-Plan.outputs.tag }}
126-
path: terraform_plan_artifacts
127-
128-
- name: Install Terraform CLI
129-
uses: hashicorp/setup-terraform@v3
130-
with:
131-
terraform_version: "1.12.2"
132-
133-
- name: Terraform Init
134-
run: terraform init
135-
working-directory: terraform_plan_artifacts
136-
137-
- name: Terraform Apply
138-
id: apply
139-
working-directory: terraform_plan_artifacts
140-
run: |
1+
name: Terraform Apply
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
Terraform-Plan:
9+
runs-on: ubuntu-latest
10+
environment: pre-prod
11+
outputs:
12+
plan_exitcode: ${{ steps.plan.outputs.exitcode }}
13+
tag: ${{ steps.bump.outputs.new_tag }}
14+
env:
15+
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
16+
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
17+
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
18+
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Bump version and push tag
24+
id: bump
25+
uses: anothrNick/github-tag-action@1.73.0
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
WITH_V: true
29+
30+
- name: Versão criada
31+
run: |
32+
echo "Tag criada: ${{ steps.bump.outputs.new_tag }}"
33+
# echo "version_tag=${{ steps.bump.outputs.new_tag }}" >> $GITHUB_OUTPUT
34+
35+
- name: ls files
36+
run: ls -ltr
37+
38+
- name: Install Terraform CLI
39+
uses: hashicorp/setup-terraform@v3
40+
with:
41+
terraform_version: "1.12.2"
42+
43+
- name: Terraform Init
44+
run: terraform init
45+
46+
- name: Terraform Validate
47+
run: terraform validate
48+
49+
- name: Terraform Plan
50+
id: plan
51+
run: terraform plan -detailed-exitcode -out=state_file-${{ steps.bump.outputs.new_tag }} || export exitcode=$? >> $GITHUB_OUTPUT
52+
continue-on-error: true # Allow the step to continue even if -detailed-exitcode returns 2
53+
54+
- name: get value of terraform plan
55+
run: |
56+
echo "The value is: ${{ steps.plan.outputs.exitcode }}"
57+
58+
- name: Check Plan Exit Code
59+
id: check_plan
60+
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
61+
run: |
62+
echo "Terraform plan detected changes. Proceeding with apply (or manual approval)."
63+
# Add logic for manual approval or direct apply here
64+
65+
- name: No Changes Detected
66+
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '0'
67+
run: |
68+
echo "No changes detected by Terraform plan. Skipping apply."
69+
70+
- name: Terraform Plan Failed
71+
if: steps.plan.outcome == 'failure' || steps.plan.outputs.exitcode == '1'
72+
run: |
73+
echo "Terraform plan failed. Review the logs for errors."
74+
exit 1 # Fail the workflow
75+
76+
- name: Send plan via email
77+
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
78+
uses: dawidd6/action-send-mail@v6
79+
with:
80+
server_address: smtp.gmail.com
81+
server_port: 587
82+
username: ${{ secrets.SMTP_USER }}
83+
password: ${{ secrets.SMTP_PASS }}
84+
subject: "O ${{ github.repository }} Inforrrrrma"
85+
to: ${{ secrets.SMTP_USER }}
86+
from: "Terraform <${{ secrets.SMTP_USER }}>"
87+
body: |
88+
Foram detectadas alterações a serem feitas em sua infraestrutura.
89+
90+
Aprove ou rejeite aqui:
91+
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
92+
93+
- name: Remove unnecessary folders
94+
run: |
95+
rm -rf some_examples
96+
rm -rf .github
97+
rm -rf .gitignore
98+
rm -rf .git
99+
100+
- name: ls files
101+
run: ls -ltra
102+
103+
- name: Upload artifacts
104+
if: steps.plan.outcome == 'success' && steps.plan.outputs.exitcode == '2'
105+
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: ${{ steps.bump.outputs.new_tag }}
109+
path: .
110+
111+
Terraform-Apply:
112+
runs-on: ubuntu-latest
113+
needs: Terraform-Plan
114+
environment: pre-prod-apply
115+
if: needs.Terraform-Plan.outputs.plan_exitcode == '2'
116+
env:
117+
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
118+
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
119+
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
120+
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
121+
steps:
122+
- name: Get build artifacts
123+
uses: actions/download-artifact@v4
124+
with:
125+
name: ${{ needs.Terraform-Plan.outputs.tag }}
126+
path: terraform_plan_artifacts
127+
128+
- name: Install Terraform CLI
129+
uses: hashicorp/setup-terraform@v3
130+
with:
131+
terraform_version: "1.12.2"
132+
133+
- name: Terraform Init
134+
run: terraform init
135+
working-directory: terraform_plan_artifacts
136+
137+
- name: Terraform Apply
138+
id: apply
139+
working-directory: terraform_plan_artifacts
140+
run: |
141141
terraform apply -auto-approve state_file-${{ needs.Terraform-Plan.outputs.tag }}

.github/workflows/rollback.yaml

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
name: Terraform Rollback
2-
run-name: Terraform Rollback para ${{ inputs.rollback_tag }} solicitado por ${{ github.actor }}
3-
4-
on:
5-
workflow_dispatch:
6-
inputs:
7-
rollback_tag:
8-
description: 'Para qual versão deseja voltar'
9-
required: true
10-
default: 'main'
11-
12-
jobs:
13-
rollback:
14-
runs-on: ubuntu-latest
15-
environment: pre-prod-apply
16-
env:
17-
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
18-
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
19-
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
20-
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
21-
steps:
22-
- name: Checkout código para rollback
23-
uses: actions/checkout@v4
24-
with:
25-
ref: ${{ github.event.inputs.rollback_tag }}
26-
27-
- name: Setup Terraform CLI
28-
uses: hashicorp/setup-terraform@v3
29-
with:
30-
terraform_version: "1.12.2"
31-
32-
- name: Terraform Init
33-
run: terraform init
34-
35-
- name: Terraform Validate
36-
run: terraform validate
37-
38-
- name: Terraform Plan
39-
id: plan
40-
run: terraform plan
41-
42-
- name: Check Plan Result
43-
if: steps.plan.outcome != 'success'
44-
run: |
45-
echo "Terraform plan falhou, abortando rollback."
46-
exit 1
47-
48-
- name: Terraform Apply Rollback
49-
if: steps.plan.outcome == 'success'
1+
name: Terraform Rollback
2+
run-name: Terraform Rollback para ${{ inputs.rollback_tag }} solicitado por ${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
rollback_tag:
8+
description: 'Para qual versão deseja voltar'
9+
required: true
10+
default: 'main'
11+
12+
jobs:
13+
rollback:
14+
runs-on: ubuntu-latest
15+
environment: pre-prod-apply
16+
env:
17+
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
18+
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
19+
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
20+
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
21+
steps:
22+
- name: Checkout código para rollback
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.event.inputs.rollback_tag }}
26+
27+
- name: Setup Terraform CLI
28+
uses: hashicorp/setup-terraform@v3
29+
with:
30+
terraform_version: "1.12.2"
31+
32+
- name: Terraform Init
33+
run: terraform init
34+
35+
- name: Terraform Validate
36+
run: terraform validate
37+
38+
- name: Terraform Plan
39+
id: plan
40+
run: terraform plan
41+
42+
- name: Check Plan Result
43+
if: steps.plan.outcome != 'success'
44+
run: |
45+
echo "Terraform plan falhou, abortando rollback."
46+
exit 1
47+
48+
- name: Terraform Apply Rollback
49+
if: steps.plan.outcome == 'success'
5050
run: terraform apply -auto-approve

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.terraform/
2-
.Terraform/
3-
*.hcl
4-
terraform.tfstate
5-
terraform.tfstate.backup
1+
.terraform/
2+
.Terraform/
3+
*.hcl
4+
terraform.tfstate
5+
terraform.tfstate.backup

0 commit comments

Comments
 (0)