Skip to content

Commit 64bd6d9

Browse files
authored
Feat: Add external_aliases Which Will Not Have CNAMEs Created for Them (#199)
Co-authored-by: Michael Burns <[email protected]> Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: Yonatan Koren <[email protected]> * Allow for aliases in CloudFront which do not get the corresponding CNAME record created in Route53. * Misc: add BridgeCrew suppressions.
1 parent 5005fd4 commit 64bd6d9

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ Available targets:
448448
| <a name="input_encryption_enabled"></a> [encryption\_enabled](#input\_encryption\_enabled) | When set to 'true' the resource will have aes256 encryption enabled by default | `bool` | `true` | no |
449449
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
450450
| <a name="input_error_document"></a> [error\_document](#input\_error\_document) | An absolute path to the document to return in case of a 4XX error | `string` | `""` | no |
451+
| <a name="input_external_aliases"></a> [external\_aliases](#input\_external\_aliases) | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront. No new route53 records will be created for these | `list(string)` | `[]` | no |
451452
| <a name="input_extra_logs_attributes"></a> [extra\_logs\_attributes](#input\_extra\_logs\_attributes) | Additional attributes to add to the end of the generated Cloudfront Access Log S3 Bucket name.<br>Only effective if `cloudfront_access_log_create_bucket` is `true`. | `list(string)` | <pre>[<br> "logs"<br>]</pre> | no |
452453
| <a name="input_extra_origin_attributes"></a> [extra\_origin\_attributes](#input\_extra\_origin\_attributes) | Additional attributes to put onto the origin label | `list(string)` | <pre>[<br> "origin"<br>]</pre> | no |
453454
| <a name="input_forward_cookies"></a> [forward\_cookies](#input\_forward\_cookies) | Specifies whether you want CloudFront to forward all or no cookies to the origin. Can be 'all' or 'none' | `string` | `"none"` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
| <a name="input_encryption_enabled"></a> [encryption\_enabled](#input\_encryption\_enabled) | When set to 'true' the resource will have aes256 encryption enabled by default | `bool` | `true` | no |
8888
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
8989
| <a name="input_error_document"></a> [error\_document](#input\_error\_document) | An absolute path to the document to return in case of a 4XX error | `string` | `""` | no |
90+
| <a name="input_external_aliases"></a> [external\_aliases](#input\_external\_aliases) | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront. No new route53 records will be created for these | `list(string)` | `[]` | no |
9091
| <a name="input_extra_logs_attributes"></a> [extra\_logs\_attributes](#input\_extra\_logs\_attributes) | Additional attributes to add to the end of the generated Cloudfront Access Log S3 Bucket name.<br>Only effective if `cloudfront_access_log_create_bucket` is `true`. | `list(string)` | <pre>[<br> "logs"<br>]</pre> | no |
9192
| <a name="input_extra_origin_attributes"></a> [extra\_origin\_attributes](#input\_extra\_origin\_attributes) | Additional attributes to put onto the origin label | `list(string)` | <pre>[<br> "origin"<br>]</pre> | no |
9293
| <a name="input_forward_cookies"></a> [forward\_cookies](#input\_forward\_cookies) | Specifies whether you want CloudFront to forward all or no cookies to the origin. Can be 'all' or 'none' | `string` | `"none"` | no |

main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ resource "aws_s3_bucket_policy" "default" {
232232
resource "aws_s3_bucket" "origin" {
233233
#bridgecrew:skip=BC_AWS_S3_13:Skipping `Enable S3 Bucket Logging` because we cannot enable it by default because we do not have a default destination for it.
234234
#bridgecrew:skip=CKV_AWS_52:Skipping `Ensure S3 bucket has MFA delete enabled` due to issue in terraform (https://github.com/hashicorp/terraform-provider-aws/issues/629).
235+
#bridgecrew:skip=BC_AWS_NETWORKING_52:Skipping `Ensure S3 Bucket has public access blocks` because we have an `aws_s3_bucket_public_access_block` resource rather than inline `block_public_*` attributes.
236+
#bridgecrew:skip=BC_AWS_GENERAL_72:Skipping `Ensure S3 bucket has cross-region replication enabled` because this is out of scope of this module's use case.
237+
#bridgecrew:skip=BC_AWS_GENERAL_56:Skipping `Ensure S3 buckets are encrypted with KMS by default` because this module has configurable encryption via `var.encryption_enabled`.
235238
count = local.create_s3_origin_bucket ? 1 : 0
236239

237240
bucket = module.origin_label.id
@@ -274,7 +277,7 @@ resource "aws_s3_bucket" "origin" {
274277
}
275278

276279
dynamic "cors_rule" {
277-
for_each = distinct(compact(concat(var.cors_allowed_origins, var.aliases)))
280+
for_each = distinct(compact(concat(var.cors_allowed_origins, var.aliases, var.external_aliases)))
278281
content {
279282
allowed_headers = var.cors_allowed_headers
280283
allowed_methods = var.cors_allowed_methods
@@ -323,6 +326,7 @@ data "aws_s3_bucket" "cf_logs" {
323326
}
324327

325328
resource "aws_cloudfront_distribution" "default" {
329+
#bridgecrew:skip=BC_AWS_GENERAL_27:Skipping `Ensure CloudFront distribution has WAF enabled` because AWS WAF is indeed configurable and is managed via `var.web_acl_id`.
326330
count = local.enabled ? 1 : 0
327331

328332
enabled = var.distribution_enabled
@@ -342,7 +346,7 @@ resource "aws_cloudfront_distribution" "default" {
342346
}
343347
}
344348

345-
aliases = var.acm_certificate_arn != "" ? var.aliases : []
349+
aliases = var.acm_certificate_arn != "" ? concat(var.aliases, var.external_aliases) : []
346350

347351
dynamic "origin_group" {
348352
for_each = var.origin_groups

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ variable "aliases" {
2727
default = []
2828
}
2929

30+
variable "external_aliases" {
31+
type = list(string)
32+
description = "List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront. No new route53 records will be created for these"
33+
default = []
34+
}
35+
3036
variable "additional_bucket_policy" {
3137
type = string
3238
default = "{}"

0 commit comments

Comments
 (0)