Skip to content

Commit 2dbe0c8

Browse files
authored
Fix IPv6 variables. Change AWS region for tests. Fix enabled logic. Update LICENSE (#68)
1 parent e59d7b5 commit 2dbe0c8

File tree

8 files changed

+53
-57
lines changed

8 files changed

+53
-57
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017-2019 Cloud Posse, LLC
189+
Copyright 2017-2020 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
8686
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/releases).
8787

8888

89+
90+
For a complete example, see [examples/complete](examples/complete).
91+
92+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
93+
8994
```hcl
9095
module "cdn" {
9196
source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=master"
@@ -97,8 +102,6 @@ module "cdn" {
97102
}
98103
```
99104

100-
Full working example can be found in [examples](./examples) folder.
101-
102105
### Generating ACM Certificate
103106

104107
Use the AWS cli to [request new ACM certifiates](http://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request.html) (requires email validation)
@@ -156,10 +159,10 @@ Available targets:
156159
| cors_allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucket | list(string) | `<list>` | no |
157160
| cors_allowed_origins | List of allowed origins (e.g. example.com, test.com) for S3 bucket | list(string) | `<list>` | no |
158161
| cors_expose_headers | List of expose header in the response for S3 bucket | list(string) | `<list>` | no |
159-
| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | string | `3600` | no |
162+
| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | number | `3600` | no |
160163
| custom_error_response | List of one or more custom error response element maps | object | `<list>` | no |
161164
| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no |
162-
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no |
165+
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | number | `60` | no |
163166
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
164167
| enabled | Select Enabled if you want CloudFront to begin processing requests as soon as the distribution is created, or select Disabled if you do not want CloudFront to begin processing requests after the distribution is created. | bool | `true` | no |
165168
| encryption_enabled | When set to 'true' the resource will have aes256 encryption enabled by default | bool | `false` | no |
@@ -172,20 +175,18 @@ Available targets:
172175
| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list(string) | `<list>` | no |
173176
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |
174177
| index_document | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | string | `` | no |
175-
| ipv6_enabled | Set to true to enable an AAAA DNS record to be set as well as the A record | bool | `false` | no |
176-
| is_ipv6_enabled | State of CloudFront IPv6 | bool | `true` | no |
178+
| ipv6_enabled | Set to true to enable an AAAA DNS record to be set as well as the A record | bool | `true` | no |
177179
| lambda_function_association | A config block that triggers a lambda function with specific actions | object | `<list>` | no |
178-
| log_expiration_days | Number of days after which to expunge the objects | string | `90` | no |
179-
| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | string | `60` | no |
180+
| log_expiration_days | Number of days after which to expunge the objects | number | `90` | no |
181+
| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | number | `60` | no |
180182
| log_include_cookies | Include cookies in access logs | bool | `false` | no |
181183
| log_prefix | Path of logs in S3 bucket | string | `` | no |
182-
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | string | `30` | no |
183-
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no |
184-
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no |
184+
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | number | `30` | no |
185+
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | number | `31536000` | no |
186+
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | number | `0` | no |
185187
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |
186188
| name | Name (e.g. `bastion` or `app`) | string | - | yes |
187189
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
188-
| null | an empty string | string | `` | no |
189190
| origin_bucket | Origin S3 bucket name | string | `` | no |
190191
| origin_force_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | bool | `false` | no |
191192
| origin_path | An optional element that causes CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin. It must begin with a /. Do not add a / at the end of the path. | string | `` | no |

README.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ description: |-
5656
5757
# How to use this project
5858
usage: |-
59+
60+
For a complete example, see [examples/complete](examples/complete).
61+
62+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
63+
5964
```hcl
6065
module "cdn" {
6166
source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=master"
@@ -67,8 +72,6 @@ usage: |-
6772
}
6873
```
6974
70-
Full working example can be found in [examples](./examples) folder.
71-
7275
### Generating ACM Certificate
7376
7477
Use the AWS cli to [request new ACM certifiates](http://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request.html) (requires email validation)

docs/terraform.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
| cors_allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucket | list(string) | `<list>` | no |
1616
| cors_allowed_origins | List of allowed origins (e.g. example.com, test.com) for S3 bucket | list(string) | `<list>` | no |
1717
| cors_expose_headers | List of expose header in the response for S3 bucket | list(string) | `<list>` | no |
18-
| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | string | `3600` | no |
18+
| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | number | `3600` | no |
1919
| custom_error_response | List of one or more custom error response element maps | object | `<list>` | no |
2020
| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no |
21-
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no |
21+
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | number | `60` | no |
2222
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
2323
| enabled | Select Enabled if you want CloudFront to begin processing requests as soon as the distribution is created, or select Disabled if you do not want CloudFront to begin processing requests after the distribution is created. | bool | `true` | no |
2424
| encryption_enabled | When set to 'true' the resource will have aes256 encryption enabled by default | bool | `false` | no |
@@ -31,20 +31,18 @@
3131
| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list(string) | `<list>` | no |
3232
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |
3333
| index_document | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | string | `` | no |
34-
| ipv6_enabled | Set to true to enable an AAAA DNS record to be set as well as the A record | bool | `false` | no |
35-
| is_ipv6_enabled | State of CloudFront IPv6 | bool | `true` | no |
34+
| ipv6_enabled | Set to true to enable an AAAA DNS record to be set as well as the A record | bool | `true` | no |
3635
| lambda_function_association | A config block that triggers a lambda function with specific actions | object | `<list>` | no |
37-
| log_expiration_days | Number of days after which to expunge the objects | string | `90` | no |
38-
| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | string | `60` | no |
36+
| log_expiration_days | Number of days after which to expunge the objects | number | `90` | no |
37+
| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | number | `60` | no |
3938
| log_include_cookies | Include cookies in access logs | bool | `false` | no |
4039
| log_prefix | Path of logs in S3 bucket | string | `` | no |
41-
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | string | `30` | no |
42-
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no |
43-
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no |
40+
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | number | `30` | no |
41+
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | number | `31536000` | no |
42+
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | number | `0` | no |
4443
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |
4544
| name | Name (e.g. `bastion` or `app`) | string | - | yes |
4645
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
47-
| null | an empty string | string | `` | no |
4846
| origin_bucket | Origin S3 bucket name | string | `` | no |
4947
| origin_force_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | bool | `false` | no |
5048
| origin_path | An optional element that causes CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin. It must begin with a /. Do not add a / at the end of the path. | string | `` | no |

examples/complete/fixtures.us-west-1.tfvars renamed to examples/complete/fixtures.us-east-2.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
region = "us-west-1"
1+
region = "us-east-2"
22

33
namespace = "eg"
44

main.tf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ locals {
1717
}
1818

1919
module "origin_label" {
20-
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.4.0"
20+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
2121
namespace = var.namespace
2222
stage = var.stage
2323
name = var.name
@@ -110,15 +110,15 @@ resource "aws_s3_bucket" "origin" {
110110
allowed_headers = var.cors_allowed_headers
111111
allowed_methods = var.cors_allowed_methods
112112
allowed_origins = sort(
113-
distinct(compact(concat(var.cors_allowed_origins, var.aliases))),
113+
distinct(compact(concat(var.cors_allowed_origins, var.aliases)))
114114
)
115115
expose_headers = var.cors_expose_headers
116116
max_age_seconds = var.cors_max_age_seconds
117117
}
118118
}
119119

120120
module "logs" {
121-
source = "git::https://github.com/cloudposse/terraform-aws-s3-log-storage.git?ref=tags/0.5.0"
121+
source = "git::https://github.com/cloudposse/terraform-aws-s3-log-storage.git?ref=tags/0.7.0"
122122
namespace = var.namespace
123123
stage = var.stage
124124
name = var.name
@@ -133,7 +133,7 @@ module "logs" {
133133
}
134134

135135
module "distribution_label" {
136-
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.4.0"
136+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
137137
namespace = var.namespace
138138
stage = var.stage
139139
name = var.name
@@ -147,11 +147,10 @@ data "aws_s3_bucket" "selected" {
147147
}
148148

149149
locals {
150-
bucket = join(
151-
"",
150+
bucket = join("",
152151
compact(
153-
concat([var.origin_bucket], concat([""], aws_s3_bucket.origin.*.id)),
154-
),
152+
concat([var.origin_bucket], concat([""], aws_s3_bucket.origin.*.id))
153+
)
155154
)
156155

157156
bucket_domain_name = var.use_regional_s3_endpoint ? format(
@@ -163,7 +162,7 @@ locals {
163162

164163
resource "aws_cloudfront_distribution" "default" {
165164
enabled = var.enabled
166-
is_ipv6_enabled = var.is_ipv6_enabled
165+
is_ipv6_enabled = var.ipv6_enabled
167166
comment = var.comment
168167
default_root_object = var.default_root_object
169168
price_class = var.price_class
@@ -250,7 +249,7 @@ resource "aws_cloudfront_distribution" "default" {
250249

251250
module "dns" {
252251
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.4.0"
253-
enabled = var.enabled && length(var.parent_zone_id) > 0 || length(var.parent_zone_name) > 0 ? true : false
252+
enabled = var.enabled && (var.parent_zone_id != "" || var.parent_zone_name != "") ? true : false
254253
aliases = var.aliases
255254
parent_zone_id = var.parent_zone_id
256255
parent_zone_name = var.parent_zone_name

test/src/examples_complete_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestExamplesComplete(t *testing.T) {
1616
TerraformDir: "../../examples/complete",
1717
Upgrade: true,
1818
// Variables to pass to our Terraform code using -var-file options
19-
VarFiles: []string{"fixtures.us-west-1.tfvars"},
19+
VarFiles: []string{"fixtures.us-east-2.tfvars"},
2020
}
2121

2222
// At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -27,13 +27,11 @@ func TestExamplesComplete(t *testing.T) {
2727

2828
// Run `terraform output` to get the value of an output variable
2929
cfArn := terraform.Output(t, terraformOptions, "cf_arn")
30-
3130
// Verify we're getting back the outputs we expect
32-
assert.Contains(t, cfArn, "arn:aws:cloudfront::126450723953:distribution/")
31+
assert.Contains(t, cfArn, "arn:aws:cloudfront::")
3332

3433
// Run `terraform output` to get the value of an output variable
3534
s3BucketName := terraform.Output(t, terraformOptions, "s3_bucket")
36-
3735
expectedS3BucketName := "eg-test-cloudfront-s3-cdn-origin"
3836
// Verify we're getting back the outputs we expect
3937
assert.Equal(t, expectedS3BucketName, s3BucketName)

variables.tf

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
variable "namespace" {
2-
description = "Namespace (e.g. `eg` or `cp`)"
32
type = string
3+
description = "Namespace (e.g. `eg` or `cp`)"
44
default = ""
55
}
66

77
variable "stage" {
8-
description = "Stage (e.g. `prod`, `dev`, `staging`)"
98
type = string
9+
description = "Stage (e.g. `prod`, `dev`, `staging`)"
1010
default = ""
1111
}
1212

1313
variable "name" {
14-
description = "Name (e.g. `bastion` or `app`)"
1514
type = string
15+
description = "Name (e.g. `bastion` or `app`)"
1616
}
1717

1818
variable "delimiter" {
@@ -112,12 +112,6 @@ variable "compress" {
112112
description = "Compress content for web requests that include Accept-Encoding: gzip in the request header"
113113
}
114114

115-
variable "is_ipv6_enabled" {
116-
type = bool
117-
default = true
118-
description = "State of CloudFront IPv6"
119-
}
120-
121115
variable "default_root_object" {
122116
type = string
123117
default = "index.html"
@@ -143,16 +137,19 @@ variable "log_prefix" {
143137
}
144138

145139
variable "log_standard_transition_days" {
140+
type = number
146141
description = "Number of days to persist in the standard storage tier before moving to the glacier tier"
147142
default = 30
148143
}
149144

150145
variable "log_glacier_transition_days" {
146+
type = number
151147
description = "Number of days after which to move the data to the glacier storage tier"
152148
default = 60
153149
}
154150

155151
variable "log_expiration_days" {
152+
type = number
156153
description = "Number of days after which to expunge the objects"
157154
default = 90
158155
}
@@ -188,6 +185,7 @@ variable "cors_expose_headers" {
188185
}
189186

190187
variable "cors_max_age_seconds" {
188+
type = number
191189
default = 3600
192190
description = "Time in seconds that browser can cache the response for S3 bucket"
193191
}
@@ -229,16 +227,19 @@ variable "cached_methods" {
229227
}
230228

231229
variable "default_ttl" {
230+
type = number
232231
default = 60
233232
description = "Default amount of time (in seconds) that an object is in a CloudFront cache"
234233
}
235234

236235
variable "min_ttl" {
236+
type = number
237237
default = 0
238238
description = "Minimum amount of time that you want objects to stay in CloudFront caches"
239239
}
240240

241241
variable "max_ttl" {
242+
type = number
242243
default = 31536000
243244
description = "Maximum amount of time (in seconds) that an object is in a CloudFront cache"
244245
}
@@ -250,10 +251,11 @@ variable "trusted_signers" {
250251
}
251252

252253
variable "geo_restriction_type" {
254+
type = string
255+
253256
# e.g. "whitelist"
254257
default = "none"
255258
description = "Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist`"
256-
type = string
257259
}
258260

259261
variable "geo_restriction_locations" {
@@ -276,11 +278,6 @@ variable "parent_zone_name" {
276278
description = "Name of the hosted zone to contain this record (or specify `parent_zone_id`)"
277279
}
278280

279-
variable "null" {
280-
description = "an empty string"
281-
default = ""
282-
}
283-
284281
variable "static_s3_bucket" {
285282
type = string
286283
default = "aws-cli"
@@ -365,6 +362,6 @@ variable "routing_rules" {
365362

366363
variable "ipv6_enabled" {
367364
type = bool
368-
default = false
365+
default = true
369366
description = "Set to true to enable an AAAA DNS record to be set as well as the A record"
370-
}
367+
}

0 commit comments

Comments
 (0)