Skip to content

Commit b2299b0

Browse files
author
francisco.lucas_dp6
committed
Add S3 Bucket Terraform
1 parent d81da58 commit b2299b0

File tree

8 files changed

+101
-0
lines changed

8 files changed

+101
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
name: CI/CD Infra AWS
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
terraform:
11+
name: 'Subir Infra'
12+
runs-on: ubuntu-latest
13+
env:
14+
TF_VAR_region: ${{ vars.REGION }}
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Terraform
21+
uses: hashicorp/setup-terraform@v3
22+
with:
23+
terraform_version: 1.12.0
24+
25+
- name: Authenticate with AWS
26+
uses: aws-actions/configure-aws-credentials@v4
27+
with:
28+
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
29+
aws-secret-access-key: ${{ secrets.SECRET_KEY }}
30+
aws-region: ${{ vars.REGION }}
31+
32+
- name: Terraform Init
33+
working-directory: infra
34+
run: terraform init
35+
36+
- name: Terraform Validate
37+
working-directory: infra
38+
run: terraform validate
39+
40+
- name: Terraform Plan
41+
working-directory: infra
42+
run: terraform plan -var="region=${{ vars.REGION }}"
43+
44+
- name: Terraform Apply
45+
if: github.ref == 'refs/heads/main'
46+
working-directory: infra
47+
run: terraform apply -auto-approve -var="region=${{ vars.REGION }}"
48+

infra/backend.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
terraform {
3+
backend "s3" {
4+
bucket = "nome_bucket_terraform_states"
5+
key = "infraestrutura/dev/terraform.tfstate"
6+
region = "sa-east-1"
7+
use_lockfile = true
8+
encrypt = true
9+
}
10+
}

infra/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
provider "aws" {
3+
region = var.region
4+
}
5+
#__________________________________________________________
6+
7+
module "s3" {
8+
source = "./modules/s3"
9+
region = var.region
10+
}
11+
#__________________________________________________________

infra/modules/s3/bucket.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
resource "aws_s3_bucket" "[nome_bucket]" {
3+
bucket = local.nome_bucket
4+
acl = "private"
5+
force_destroy = false
6+
versioning {
7+
enabled = true
8+
}
9+
tags = {
10+
Name = "MinhaTag"
11+
Environment = local.environment
12+
}
13+
}

infra/modules/s3/locals.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
locals {
2+
#BUCKET NAMES
3+
#nome_bucket = "nome-unico-para-o-bucket"
4+
#environment = "dev"
5+
####################################################
6+
}

infra/modules/s3/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Valor preenchido automáticamente pelo GitHub Secrets
2+
variable "region" {
3+
description = "Região"
4+
type = string
5+
}
6+
#__________________________________________________________

infra/terraform.tfvars

Whitespace-only changes.

infra/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Valor preenchido automáticamente pelo GitHub Secrets
3+
variable "region" {
4+
description = "Região"
5+
type = string
6+
}
7+
#__________________________________________________________

0 commit comments

Comments
 (0)