Skip to content

Commit

Permalink
Feat: Add external_aliases Which Will Not Have CNAMEs Created for T…
Browse files Browse the repository at this point in the history
…hem (#199)

Co-authored-by: Michael Burns <michael@navio.com>
Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
Co-authored-by: Yonatan Koren <me@yonatankoren.com>

* Allow for aliases in CloudFront which do not get the corresponding CNAME record created in Route53.
* Misc: add BridgeCrew suppressions.
  • Loading branch information
mburns committed Dec 14, 2021
1 parent 5005fd4 commit 64bd6d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -448,6 +448,7 @@ Available targets:
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Expand Up @@ -87,6 +87,7 @@
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
8 changes: 6 additions & 2 deletions main.tf
Expand Up @@ -232,6 +232,9 @@ resource "aws_s3_bucket_policy" "default" {
resource "aws_s3_bucket" "origin" {
#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.
#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).
#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.
#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.
#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`.
count = local.create_s3_origin_bucket ? 1 : 0

bucket = module.origin_label.id
Expand Down Expand Up @@ -274,7 +277,7 @@ resource "aws_s3_bucket" "origin" {
}

dynamic "cors_rule" {
for_each = distinct(compact(concat(var.cors_allowed_origins, var.aliases)))
for_each = distinct(compact(concat(var.cors_allowed_origins, var.aliases, var.external_aliases)))
content {
allowed_headers = var.cors_allowed_headers
allowed_methods = var.cors_allowed_methods
Expand Down Expand Up @@ -323,6 +326,7 @@ data "aws_s3_bucket" "cf_logs" {
}

resource "aws_cloudfront_distribution" "default" {
#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`.
count = local.enabled ? 1 : 0

enabled = var.distribution_enabled
Expand All @@ -342,7 +346,7 @@ resource "aws_cloudfront_distribution" "default" {
}
}

aliases = var.acm_certificate_arn != "" ? var.aliases : []
aliases = var.acm_certificate_arn != "" ? concat(var.aliases, var.external_aliases) : []

dynamic "origin_group" {
for_each = var.origin_groups
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Expand Up @@ -27,6 +27,12 @@ variable "aliases" {
default = []
}

variable "external_aliases" {
type = list(string)
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"
default = []
}

variable "additional_bucket_policy" {
type = string
default = "{}"
Expand Down

0 comments on commit 64bd6d9

Please sign in to comment.