Skip to content

Commit de139e3

Browse files
authored
Merge pull request #8 from buildrun-tech/develop
Develop
2 parents a474fd9 + c12fd1f commit de139e3

10 files changed

+125
-158
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+
environment: dev
17+
aws-assume-role-arn: "arn:aws:iam::{{ sua conta aws }}:role/{{ nome da role }}"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "{{ nome do bucket s3 }}"
20+
aws-lock-dynamodb-table: "{{ nome da tabela do dynamodb }}"

.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+
environment: prod
17+
aws-assume-role-arn: "arn:aws:iam::{{ sua conta aws }}:role/{{ nome da role }}"
18+
aws-region: "sa-east-1"
19+
aws-statefile-s3-bucket: "{{ nome do bucket s3 }}"
20+
aws-lock-dynamodb-table: "{{ nome da tabela do dynamodb }}"

.github/workflows/terraform-dev.yml

-77
This file was deleted.

.github/workflows/terraform-prod.yml

-77
This file was deleted.

.github/workflows/terraform.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: "Terraform Workflow"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
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: Read destroy configuration
46+
id: read-destroy-config
47+
run: |
48+
DESTROY="$(jq -r '.${{ inputs.environment }}' ./infra/destroy_config.json)"
49+
echo "destroy=$(echo $DESTROY)" >> $GITHUB_OUTPUT
50+
51+
- name: Terraform Init
52+
run: |
53+
cd infra && terraform init \
54+
-backend-config="bucket=${{ inputs.aws-statefile-s3-bucket }}" \
55+
-backend-config="key=${{ github.event.repository.name }}" \
56+
-backend-config="region=${{ inputs.aws-region }}" \
57+
-backend-config="dynamodb_table=${{ inputs.aws-lock-dynamodb-table }}"
58+
59+
- name: Terraform Validate
60+
run: terraform validate
61+
62+
- name: Terraform Destroy
63+
if: steps.read-destroy-config.outputs.destroy == 'true'
64+
id: terraform-destroy
65+
run: cd infra &&
66+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
67+
terraform destroy -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -auto-approve
68+
69+
- name: Terraform Plan
70+
if: steps.read-destroy-config.outputs.destroy != 'true'
71+
id: terraform-plan
72+
run: cd infra &&
73+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
74+
terraform plan -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -out="${{ inputs.environment }}.plan"
75+
76+
- name: Terraform Apply
77+
if: steps.read-destroy-config.outputs.destroy != 'true'
78+
id: terraform-apply
79+
run: cd infra &&
80+
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
81+
terraform apply "${{ inputs.environment }}.plan"

infra/envs/dev/terraform.tfvars

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bucket_name="dev-buildrun-pipeline-123-bucket"
1+
bucket_name="dev-sa-east-1-buildrun-video-pipeline"

infra/envs/prod/terraform.tfvars

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bucket_name="prod-buildrun-pipeline-123-bucket"
1+
bucket_name="prod-sa-east-1-buildrun-video-pipeline"

infra/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
resource "aws_s3_bucket" "myBucket" {
1+
resource "aws_s3_bucket" "bucket" {
22
bucket = var.bucket_name
33
}
File renamed without changes.

infra/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
variable "bucket_name" {
2-
nullable = false
2+
type = string
33
}

0 commit comments

Comments
 (0)