File tree Expand file tree Collapse file tree 5 files changed +125
-2
lines changed Expand file tree Collapse file tree 5 files changed +125
-2
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 3131
3232# ## VS Code ###
3333.vscode /
34+
35+ # ## terraform ###
36+ .terraform
Original file line number Diff line number Diff line change 11resource "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+ }
You can’t perform that action at this time.
0 commit comments