Skip to content

Commit

Permalink
add aws provider v4 s3 things
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed May 6, 2022
1 parent fe020a0 commit d96cee2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
5 changes: 5 additions & 0 deletions terraform-state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ No modules.
| [aws_kms_alias.tfstate_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource |
| [aws_kms_key.tfstate_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_s3_bucket.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_acl.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
| [aws_s3_bucket_logging.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | resource |
| [aws_s3_bucket_ownership_controls.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_public_access_block.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [aws_s3_bucket_versioning.tfstate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy.group_managed_policies](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
Expand Down
51 changes: 38 additions & 13 deletions terraform-state/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,6 @@ resource "aws_s3_bucket" "tfstate" {
bucket = local.tfstate_bucket
acl = "private"

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.tfstate_key.arn
sse_algorithm = "aws:kms"
}
}
}

versioning {
enabled = true
}

lifecycle {
prevent_destroy = true
ignore_changes = [tags["boc:tf_module_version"]]
Expand All @@ -131,6 +118,13 @@ resource "aws_s3_bucket" "tfstate" {

}

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

resource "aws_s3_bucket_public_access_block" "tfstate" {
bucket = aws_s3_bucket.tfstate.id
block_public_acls = true
Expand All @@ -139,6 +133,36 @@ resource "aws_s3_bucket_public_access_block" "tfstate" {
restrict_public_buckets = true
}

resource "aws_s3_bucket_logging" "tfstate" {
bucket = aws_s3_bucket.tfstate.id
target_bucket = var.access_log_bucket
target_prefix = format("%s/%s/", var.access_log_bucket_prefix, local.bucket_name)
}

resource "aws_s3_bucket_server_side_encryption_configuration" "tfstate" {
bucket = aws_s3_bucket.tfstate.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.tfstate_key.arn
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_ownership_controls" "tfstate" {
bucket = aws_s3_bucket.tfstate.id
rule {
object_ownership = "BucketOwnerEnforced"
}
}

resource "aws_s3_bucket_acl" "tfstate" {
# count = var.bucket_owner == "BucketOwnerEnforced" ? 0 : 1
count = 0
bucket = aws_s3_bucket.tfstate.id
acl = "private"
}

#---
# kms
#---
Expand All @@ -164,3 +188,4 @@ resource "aws_kms_alias" "tfstate_key" {
target_key_id = aws_kms_key.tfstate_key.key_id
}


0 comments on commit d96cee2

Please sign in to comment.