Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #8

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "DEV DEPLOY"

on:
push:
branches:
- develop

permissions:
id-token: write
contents: read

jobs:
terraform:
uses: ./.github/workflows/terraform.yml
with:
environment: dev
aws-assume-role-arn: "arn:aws:iam::{{ sua conta aws }}:role/{{ nome da role }}"
aws-region: "sa-east-1"
aws-statefile-s3-bucket: "{{ nome do bucket s3 }}"
aws-lock-dynamodb-table: "{{ nome da tabela do dynamodb }}"
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "PROD DEPLOY"

on:
push:
branches:
- main

permissions:
id-token: write
contents: read

jobs:
terraform:
uses: ./.github/workflows/terraform.yml
with:
environment: prod
aws-assume-role-arn: "arn:aws:iam::{{ sua conta aws }}:role/{{ nome da role }}"
aws-region: "sa-east-1"
aws-statefile-s3-bucket: "{{ nome do bucket s3 }}"
aws-lock-dynamodb-table: "{{ nome da tabela do dynamodb }}"
77 changes: 0 additions & 77 deletions .github/workflows/terraform-dev.yml

This file was deleted.

77 changes: 0 additions & 77 deletions .github/workflows/terraform-prod.yml

This file was deleted.

81 changes: 81 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Terraform Workflow"

on:
workflow_call:
inputs:
environment:
type: string
required: true
aws-assume-role-arn:
type: string
required: true
aws-region:
type: string
required: true
aws-statefile-s3-bucket:
type: string
required: true
aws-lock-dynamodb-table:
type: string
required: true

jobs:
terraform:
runs-on: ubuntu-latest
defaults:
run:
shell: bash

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.aws-assume-role-arn }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ inputs.aws-region }}

- name: Read destroy configuration
id: read-destroy-config
run: |
DESTROY="$(jq -r '.${{ inputs.environment }}' ./infra/destroy_config.json)"
echo "destroy=$(echo $DESTROY)" >> $GITHUB_OUTPUT

- name: Terraform Init
run: |
cd infra && terraform init \
-backend-config="bucket=${{ inputs.aws-statefile-s3-bucket }}" \
-backend-config="key=${{ github.event.repository.name }}" \
-backend-config="region=${{ inputs.aws-region }}" \
-backend-config="dynamodb_table=${{ inputs.aws-lock-dynamodb-table }}"

- name: Terraform Validate
run: terraform validate

- name: Terraform Destroy
if: steps.read-destroy-config.outputs.destroy == 'true'
id: terraform-destroy
run: cd infra &&
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
terraform destroy -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -auto-approve

- name: Terraform Plan
if: steps.read-destroy-config.outputs.destroy != 'true'
id: terraform-plan
run: cd infra &&
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
terraform plan -var-file="./envs/${{ inputs.environment }}/terraform.tfvars" -out="${{ inputs.environment }}.plan"

- name: Terraform Apply
if: steps.read-destroy-config.outputs.destroy != 'true'
id: terraform-apply
run: cd infra &&
terraform workspace select ${{ inputs.environment }} || terraform workspace new ${{ inputs.environment }} &&
terraform apply "${{ inputs.environment }}.plan"
2 changes: 1 addition & 1 deletion infra/envs/dev/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bucket_name="dev-buildrun-pipeline-123-bucket"
bucket_name="dev-sa-east-1-buildrun-video-pipeline"
2 changes: 1 addition & 1 deletion infra/envs/prod/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bucket_name="prod-buildrun-pipeline-123-bucket"
bucket_name="prod-sa-east-1-buildrun-video-pipeline"
2 changes: 1 addition & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resource "aws_s3_bucket" "myBucket" {
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
}
File renamed without changes.
2 changes: 1 addition & 1 deletion infra/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
variable "bucket_name" {
nullable = false
type = string
}
Loading