Skip to content

Commit

Permalink
feat(instances): add bootstrap and persist terraform-state on S3 e Dy…
Browse files Browse the repository at this point in the history
…namo
  • Loading branch information
igr-santos committed Nov 6, 2024
1 parent 110e510 commit aaf989d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Instancias

Tecnologia: terraform

### Como executar a infraestrutura

O estado do terraform está sendo compartilhado no S3 com gerenciamento de lock em uma tabela no DynamoDB.

Se o bucket configurado `bonde-terraform-up-and-running-state` não existir na lista de buckets da sua conta Amazon (região: us-east-1), você deve executar os seguintes comandos na pasta `instances/boostrap`:

```bash
terraform init
terraform plan
terraform init -auto-approve
```

Essa sequência de comandos acima irá criar a infraestrutura não persistente responsável por cuidar do estado da nossa infraestrutura persistente.

#### Executando a infraestrutura persistente



## Sites


## TODO

- Persistir o estado no S3
- Criar fluxo de trabalho para publicação automatizada no Github
48 changes: 48 additions & 0 deletions instances/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_s3_bucket" "terraform_state" {
bucket = "bonde-terraform-up-and-running-state"

# Prevent accidental deletion of this S3 bucket
lifecycle {
prevent_destroy = true
}
}

resource "aws_s3_bucket_versioning" "enabled" {
bucket = aws_s3_bucket.terraform_state.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "default" {
bucket = aws_s3_bucket.terraform_state.id

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

resource "aws_s3_bucket_public_access_block" "public_access" {
bucket = aws_s3_bucket.terraform_state.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

resource "aws_dynamodb_table" "terraform_locks" {
name = "terraform-up-and-running-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}
}
13 changes: 12 additions & 1 deletion instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ terraform {
}

required_version = ">= 1.2.0"

backend "s3" {
# Replace this with your bucket name!
bucket = "bonde-terraform-up-and-running-state"
key = "global/s3/terraform.tfstate"
region = "us-east-1"

# Replace this with your DynamoDB table name!
dynamodb_table = "terraform-up-and-running-locks"
encrypt = true
}
}

provider "aws" {
region = "us-east-1"
region = "us-east-1"
}

# Módulo para o servidor web
Expand Down

0 comments on commit aaf989d

Please sign in to comment.