Created
June 23, 2020 03:44
-
-
Save ksummersill2/6c0b368c3d971fecce9113c5a65f18b9 to your computer and use it in GitHub Desktop.
S3 Bucket resource for Terraform State
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# S3 Bucket Used by the Terraform State Management | |
# Must be initialized first prior to uncommiting the configuration for terraform | |
resource "aws_s3_bucket" "devsecops-bc-state" { | |
bucket = "devsecops-bc-state" | |
versioning { | |
enabled = true | |
} | |
server_side_encryption_configuration { | |
rule { | |
apply_server_side_encryption_by_default { | |
sse_algorithm = "AES256" | |
} | |
} | |
} | |
} | |
# Setup the S3 Bucket Policy Required by Terraform | |
resource "aws_s3_bucket_policy" "devsecops-bc-state-policy" { | |
bucket = aws_s3_bucket.devsecops-bc-state.id | |
policy = <<POLICY | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Principal": "*", | |
"Effect": "Allow", | |
"Action": "s3:ListBucket", | |
"Resource": "${aws_s3_bucket.devsecops-bc-state.arn}" | |
}, | |
{ | |
"Principal": "*", | |
"Effect": "Allow", | |
"Action": ["s3:GetObject", "s3:PutObject"], | |
"Resource": [ "${aws_s3_bucket.devsecops-bc-state.arn}/*" ] | |
} | |
] | |
} | |
POLICY | |
} | |
# S3 Bucket Terraform ARN | |
output "aws_terraform_arn" { | |
value = aws_s3_bucket.devsecops-bc-state.arn | |
description = "The ARN associated to the S3 Bucket" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment