Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 4ae8d83

Browse files
authored
Merge pull request #17 from rackspace-infrastructure-automation/gdv/custom_header_type
Update custom header type
2 parents 9bc1387 + 8b76fb3 commit 4ae8d83

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# aws-terraform-cloudfront\_s3\_origin
22

3-
This modules creates an AWS CloudFront distribution with S3 origin
4-
Enable Logging
3+
This modules creates an AWS CloudFront distribution with S3 origin
4+
### Enable Logging
55
If you enable logging the bucket must already exist. You will get an error if you try
6-
to use a dynamic bucket like "${aws\_s3\_bucket.cloudfront\_log\_s3bucket.bucket\_domain\_name}"
7-
You must use something like bucket = "MyExistingbucket"
6+
to use a dynamic bucket like `"${aws_s3_bucket.cloudfront_log_s3bucket.bucket_domain_name}"`.
7+
You must use something like `bucket = "MyExistingbucket"`.
88

99
## Basic Usage
1010

1111
```
1212
module "cloudfront_s3_origin" {
13-
source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.0"
13+
source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.1"
1414
1515
allowed_methods = ["GET", "HEAD"]
1616
bucket_logging = false
@@ -46,16 +46,22 @@ module "cloudfront_s3_origin" {
4646
},
4747
]
4848
}
49-
*
5049
```
5150

5251
Full working references are available at [examples](examples)
5352

53+
## Terraform 0.12 upgrade
54+
55+
Several changes were made while adding terraform 0.12 compatibility.
56+
The main change to be aware of is the `customer_header` variable
57+
changed types from `list(string)` to `list(map(string))` to properly function with dynamic
58+
configuration blocks.
59+
5460
## Providers
5561

5662
| Name | Version |
5763
|------|---------|
58-
| aws | >= 2.1.0 |
64+
| aws | >= 2.7.0 |
5965

6066
## Inputs
6167

@@ -71,7 +77,7 @@ Full working references are available at [examples](examples)
7177
| comment | Any comments you want to include about the distribution. (OPTIONAL) | `string` | `""` | no |
7278
| compress | Indicates whether CloudFront automatically compresses certain files for this cache behavior. (OPTIONAL) | `bool` | `false` | no |
7379
| custom\_error\_response | (Optional) - List of one or more custom error response element maps | `list(map(string))` | `[]` | no |
74-
| custom\_header | One or more sub-resources with name and value parameters that specify header data that will be sent to the origin | `list(string)` | `[]` | no |
80+
| custom\_header | One or more sub-resources with name and value parameters that specify header data that will be sent to the origin. For example: `[{name = "header1", value = "value1"}]`. | `list(map(string))` | `[]` | no |
7581
| default\_root\_object | The object that you want CloudFront to return (for example, index.html) when an end user requests the root URL. | `string` | `""` | no |
7682
| default\_ttl | The default time in seconds that objects stay in CloudFront caches before CloudFront forwards another request to your custom origin to determine whether the object has been updated. | `number` | `3600` | no |
7783
| domain\_name | The DNS domain name of either the S3 bucket, or web site of your custom origin. | `string` | `""` | no |

examples/cloudfront_s3_origin.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ terraform {
33
}
44

55
provider "aws" {
6-
region = "us-west-2"
6+
version = "~> 2.7"
7+
region = "us-west-2"
78
}
89

910
resource "random_string" "cloudfront_rstring" {
@@ -49,7 +50,7 @@ resource "aws_s3_bucket_policy" "cloudfront_s3bucket_policy" {
4950
}
5051

5152
module "cloudfront_s3_origin" {
52-
source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.0"
53+
source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.1"
5354

5455
allowed_methods = ["GET", "HEAD"]
5556
bucket_logging = false

main.tf

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* # aws-terraform-cloudfront_s3_origin
33
*
44
* This modules creates an AWS CloudFront distribution with S3 origin
5-
* Enable Logging
5+
* ### Enable Logging
66
* If you enable logging the bucket must already exist. You will get an error if you try
7-
* to use a dynamic bucket like "${aws_s3_bucket.cloudfront_log_s3bucket.bucket_domain_name}"
8-
* You must use something like bucket = "MyExistingbucket"
7+
* to use a dynamic bucket like `"${aws_s3_bucket.cloudfront_log_s3bucket.bucket_domain_name}"`.
8+
* You must use something like `bucket = "MyExistingbucket"`.
99
*
1010
* ## Basic Usage
1111
*
1212
* ```
1313
* module "cloudfront_s3_origin" {
14-
* source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.0"
14+
* source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-cloudfront_s3_origin//?ref=v0.12.1"
1515
*
1616
* allowed_methods = ["GET", "HEAD"]
1717
* bucket_logging = false
@@ -47,21 +47,27 @@
4747
* },
4848
* ]
4949
* }
50-
*```
50+
* ```
5151
*
5252
* Full working references are available at [examples](examples)
53+
*
54+
* ## Terraform 0.12 upgrade
55+
*
56+
* Several changes were made while adding terraform 0.12 compatibility.
57+
* The main change to be aware of is the `customer_header` variable
58+
* changed types from `list(string)` to `list(map(string))` to properly function with dynamic
59+
* configuration blocks.
5360
*/
5461

5562
terraform {
5663
required_version = ">= 0.12"
5764

5865
required_providers {
59-
aws = ">= 2.1.0"
66+
aws = ">= 2.7.0"
6067
}
6168
}
6269

6370
locals {
64-
bucket_logging_config = var.bucket_logging ? "enabled" : "disabled"
6571

6672
tags = {
6773
Name = var.origin_id
@@ -70,14 +76,9 @@ locals {
7076
}
7177

7278
bucket_logging = {
73-
enabled = [
74-
{
75-
bucket = var.bucket
76-
include_cookies = var.include_cookies
77-
prefix = var.prefix
78-
},
79-
]
80-
disabled = []
79+
bucket = var.bucket
80+
include_cookies = var.include_cookies
81+
prefix = var.prefix
8182
}
8283

8384
active_trusted_signers = coalescelist(
@@ -130,7 +131,7 @@ resource "aws_cloudfront_distribution" "cf_distribution" {
130131
}
131132

132133
dynamic "logging_config" {
133-
for_each = local.bucket_logging[local.bucket_logging_config]
134+
for_each = var.bucket_logging ? [local.bucket_logging] : []
134135
content {
135136
bucket = logging_config.value.bucket
136137
include_cookies = lookup(logging_config.value, "include_cookies", null)
@@ -225,7 +226,7 @@ resource "aws_cloudfront_distribution" "cf_distribution_no_s3_origin_config" {
225226
}
226227

227228
dynamic "logging_config" {
228-
for_each = local.bucket_logging[local.bucket_logging_config]
229+
for_each = var.bucket_logging ? [local.bucket_logging] : []
229230
content {
230231
bucket = logging_config.value.bucket
231232
include_cookies = lookup(logging_config.value, "include_cookies", null)

tests/test1/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
}
44

55
provider "aws" {
6-
version = "~> 2.2"
6+
version = "~> 2.7"
77
region = "us-west-2"
88
}
99

@@ -54,6 +54,7 @@ module "cloudfront_s3_origin" {
5454

5555
allowed_methods = ["GET", "HEAD"]
5656
bucket_logging = false
57+
custom_header = [{ name = "header1", value = "value1" }, { name = "header2", value = "value2" }]
5758
cached_methods = ["GET", "HEAD"]
5859
cloudfront_default_certificate = true
5960
comment = "This is a test comment"

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ variable "custom_error_response" {
6969
}
7070

7171
variable "custom_header" {
72-
description = "One or more sub-resources with name and value parameters that specify header data that will be sent to the origin"
73-
type = list(string)
72+
description = "One or more sub-resources with name and value parameters that specify header data that will be sent to the origin. For example: `[{name = \"header1\", value = \"value1\"}]`."
73+
type = list(map(string))
7474
default = []
7575
}
7676

0 commit comments

Comments
 (0)