Skip to content

Commit 2bb2a7c

Browse files
authored
Merge pull request #2 from Heider1988/develop
Develop
2 parents fa0022c + 5ba7ad6 commit 2bb2a7c

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

.github/workflows/developer.yml

Lines changed: 20 additions & 0 deletions
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+
enviroment: dev
17+
aws-assume-role-arn: "arn:aws:iam::243637693710:role/github-actions-heideroliveira-pipeline"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "heider1988-sa-east-1-terraform-statefile"
20+
aws-lock-dynamodb-table: "heider1988-sa-east-1-terraform-lock"

.github/workflows/main.yml

Lines changed: 20 additions & 0 deletions
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+
enviroment: prod
17+
aws-assume-role-arn: "arn:aws:iam::243637693710:role/github-actions-heideroliveira-pipeline"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "heider1988-sa-east-1-terraform-statefile"
20+
aws-lock-dynamodb-table: "heider1988-sa-east-1-terraform-lock"

.github/workflows/terraform.yml

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34+
35+
### terraform ###
36+
.terraform

infra/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
resource "aws_s3_bucket" "bucket" {
2-
bucket = var.bucket_name
3-
}
2+
bucket = "${var.bucket_name}-${random_string.bucket_suffix.result}"
3+
}
4+
5+
resource "random_string" "bucket_suffix" {
6+
length = 8
7+
special = false
8+
upper = false
9+
}

0 commit comments

Comments
 (0)