Skip to content

Commit

Permalink
Merge pull request #168 from dxw/allow-custom-key-policy-statements-a…
Browse files Browse the repository at this point in the history
…nd-bucket-policy-for-custom-buckets

Allow custom policies for custom S3 buckets
  • Loading branch information
Stretch96 authored Sep 30, 2024
2 parents 6241691 + 26e0cc5 commit 3bea38e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ This project creates and manages resources within an AWS account for infrastruct
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region in which to launch resources | `string` | n/a | yes |
| <a name="input_custom_cloudformation_stacks"></a> [custom\_cloudformation\_stacks](#input\_custom\_cloudformation\_stacks) | Map of CloudFormation stacks to deploy<br/> {<br/> stack-name = {<br/> s3\_template\_store\_key: The filename of a CloudFormation template that is stored within the S3 bucket, created by the `enable_cloudformatian_s3_template_store`<br/> template\_body: (Optional - use of s3\_template\_store\_key is preferred) The CloudFormation template body<br/> parameters: The CloudFormation template parameters ({ parameter-name = parameter-value, ... })<br/> on\_failure: What to do on failure, either 'DO\_NOTHING', 'ROLLBACK' or 'DELETE'<br/> capabilities: A list of capabilities. Valid values: `CAPABILITY_NAMED_IAM`, `CAPABILITY_IAM`, `CAPABILITY_AUTO_EXPAND`<br/> }<br/> } | <pre>map(object({<br/> s3_template_store_key = optional(string, null)<br/> template_body = optional(string, null)<br/> parameters = optional(map(string), null)<br/> on_failure = optional(string, null)<br/> capabilities = optional(list(string), null)<br/> }))</pre> | n/a | yes |
| <a name="input_custom_route53_hosted_zones"></a> [custom\_route53\_hosted\_zones](#input\_custom\_route53\_hosted\_zones) | Map of Route53 Hosted Zone configurations to create<br/> {<br/> example.com = {<br/> ns\_records: Map of NS records to create ({ "domain.example.com" = { values = ["ns1.example.com", "ns2.example.com"], ttl = 300 })<br/> a\_records: Map of A records to create ({ "domain.example.com" = { values = ["1.2.3.4", "5.6.7.8"], ttl = 300 })<br/> alias\_records: Map of ALIAS records to create ({ "domain.example.com" = { value = "example.cloudfront.com", zone\_id = "Z2FDTNDATAQYW2" })<br/> cname\_records: Map of CNAME records to create ({ "domain.example.com" = { values = ["external1.example.com", "external2.example.com"], ttl = 60 })<br/> mx\_records: Map of MX records to create ({ "example.com" = { values = ["1 mail.example.com", "5 mail2.example.com"], ttl = 60 })<br/> txt\_records: Map of TXT records to create ({ "example.com" = { values = ["v=spf1 include:spf.example.com -all"], ttl = 60 })<br/> }<br/> } | <pre>map(object({<br/> ns_records = optional(map(object({<br/> values = list(string)<br/> ttl = optional(number, 300)<br/> })), null)<br/> a_records = optional(map(object({<br/> values = list(string)<br/> ttl = optional(number, 300)<br/> })), null)<br/> alias_records = optional(map(object({<br/> value = string<br/> zone_id = string<br/> })), null)<br/> cname_records = optional(map(object({<br/> values = list(string)<br/> ttl = optional(number, 300)<br/> })), null)<br/> mx_records = optional(map(object({<br/> values = list(string)<br/> ttl = optional(number, 300)<br/> })), null)<br/> txt_records = optional(map(object({<br/> values = list(string)<br/> ttl = optional(number, 300)<br/> })), null)<br/> }))</pre> | n/a | yes |
| <a name="input_custom_s3_buckets"></a> [custom\_s3\_buckets](#input\_custom\_s3\_buckets) | Map of S3 buckets to create, and conditionally serve via CloudFront. The S3 configuration will follow AWS best practices (eg. Private, ACLS disabled, SSE, Versioning, Logging). The bucket must be emptied before attempting deletion/destruction."<br/> {<br/> bucket-name = {<br/> create\_dedicated\_kms\_key: Conditionally create a KMS key specifically for this bucket's server side encryption (rather than using the Infrastructure's KMS key). It's recommended to use this if the S3 bucket will be accessed from external AWS accounts.<br/> transition\_to\_ia\_days: Conditionally transition objects to 'Standard Infrequent Access' storage in N days<br/> transition\_to\_glacier\_days: Conditionally transition objects to 'Glacier' storage in N days<br/> cloudfront\_dedicated\_distribution: Conditionally create a CloudFront distribution to serve objects from the S3 bucket.<br/> cloudfront\_s3\_root: Sets the S3 document root when being served from CloudFront. By default this will be '/'. If `cloudfront_infrastructure_ecs_cluster_service_path` has been set, this helps by modifying the request from `/sub-directory-path` to `/` by use of a CloudFront function.<br/> cloudfront\_infrastructure\_ecs\_cluster\_service: Conditionally create an Origin on a CloudFront distribution that is serving the given Infrastructure ECS Cluster Service name<br/> cloudfront\_infrastructure\_ecs\_cluster\_service\_path: If `cloudfront_infrastructure_ecs_cluster_service`, set this to the path that objects will be served from.<br/> }<br/> } | <pre>map(object({<br/> create_dedicated_kms_key = optional(bool, null)<br/> transition_to_ia_days = optional(number, null)<br/> transition_to_glacier_days = optional(number, null)<br/> cloudfront_dedicated_distribution = optional(bool, null)<br/> cloudfront_s3_root = optional(string, null)<br/> cloudfront_infrastructure_ecs_cluster_service = optional(string, null)<br/> cloudfront_infrastructure_ecs_cluster_service_path = optional(string, null)<br/> }))</pre> | n/a | yes |
| <a name="input_custom_s3_buckets"></a> [custom\_s3\_buckets](#input\_custom\_s3\_buckets) | Map of S3 buckets to create, and conditionally serve via CloudFront. The S3 configuration will follow AWS best practices (eg. Private, ACLS disabled, SSE, Versioning, Logging). The bucket must be emptied before attempting deletion/destruction."<br/> {<br/> bucket-name = {<br/> create\_dedicated\_kms\_key: Conditionally create a KMS key specifically for this bucket's server side encryption (rather than using the Infrastructure's KMS key). It's recommended to use this if the S3 bucket will be accessed from external AWS accounts.<br/> custom\_kms\_key\_policy\_statements: Conditionally add a list of user-defined key policy statements<br/> transition\_to\_ia\_days: Conditionally transition objects to 'Standard Infrequent Access' storage in N days<br/> transition\_to\_glacier\_days: Conditionally transition objects to 'Glacier' storage in N days<br/> cloudfront\_dedicated\_distribution: Conditionally create a CloudFront distribution to serve objects from the S3 bucket.<br/> cloudfront\_s3\_root: Sets the S3 document root when being served from CloudFront. By default this will be '/'. If `cloudfront_infrastructure_ecs_cluster_service_path` has been set, this helps by modifying the request from `/sub-directory-path` to `/` by use of a CloudFront function.<br/> cloudfront\_infrastructure\_ecs\_cluster\_service: Conditionally create an Origin on a CloudFront distribution that is serving the given Infrastructure ECS Cluster Service name<br/> cloudfront\_infrastructure\_ecs\_cluster\_service\_path: If `cloudfront_infrastructure_ecs_cluster_service`, set this to the path that objects will be served from.<br/> custom\_bucket\_policy\_statements: Conditionally add a list of user-defined bucket policy statements<br/> }<br/> } | <pre>map(object({<br/> create_dedicated_kms_key = optional(bool, null)<br/> custom_kms_key_policy_statements = optional(list(object({<br/> Effect = string,<br/> Principal = map(any),<br/> Action = list(string),<br/> Resource = string,<br/> Condition = optional(map(any), {})<br/> })), [])<br/> transition_to_ia_days = optional(number, null)<br/> transition_to_glacier_days = optional(number, null)<br/> cloudfront_dedicated_distribution = optional(bool, null)<br/> cloudfront_s3_root = optional(string, null)<br/> cloudfront_infrastructure_ecs_cluster_service = optional(string, null)<br/> cloudfront_infrastructure_ecs_cluster_service_path = optional(string, null)<br/> custom_bucket_policy_statements = optional(list(object({<br/> Effect = string,<br/> Principal = map(any),<br/> Action = list(string),<br/> Resource = string,<br/> Condition = optional(map(any), {})<br/> })), [])<br/> }))</pre> | n/a | yes |
| <a name="input_ecs_cluster_efs_directories"></a> [ecs\_cluster\_efs\_directories](#input\_ecs\_cluster\_efs\_directories) | ECS cluster EFS directories to create | `list(string)` | n/a | yes |
| <a name="input_ecs_cluster_efs_infrequent_access_transition"></a> [ecs\_cluster\_efs\_infrequent\_access\_transition](#input\_ecs\_cluster\_efs\_infrequent\_access\_transition) | ECS cluser EFS IA transiton in days. Set to 0 to disable IA transition. | `number` | n/a | yes |
| <a name="input_ecs_cluster_efs_performance_mode"></a> [ecs\_cluster\_efs\_performance\_mode](#input\_ecs\_cluster\_efs\_performance\_mode) | ECS cluser EFS performance mode | `string` | n/a | yes |
Expand Down
2 changes: 1 addition & 1 deletion s3-custom-buckets-kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resource "aws_kms_key" "custom_s3_buckets" {
each.value["cloudfront_infrastructure_ecs_cluster_service"] != null ? [aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.value["cloudfront_infrastructure_ecs_cluster_service"]].arn] : []
)))
}
)}
)}${length(each.value["custom_kms_key_policy_statements"]) != 0 ? ",${trim(jsonencode(each.value["custom_kms_key_policy_statements"]), "[]")}" : ""}
]
EOT
}
Expand Down
2 changes: 1 addition & 1 deletion s3-custom-buckets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "aws_s3_bucket_policy" "custom" {
[for k, v in local.custom_s3_buckets : aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[v["cloudfront_infrastructure_ecs_cluster_service"]].arn if v["cloudfront_infrastructure_ecs_cluster_service"] != null]
)))
}
)}
)}${length(each.value["custom_bucket_policy_statements"]) != 0 ? ",${trim(jsonencode(each.value["custom_bucket_policy_statements"]), "[]")}" : ""}
]
EOT
}
Expand Down
18 changes: 17 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -846,23 +846,39 @@ variable "custom_s3_buckets" {
{
bucket-name = {
create_dedicated_kms_key: Conditionally create a KMS key specifically for this bucket's server side encryption (rather than using the Infrastructure's KMS key). It's recommended to use this if the S3 bucket will be accessed from external AWS accounts.
custom_kms_key_policy_statements: Conditionally add a list of user-defined key policy statements
transition_to_ia_days: Conditionally transition objects to 'Standard Infrequent Access' storage in N days
transition_to_glacier_days: Conditionally transition objects to 'Glacier' storage in N days
cloudfront_dedicated_distribution: Conditionally create a CloudFront distribution to serve objects from the S3 bucket.
cloudfront_s3_root: Sets the S3 document root when being served from CloudFront. By default this will be '/'. If `cloudfront_infrastructure_ecs_cluster_service_path` has been set, this helps by modifying the request from `/sub-directory-path` to `/` by use of a CloudFront function.
cloudfront_infrastructure_ecs_cluster_service: Conditionally create an Origin on a CloudFront distribution that is serving the given Infrastructure ECS Cluster Service name
cloudfront_infrastructure_ecs_cluster_service_path: If `cloudfront_infrastructure_ecs_cluster_service`, set this to the path that objects will be served from.
custom_bucket_policy_statements: Conditionally add a list of user-defined bucket policy statements
}
}
EOT
type = map(object({
create_dedicated_kms_key = optional(bool, null)
create_dedicated_kms_key = optional(bool, null)
custom_kms_key_policy_statements = optional(list(object({
Effect = string,
Principal = map(any),
Action = list(string),
Resource = string,
Condition = optional(map(any), {})
})), [])
transition_to_ia_days = optional(number, null)
transition_to_glacier_days = optional(number, null)
cloudfront_dedicated_distribution = optional(bool, null)
cloudfront_s3_root = optional(string, null)
cloudfront_infrastructure_ecs_cluster_service = optional(string, null)
cloudfront_infrastructure_ecs_cluster_service_path = optional(string, null)
custom_bucket_policy_statements = optional(list(object({
Effect = string,
Principal = map(any),
Action = list(string),
Resource = string,
Condition = optional(map(any), {})
})), [])
}))
}

Expand Down

0 comments on commit 3bea38e

Please sign in to comment.