Skip to content

Commit

Permalink
fixing regional support (#29)
Browse files Browse the repository at this point in the history
* fixing regional support

* Fix descriptions. Bump module versions. Update README
  • Loading branch information
Jamie-BitFlight authored and aknysh committed Nov 2, 2018
1 parent b0960c0 commit f6420b3
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
**/*.tfstate
**/*.tfstate.backup
**/*.terraform.tfstate*

# Module directory
.idea
*.iml
**/.terraform

.build-harness
build-harness
build-harness
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ install:
- make init

script:
- make terraform:install
- make terraform:get-plugins
- make terraform:get-modules
- make terraform:lint
- make terraform:validate
- make terraform/install
- make terraform/get-plugins
- make terraform/get-modules
- make terraform/lint
- make terraform/validate
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export README_DEPS ?= docs/targets.md docs/terraform.md

## Lint terraform code
lint:
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
130 changes: 94 additions & 36 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ related:

# Short description of this project
description: |-
Terraform module to easily provision an AWS CloudFront CDN with an S3 or custom origin.
Terraform module to provision an AWS CloudFront CDN with an S3 origin.
# How to use this project
usage: |-
```hcl
module "cdn" {
source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=master"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
aliases = "${var.hostname}"
parent_zone_name = "${var.parent_zone_name}"
namespace = "eg"
stage = "prod"
name = "app"
aliases = ["assets.cloudposse.com"]
parent_zone_name = "cloudposse.com"
}
```
Expand Down
14 changes: 7 additions & 7 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| acm_certificate_arn | Existing ACM Certificate ARN | string | `` | no |
| aliases | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront | list | `<list>` | no |
| allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | list | `<list>` | no |
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no |
| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list | `<list>` | no |
| comment | Comment for the origin access identity | string | `Managed by Terraform` | no |
Expand All @@ -19,7 +19,7 @@
| custom_error_response | List of one or more custom error response element maps | list | `<list>` | no |
| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no |
| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
| 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 |
| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no |
| forward_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | no |
Expand All @@ -35,18 +35,18 @@
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no |
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no |
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |
| name | Name (e.g. `bastion` or `db`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| name | Name (e.g. `bastion` or `app`) | string | - | yes |
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
| null | an empty string | string | `` | no |
| origin_bucket | Name of S3 bucket | string | `` | no |
| 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 |
| 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 |
| 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 |
| parent_zone_id | ID of the hosted zone to contain this record (or specify `parent_zone_name`) | string | `` | no |
| parent_zone_name | Name of the hosted zone to contain this record (or specify `parent_zone_id`) | string | `` | no |
| price_class | Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | string | `PriceClass_100` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| 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 |
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
| 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 |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
| 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 |
| viewer_protocol_policy | allow-all, redirect-to-https | string | `redirect-to-https` | no |

Expand Down
12 changes: 6 additions & 6 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<head>
<meta charset="UTF-8">
<title>Your CDN is working</title>
</head>
<body>
<H1>Your CDN is working!</H1>
</body>
</html>
</head>
<body>
<h1>Your CDN is working!</h1>
</body>
</html>
6 changes: 3 additions & 3 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ resource "aws_route53_zone" "primary" {

module "cdn" {
source = "../"
namespace = "cp"
stage = "dev"
name = "app-cdn"
namespace = "eg"
stage = "prod"
name = "app"
aliases = ["assets.cloudposse.com"]
parent_zone_id = "${aws_route53_zone.primary.zone_id}"
use_regional_s3_endpoint = "true"
Expand Down
4 changes: 2 additions & 2 deletions example/provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
provider "aws" {
region = "eu-west-2"
region = "us-west-2"

# Make it faster by skipping something
# Make it faster by skipping some checks
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
Expand Down
13 changes: 6 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "origin_label" {
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.2"
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.6"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
Expand Down Expand Up @@ -83,7 +83,7 @@ module "logs" {
}

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

locals {
bucket = "${join("", compact(concat(list(var.origin_bucket), concat(list(""),aws_s3_bucket.origin.*.bucket))))}"
region_endpoint = "${data.aws_s3_bucket.selected.region == "us-east-1" ? "s3" : "s3-${data.aws_s3_bucket.selected.region}" }"
bucket_domain_format = "${var.use_regional_s3_endpoint == "true" ? "%s.${local.region_endpoint}.amazonaws.com" : var.bucket_domain_format }"
bucket_domain_name = "${format(local.bucket_domain_format, local.bucket)}"
bucket = "${join("", compact(concat(list(var.origin_bucket), concat(list(""), aws_s3_bucket.origin.*.bucket))))}"
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)}"
}

resource "aws_cloudfront_distribution" "default" {
Expand Down Expand Up @@ -170,7 +168,8 @@ resource "aws_cloudfront_distribution" "default" {
}

module "dns" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.2.3"
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.2.5"
enabled = "${var.enabled}"
aliases = "${var.aliases}"
parent_zone_id = "${var.parent_zone_id}"
parent_zone_name = "${var.parent_zone_name}"
Expand Down
18 changes: 9 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "namespace" {
description = "Namespace (e.g. `cp` or `cloudposse`)"
description = "Namespace (e.g. `eg` or `cp`)"
type = "string"
}

Expand All @@ -9,26 +9,26 @@ variable "stage" {
}

variable "name" {
description = "Name (e.g. `bastion` or `db`)"
description = "Name (e.g. `bastion` or `app`)"
type = "string"
}

variable "delimiter" {
type = "string"
default = "-"
description = "Delimiter to be used between `name`, `namespace`, `stage`, etc."
description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`"
}

variable "attributes" {
type = "list"
default = []
description = "Additional attributes (e.g. `policy` or `role`)"
description = "Additional attributes (e.g. `1`)"
}

variable "tags" {
type = "map"
default = {}
description = "Additional tags (e.g. map('BusinessUnit`,`XYZ`)"
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)"
}

variable "enabled" {
Expand Down Expand Up @@ -65,7 +65,7 @@ variable "origin_bucket" {

variable "origin_path" {
# http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesOriginPath
description = "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."
description = "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."
default = ""
}

Expand Down Expand Up @@ -237,12 +237,12 @@ variable "null" {

variable "static_s3_bucket" {
description = <<DOC
aws-cli is a bucket owned by amazon that will perminantly exist
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
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.
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.
DOC

Expand Down

0 comments on commit f6420b3

Please sign in to comment.