Skip to content

Commit

Permalink
chore: Add AWS S3 bucket for Terraform state backend
Browse files Browse the repository at this point in the history
  • Loading branch information
nilgaar committed Jul 26, 2024
1 parent 1eea561 commit 9b7a7e2
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions IaC/aws/tofu/_backend.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# tofu {
# backend "s3" {
# bucket = "tofu-terraform-state"
# key = "terraform.tfstate"
# region = "eu-west-1"
# }
# }


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

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

resource "aws_s3_bucket_public_access_block" "default" {
bucket = aws_s3_bucket.state_backend.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

// Lock system
resource "aws_dynamodb_table" "tofu_backend_lock" {
name = "tofu-terraform-state-lock"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
tags = {
Name = "tofu-terraform-state-lock"
Environment = "dev"
}

}


resource "aws_s3_bucket" "state_backend" {
bucket = "tofu-terraform-state"

Expand Down

0 comments on commit 9b7a7e2

Please sign in to comment.