-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring Terraform For Scratch Deployment #721
Changes from 6 commits
44cdf0c
41a5df2
7449efa
63ed8a5
8f90d55
72179b0
1ab2df0
cd8c049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ resource "aws_s3_bucket_public_access_block" "csv_bucket" { | |
|
||
resource "aws_s3_bucket" "csv_bucket_logs" { | ||
bucket = "notification-canada-ca-${var.env}-csv-upload-logs" | ||
acl = "log-delivery-write" | ||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
|
@@ -69,6 +68,32 @@ resource "aws_s3_bucket" "csv_bucket_logs" { | |
#tfsec:ignore:AWS077 - Versioning is not enabled | ||
} | ||
|
||
resource "aws_s3_bucket_public_access_block" "csv_bucket_logs" { | ||
bucket = aws_s3_bucket.csv_bucket_logs.id | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "csv_bucket_logs" { | ||
bucket = aws_s3_bucket.csv_bucket_logs.id | ||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "csv_bucket_logs" { | ||
depends_on = [ | ||
aws_s3_bucket_public_access_block.csv_bucket_logs, | ||
aws_s3_bucket_ownership_controls.csv_bucket_logs, | ||
] | ||
|
||
bucket = aws_s3_bucket.csv_bucket_logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
resource "aws_s3_bucket" "bulk_send" { | ||
bucket = "notification-canada-ca-${var.env}-bulk-send" | ||
acl = "private" | ||
|
@@ -110,7 +135,6 @@ resource "aws_s3_bucket_public_access_block" "bulk_send" { | |
|
||
resource "aws_s3_bucket" "bulk_send_logs" { | ||
bucket = "notification-canada-ca-${var.env}-bulk-send-logs" | ||
acl = "log-delivery-write" | ||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
|
@@ -135,15 +159,33 @@ resource "aws_s3_bucket" "bulk_send_logs" { | |
#tfsec:ignore:AWS077 - Versioning is not enabled | ||
} | ||
|
||
resource "aws_s3_bucket_public_access_block" "csv_bucket_logs" { | ||
bucket = aws_s3_bucket.csv_bucket_logs.id | ||
resource "aws_s3_bucket_public_access_block" "bulk_send_logs" { | ||
bucket = aws_s3_bucket.bulk_send_logs.id | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "bulk_send_logs" { | ||
bucket = aws_s3_bucket.bulk_send_logs.id | ||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "bulk_send_logs" { | ||
depends_on = [ | ||
aws_s3_bucket_public_access_block.bulk_send_logs, | ||
aws_s3_bucket_ownership_controls.bulk_send_logs, | ||
] | ||
|
||
bucket = aws_s3_bucket.bulk_send_logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
|
||
resource "aws_s3_bucket" "asset_bucket" { | ||
bucket = "notification-canada-ca-${var.env}-asset-upload" | ||
server_side_encryption_configuration { | ||
|
@@ -301,7 +343,6 @@ resource "aws_s3_bucket_public_access_block" "scan_files_document_bucket" { | |
|
||
resource "aws_s3_bucket" "document_bucket_logs" { | ||
bucket = "notification-canada-ca-${var.env}-document-download-logs" | ||
acl = "log-delivery-write" | ||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
|
@@ -335,6 +376,23 @@ resource "aws_s3_bucket_public_access_block" "document_bucket_logs" { | |
restrict_public_buckets = true | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "document_bucket_logs" { | ||
bucket = aws_s3_bucket.document_bucket_logs.id | ||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "document_bucket_logs" { | ||
depends_on = [ | ||
aws_s3_bucket_public_access_block.document_bucket_logs, | ||
aws_s3_bucket_ownership_controls.document_bucket_logs, | ||
] | ||
|
||
bucket = aws_s3_bucket.document_bucket_logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
resource "aws_s3_bucket" "alb_log_bucket" { | ||
bucket = "notification-canada-ca-${var.env}-alb-logs" | ||
acl = "private" | ||
|
@@ -454,7 +512,6 @@ resource "aws_s3_bucket_public_access_block" "athena_bucket" { | |
|
||
resource "aws_s3_bucket" "athena_bucket_logs" { | ||
bucket = "notification-canada-ca-${var.env}-athena-logs" | ||
acl = "log-delivery-write" | ||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
|
@@ -478,3 +535,81 @@ resource "aws_s3_bucket" "athena_bucket_logs" { | |
#tfsec:ignore:AWS002 - Ignore log of logs | ||
#tfsec:ignore:AWS077 - Versioning is not enabled | ||
} | ||
|
||
resource "aws_s3_bucket_public_access_block" "athena_bucket_logs" { | ||
bucket = aws_s3_bucket.athena_bucket_logs.id | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "athena_bucket_logs" { | ||
bucket = aws_s3_bucket.athena_bucket_logs.id | ||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "athena_bucket_logs" { | ||
depends_on = [ | ||
aws_s3_bucket_public_access_block.athena_bucket_logs, | ||
aws_s3_bucket_ownership_controls.athena_bucket_logs, | ||
] | ||
|
||
bucket = aws_s3_bucket.athena_bucket_logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
resource "aws_s3_bucket" "cbs_sensor_bucket" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the CBS bucket is being managed here for all accounts: If you want to bring it into this repo you'll need to do a bit of IAM setup and add replication rules so it can send objects to the log archive account's bucket: Happy to chat about this if you want more details. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Pat - based on this info I think I will refactor this. |
||
bucket = "cbs-satellite-${var.account_id}" | ||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
sse_algorithm = "AES256" | ||
} | ||
} | ||
} | ||
|
||
lifecycle_rule { | ||
enabled = true | ||
|
||
expiration { | ||
days = 14 | ||
} | ||
} | ||
|
||
tags = { | ||
CostCenter = "notification-canada-ca-${var.env}" | ||
} | ||
|
||
#tfsec:ignore:AWS002 - Ignore log of logs | ||
#tfsec:ignore:AWS077 - Versioning is not enabled | ||
} | ||
|
||
resource "aws_s3_bucket_public_access_block" "cbs_sensor_bucket" { | ||
bucket = aws_s3_bucket.cbs_sensor_bucket.id | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "cbs_sensor_bucket" { | ||
bucket = aws_s3_bucket.cbs_sensor_bucket.id | ||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "cbs_sensor_bucket" { | ||
depends_on = [ | ||
aws_s3_bucket_public_access_block.cbs_sensor_bucket, | ||
aws_s3_bucket_ownership_controls.cbs_sensor_bucket, | ||
] | ||
|
||
bucket = aws_s3_bucket.cbs_sensor_bucket.id | ||
acl = "log-delivery-write" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you seen our Terraform modules?
https://github.com/cds-snc/terraform-modules
We have modules for S3 Buckets that might be useful.
When v5 of the AWS Provider comes out and this type of bucket is finally deprecated I plan on fixing the s3 bucket module so it automatically refactors to the new way of building them.
It also configures them in a consistent that meets some of our organizational defined best practices.
It's not 100% perfect so open to any issues that can help us secure and make our orgs infra better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Calvin. I'd probably still proceed with this PR for now, but once we're back into a state where things actually build I'll do some investigation in to what modules we can leverage. Happy to be a contributor to make them as useful and secure as possible 👍