Skip to content

Commit f6420b3

Browse files
Jamie-BitFlightaknysh
authored andcommitted
fixing regional support (#29)
* fixing regional support * Fix descriptions. Bump module versions. Update README
1 parent b0960c0 commit f6420b3

File tree

11 files changed

+141
-83
lines changed

11 files changed

+141
-83
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
**/*.tfstate
33
**/*.tfstate.backup
44
**/*.terraform.tfstate*
5+
56
# Module directory
67
.idea
78
*.iml
89
**/.terraform
910

1011
.build-harness
11-
build-harness
12+
build-harness

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ install:
99
- make init
1010

1111
script:
12-
- make terraform:install
13-
- make terraform:get-plugins
14-
- make terraform:get-modules
15-
- make terraform:lint
16-
- make terraform:validate
12+
- make terraform/install
13+
- make terraform/get-plugins
14+
- make terraform/get-modules
15+
- make terraform/lint
16+
- make terraform/validate

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export README_DEPS ?= docs/targets.md docs/terraform.md
77

88
## Lint terraform code
99
lint:
10-
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
10+
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate

README.md

Lines changed: 94 additions & 36 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ related:
3838

3939
# Short description of this project
4040
description: |-
41-
Terraform module to easily provision an AWS CloudFront CDN with an S3 or custom origin.
41+
Terraform module to provision an AWS CloudFront CDN with an S3 origin.
4242
4343
# How to use this project
4444
usage: |-
4545
```hcl
4646
module "cdn" {
4747
source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=master"
48-
namespace = "${var.namespace}"
49-
stage = "${var.stage}"
50-
name = "${var.name}"
51-
aliases = "${var.hostname}"
52-
parent_zone_name = "${var.parent_zone_name}"
48+
namespace = "eg"
49+
stage = "prod"
50+
name = "app"
51+
aliases = ["assets.cloudposse.com"]
52+
parent_zone_name = "cloudposse.com"
5353
}
5454
```
5555

docs/terraform.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| acm_certificate_arn | Existing ACM Certificate ARN | string | `` | no |
77
| aliases | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront | list | `<list>` | no |
88
| allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | list | `<list>` | no |
9-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
9+
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
1010
| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no |
1111
| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list | `<list>` | no |
1212
| comment | Comment for the origin access identity | string | `Managed by Terraform` | no |
@@ -19,7 +19,7 @@
1919
| custom_error_response | List of one or more custom error response element maps | list | `<list>` | no |
2020
| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no |
2121
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no |
22-
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
22+
| 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. | string | `true` | no |
2424
| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no |
2525
| forward_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | no |
@@ -35,18 +35,18 @@
3535
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no |
3636
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no |
3737
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |
38-
| name | Name (e.g. `bastion` or `db`) | string | - | yes |
39-
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
38+
| name | Name (e.g. `bastion` or `app`) | string | - | yes |
39+
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
4040
| null | an empty string | string | `` | no |
4141
| origin_bucket | Name of S3 bucket | string | `` | no |
4242
| origin_force_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | string | `false` | no |
43-
| origin_path | When set, will cause 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 |
43+
| 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 |
4444
| parent_zone_id | ID of the hosted zone to contain this record (or specify `parent_zone_name`) | string | `` | no |
4545
| parent_zone_name | Name of the hosted zone to contain this record (or specify `parent_zone_id`) | string | `` | no |
4646
| price_class | Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | string | `PriceClass_100` | no |
4747
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
48-
| static_s3_bucket | aws-cli is a bucket owned by amazon that will perminantly exist It allows for the data source to be called during the destruction process without failing. It doesn't get used for anything else, this is a safe workaround for handling the fact that if a data source like the one `aws_s3_bucket.selected` gets an error, you can't continue the terraform process which also includes the 'destroy' command, where is doesn't even need this data source! Don't change this bucket name, its a variable so that we can provide this description. And this works around a problem that is an edge case. | string | `aws-cli` | no |
49-
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
48+
| static_s3_bucket | aws-cli is a bucket owned by amazon that will perminantly exist. It allows for the data source to be called during the destruction process without failing. It doesn't get used for anything else, this is a safe workaround for handling the fact that if a data source like the one `aws_s3_bucket.selected` gets an error, you can't continue the terraform process which also includes the 'destroy' command, where is doesn't even need this data source! Don't change this bucket name, it's a variable so that we can provide this description. And this works around a problem that is an edge case. | string | `aws-cli` | no |
49+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
5050
| use_regional_s3_endpoint | When set to 'true' the s3 origin_bucket will use the regional endpoint address instead of the global endpoint address | string | `false` | no |
5151
| viewer_protocol_policy | allow-all, redirect-to-https | string | `redirect-to-https` | no |
5252

example/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
3+
<head>
44
<meta charset="UTF-8">
55
<title>Your CDN is working</title>
6-
</head>
7-
<body>
8-
<H1>Your CDN is working!</H1>
9-
</body>
10-
</html>
6+
</head>
7+
<body>
8+
<h1>Your CDN is working!</h1>
9+
</body>
10+
</html>

example/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ resource "aws_route53_zone" "primary" {
55

66
module "cdn" {
77
source = "../"
8-
namespace = "cp"
9-
stage = "dev"
10-
name = "app-cdn"
8+
namespace = "eg"
9+
stage = "prod"
10+
name = "app"
1111
aliases = ["assets.cloudposse.com"]
1212
parent_zone_id = "${aws_route53_zone.primary.zone_id}"
1313
use_regional_s3_endpoint = "true"

example/provider.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
provider "aws" {
2-
region = "eu-west-2"
2+
region = "us-west-2"
33

4-
# Make it faster by skipping something
4+
# Make it faster by skipping some checks
55
skip_get_ec2_platforms = true
66
skip_metadata_api_check = true
77
skip_region_validation = true

main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "origin_label" {
2-
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.2"
2+
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.6"
33
namespace = "${var.namespace}"
44
stage = "${var.stage}"
55
name = "${var.name}"
@@ -83,7 +83,7 @@ module "logs" {
8383
}
8484

8585
module "distribution_label" {
86-
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.2"
86+
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.6"
8787
namespace = "${var.namespace}"
8888
stage = "${var.stage}"
8989
name = "${var.name}"
@@ -97,10 +97,8 @@ data "aws_s3_bucket" "selected" {
9797
}
9898

9999
locals {
100-
bucket = "${join("", compact(concat(list(var.origin_bucket), concat(list(""),aws_s3_bucket.origin.*.bucket))))}"
101-
region_endpoint = "${data.aws_s3_bucket.selected.region == "us-east-1" ? "s3" : "s3-${data.aws_s3_bucket.selected.region}" }"
102-
bucket_domain_format = "${var.use_regional_s3_endpoint == "true" ? "%s.${local.region_endpoint}.amazonaws.com" : var.bucket_domain_format }"
103-
bucket_domain_name = "${format(local.bucket_domain_format, local.bucket)}"
100+
bucket = "${join("", compact(concat(list(var.origin_bucket), concat(list(""), aws_s3_bucket.origin.*.bucket))))}"
101+
bucket_domain_name = "${var.use_regional_s3_endpoint == "true" ? format("%s.s3-%s.amazonaws.com" , local.bucket, data.aws_s3_bucket.selected.region): format(var.bucket_domain_format, local.bucket)}"
104102
}
105103

106104
resource "aws_cloudfront_distribution" "default" {
@@ -170,7 +168,8 @@ resource "aws_cloudfront_distribution" "default" {
170168
}
171169

172170
module "dns" {
173-
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.2.3"
171+
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.2.5"
172+
enabled = "${var.enabled}"
174173
aliases = "${var.aliases}"
175174
parent_zone_id = "${var.parent_zone_id}"
176175
parent_zone_name = "${var.parent_zone_name}"

0 commit comments

Comments
 (0)