Skip to content

Commit 5694dff

Browse files
authored
Merge pull request #2 from hyprnz/rdunn/0.12
Supports Terraform version 0.12
2 parents 37118f4 + 0274c28 commit 5694dff

File tree

17 files changed

+147
-123
lines changed

17 files changed

+147
-123
lines changed

README.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,50 @@ This repo supports version 0.11 and 0.12 of Terraform. The implementation patter
2727
## Contributions
2828
All contributions are accepted, details on how to contribute can be found in [contrib.md](contrib.md).
2929

30+
## Providers
31+
32+
| Name | Version |
33+
|------|---------|
34+
| aws | ~> 2.19 |
35+
3036
## Inputs
3137

3238
| Name | Description | Type | Default | Required |
33-
|------|-------------|:----:|:-----:|:-----:|
34-
| certificate\_arn | The arn of the certificate to be used for TLS connections. The certificate must be in the same account as the cloudfront resource. | string | n/a | yes |
35-
| cors\_allowed\_headers | Specifies which headers are allowed. | list | n/a | yes |
36-
| cors\_allowed\_origins | A list of allowed CORS origins. | list | n/a | yes |
37-
| namespace | A namespace that is appended to the `site_name` variable. This minimises S3 bucket naming collisions. | string | n/a | yes |
38-
| site\_name | The name of the static website or js bundle to be hosted by the S3 bucket. This will be the bucket name prefix. | string | n/a | yes |
39-
| url | The url alias to access the bucket. Must match the certificate name to provide a TLS connection | string | n/a | yes |
40-
| cloudfront\_allowed\_methods | Controls which HTTP methods CloudFront processes and forwards to your Amazon S3 bucket or your custom origin. | list | `<list>` | no |
41-
| cloudfront\_cached\_methods | Controls whether CloudFront caches the response to requests using the specified HTTP methods. | list | `<list>` | no |
42-
| cloudfront\_tags | Additional tags to be added to all cloudfront resources | map | `<map>` | no |
43-
| comment | A comment for the Cloudfront distribution resource | string | `""` | no |
44-
| cors\_allowed\_methods | Specifies which methods are allowed. Can be GET, PUT, POST, DELETE or HEAD. Defaults to `GET`, `PUT`, `POST`. | list | `<list>` | no |
45-
| cors\_expose\_headers | Specifies expose header in the response. Defaults to `ETag` | list | `<list>` | no |
46-
| cors\_max\_age\_seconds | Specifies time in seconds that browser can cache the response for a preflight request. Defaults to 1 hour. | string | `"3600"` | no |
47-
| create\_custom\_route53\_record | Determines if a route53 alias record should be created that matches the `url` variable. Default is false. | string | `"false"` | no |
48-
| default\_ttl | The default amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request in the absence of an Cache-Control max-age or Expires header. Defaults to 1 hour. | string | `"3600"` | no |
49-
| enable\_cdn\_compression | Select whether you want CloudFront to automatically compress content for web requests that include Accept-Encoding: gzip in the request header. CloudFront compresses files of certain types for both Amazon S3 and custom origins. Default is `true`. | string | `"true"` | no |
50-
| error\_document\_default | The default error html file. Defaults to `error.html`. | string | `"error.html"` | no |
51-
| index\_document\_default | The default html file. Defaults to `index.html`. | string | `"index.html"` | no |
52-
| max\_ttl | The maximum amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request to your origin to determine whether the object has been updated. Only effective in the presence of Cache-Control max-age, Cache-Control s-maxage, and Expires headers. Defaults to 7 days. | string | `"604800"` | no |
53-
| min\_ttl | The minimum amount of time that you want objects to stay in CloudFront caches before CloudFront queries your origin to see whether the object has been updated. Defaults to 0 seconds. | string | `"0"` | no |
54-
| module\_tags | Additional tags that are added to all resources in this module. | map | `<map>` | no |
55-
| price\_class | The price class for this distribution. One of `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | string | `"PriceClass_All"` | no |
56-
| s3\_tags | Additional tags to be added to all s3 resources | map | `<map>` | no |
57-
| site\_config\_values | A map of js bundle configuration values required for a specific environment. | map | `<map>` | no |
58-
| wait\_for\_deployment | If enabled, the resource will wait for the distribution status to change from `InProgress` to `Deployed`. Setting this to `false` will skip the process. Default: `true`. | string | `"true"` | no |
59-
| zone\_id | The zone id of the hosted zone to create the alias record in. Used only when `create_custom_route53_record` is set to `true`. | string | `""` | no |
39+
|------|-------------|------|---------|:-----:|
40+
| certificate\_arn | The arn of the certificate to be used for TLS connections. The certificate must be in the same account as the cloudfront resource. | `any` | n/a | yes |
41+
| cors\_allowed\_headers | Specifies which headers are allowed. | `list(string)` | n/a | yes |
42+
| cors\_allowed\_origins | A list of allowed CORS origins. | `list(string)` | n/a | yes |
43+
| namespace | A namespace that is appended to the `site_name` variable. This minimises S3 bucket naming collisions. | `any` | n/a | yes |
44+
| site\_name | The name of the static website or js bundle to be hosted by the S3 bucket. This will be the bucket name prefix. | `any` | n/a | yes |
45+
| url | The custom URL to access the site. Must match the certificate name to provide a valid TLS connection. | `any` | n/a | yes |
46+
| cloudfront\_allowed\_methods | Controls which HTTP methods CloudFront processes and forwards to your Amazon S3 bucket or your custom origin. | `list(string)` | <pre>[<br> "GET",<br> "HEAD",<br> "OPTIONS"<br>]<br></pre> | no |
47+
| cloudfront\_cached\_methods | Controls whether CloudFront caches the response to requests using the specified HTTP methods. | `list(string)` | <pre>[<br> "GET",<br> "HEAD"<br>]<br></pre> | no |
48+
| cloudfront\_tags | Additional tags to be added to all cloudfront resources. | `map(any)` | `{}` | no |
49+
| comment | A comment for the Cloudfront distribution resource | `string` | `""` | no |
50+
| cors\_allowed\_methods | Specifies which methods are allowed. Can be GET, PUT, POST, DELETE or HEAD. Defaults to `GET`, `PUT`, `POST`. | `list(string)` | <pre>[<br> "GET",<br> "PUT",<br> "POST"<br>]<br></pre> | no |
51+
| cors\_expose\_headers | Specifies expose header in the response. Defaults to `ETag`. | `list(string)` | <pre>[<br> "ETag"<br>]<br></pre> | no |
52+
| cors\_max\_age\_seconds | Specifies time in seconds that browser can cache the response for a preflight request. Defaults to 1 hour. | `number` | `3600` | no |
53+
| create\_custom\_route53\_record | Determines if a route53 alias record should be created that matches the `url` variable. Default is false. | `bool` | `false` | no |
54+
| default\_ttl | The default amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request in the absence of an Cache-Control max-age or Expires header. Defaults to 1 hour. | `number` | `3600` | no |
55+
| enable\_cdn\_compression | Select whether you want CloudFront to automatically compress content for web requests that include Accept-Encoding: gzip in the request header. CloudFront compresses files of certain types for both Amazon S3 and custom origins. Default is `true`. | `bool` | `true` | no |
56+
| error\_document\_default | The default error html file. Defaults to `error.html`. | `string` | `"error.html"` | no |
57+
| index\_document\_default | The default html file. Defaults to `index.html`. | `string` | `"index.html"` | no |
58+
| max\_ttl | The maximum amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request to your origin to determine whether the object has been updated. Only effective in the presence of Cache-Control max-age, Cache-Control s-maxage, and Expires headers. Defaults to 7 days. | `number` | `604800` | no |
59+
| min\_ttl | The minimum amount of time that you want objects to stay in CloudFront caches before CloudFront queries your origin to see whether the object has been updated. Defaults to 0 seconds. | `number` | `0` | no |
60+
| module\_tags | Additional tags that are added to all resources in this module. | `map(any)` | `{}` | no |
61+
| price\_class | The price class for this distribution. One of `PriceClass_All`, `PriceClass_200`, `PriceClass_100`. | `string` | `"PriceClass_All"` | no |
62+
| s3\_tags | Additional tags to be added to all s3 resources. | `map(any)` | `{}` | no |
63+
| site\_config\_values | A map of js bundle configuration values required for a specific environment. | `map(any)` | `{}` | no |
64+
| wait\_for\_deployment | If enabled, the resource will wait for the distribution status to change from `InProgress` to `Deployed`. Setting this to `false` will skip the process. Default: `true`. | `bool` | `true` | no |
65+
| zone\_id | The zone id of the hosted zone to create the alias record in. Used only when `create_custom_route53_record` is set to `true`. | `string` | `""` | no |
6066

6167
## Outputs
6268

6369
| Name | Description |
6470
|------|-------------|
6571
| cloudfront\_hosted\_zone | The hosted zone id of the Cloudfront Distribution |
6672
| cloudfront\_url | The URL for the Cloudfront Distribution - used to set the alias for the custom domain. |
67-
| s3\_bucket\_hosted\_id | The hosted_id s3 web site bucket. |
73+
| s3\_bucket\_hosted\_id | The hosted\_id s3 web site bucket. |
6874
| s3\_bucket\_website\_domain | The domain of the s3 web site bucket. |
6975
| s3\_bucket\_website\_endpoint | The endpoint of the s3 web site bucket. |
7076

artifactory/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ This Terraform module is provided as an additional component for those wanting t
44

55
This has been provided as an additional module to meet the architectural needs of a global module i.e. there will only ever be one module implementation of an artifactory, as opposed to n number of s3-static-website module implementations, where n is the number of environments. This module design also caters for cross AWS Account patterns.
66

7+
## Providers
8+
9+
| Name | Version |
10+
|------|---------|
11+
| aws | ~> 2.19 |
12+
713
## Inputs
814

915
| Name | Description | Type | Default | Required |
10-
|------|-------------|:----:|:-----:|:-----:|
11-
| namespace | A namespace that is appended to the `site_name-artifactory.` variable. This minimises S3 bucket naming collisions. | string | n/a | yes |
12-
| site\_name | The name of the static website or js bundle to be hosted by the S3 bucket. This will be the bucket name prefix. | string | n/a | yes |
13-
| force\_destroy | Controls if all objects in a bucket should be deleted when destroying the bucket resource. If set to `false`, the bucket resource cannot be destroyed until all objects are deleted. Defaults to `true`. | string | `"true"` | no |
14-
| tags | A map of additional tags to add to the artifactory resource. A name tag with the value `<site_name>-artifactory.<namespace>` is added by default. | map | `<map>` | no |
16+
|------|-------------|------|---------|:-----:|
17+
| namespace | A namespace that is appended to the `site_name-artifactory.` variable. This minimises S3 bucket naming collisions. | `any` | n/a | yes |
18+
| site\_name | The name of the static website or js bundle to be hosted by the S3 bucket. This will be the bucket name prefix. | `any` | n/a | yes |
19+
| force\_destroy | Controls if all objects in a bucket should be deleted when destroying the bucket resource. If set to `false`, the bucket resource cannot be destroyed until all objects are deleted. Defaults to `true`. | `bool` | `true` | no |
20+
| tags | A map of additional tags to add to the artifactory resource. A name tag with the value `<site_name>-artifactory.<namespace>` is added by default. | `map(any)` | `{}` | no |
1521

1622
## Outputs
1723

artifactory/example/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ module "static_website_artifactory_example" {
22
source = "../"
33

44
providers = {
5-
aws = "aws"
5+
aws = aws
66
}
77

88
site_name = "bundle"
99
namespace = "dev.example.com"
1010
}
1111

1212
provider "aws" {
13-
region = "${var.aws_region}"
13+
region = var.aws_region
1414
}
1515

1616
variable "aws_region" {
1717
default = "ap-southeast-2"
1818
}
1919

2020
output "bucket_name" {
21-
value = "${module.static_website_artifactory_example.bucket_name}"
21+
value = module.static_website_artifactory_example.bucket_name
2222
}

artifactory/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
locals {
2-
bucket_name = "${format("%s-%s.%s", var.site_name, "artifactory", var.namespace)}"
2+
bucket_name = format("%s-%s.%s", var.site_name, "artifactory", var.namespace)
33
}
44

55
resource "aws_s3_bucket" "artifactory" {
6-
bucket = "${local.bucket_name}"
6+
bucket = local.bucket_name
77
acl = "private"
88

9-
force_destroy = "${var.force_destroy}"
9+
force_destroy = var.force_destroy
1010

11-
tags = "${merge(map("Name", local.bucket_name), var.tags)}"
11+
tags = merge(map("Name", local.bucket_name), map("Site Name", var.site_name), var.tags)
1212
}

artifactory/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "bucket_name" {
22
description = "The name of the artifactory bucket"
3-
value = "${aws_s3_bucket.artifactory.id}"
3+
value = aws_s3_bucket.artifactory.id
44
}

artifactory/providers.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

artifactory/vars.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ variable "namespace" {
88

99
variable "force_destroy" {
1010
description = "Controls if all objects in a bucket should be deleted when destroying the bucket resource. If set to `false`, the bucket resource cannot be destroyed until all objects are deleted. Defaults to `true`."
11+
type = bool
1112
default = true
1213
}
1314

1415
variable "tags" {
1516
description = "A map of additional tags to add to the artifactory resource. A name tag with the value `<site_name>-artifactory.<namespace>` is added by default."
17+
type = map(any)
1618
default = {}
1719
}

artifactory/versions.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
terraform {
2-
required_version = "~> 0.11"
2+
required_version = ">= 0.12"
3+
4+
required_providers {
5+
aws = "~> 2.19"
6+
}
7+
38
}

cloudfront.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
resource "aws_cloudfront_distribution" "cdn" {
22
origin {
3-
origin_id = "${aws_s3_bucket.static_website.id}"
4-
domain_name = "${aws_s3_bucket.static_website.bucket_domain_name}"
3+
origin_id = aws_s3_bucket.static_website.id
4+
domain_name = aws_s3_bucket.static_website.bucket_domain_name
55
}
66

7-
aliases = ["${var.url}"]
8-
wait_for_deployment = "${var.wait_for_deployment}"
7+
aliases = [var.url]
8+
wait_for_deployment = var.wait_for_deployment
99

1010
enabled = true
11-
comment = "${var.comment}"
12-
default_root_object = "${var.index_document_default}"
11+
comment = var.comment
12+
default_root_object = var.index_document_default
1313

1414
default_cache_behavior {
15-
allowed_methods = "${var.cloudfront_allowed_methods}"
16-
cached_methods = "${var.cloudfront_cached_methods}"
17-
target_origin_id = "${aws_s3_bucket.static_website.id}"
18-
compress = "${var.enable_cdn_compression}"
15+
allowed_methods = var.cloudfront_allowed_methods
16+
cached_methods = var.cloudfront_cached_methods
17+
target_origin_id = aws_s3_bucket.static_website.id
18+
compress = var.enable_cdn_compression
1919

2020
forwarded_values {
2121
query_string = false
@@ -26,12 +26,12 @@ resource "aws_cloudfront_distribution" "cdn" {
2626
}
2727

2828
viewer_protocol_policy = "redirect-to-https"
29-
min_ttl = "${var.min_ttl}"
30-
default_ttl = "${var.default_ttl}"
31-
max_ttl = "${var.max_ttl}"
29+
min_ttl = var.min_ttl
30+
default_ttl = var.default_ttl
31+
max_ttl = var.max_ttl
3232
}
3333

34-
price_class = "${var.price_class}"
34+
price_class = var.price_class
3535

3636
restrictions {
3737
geo_restriction {
@@ -42,15 +42,15 @@ resource "aws_cloudfront_distribution" "cdn" {
4242

4343
viewer_certificate {
4444
# Certificates for cloudfront _must_ be created in us-east-1
45-
acm_certificate_arn = "${var.certificate_arn}"
45+
acm_certificate_arn = var.certificate_arn
4646
ssl_support_method = "sni-only"
4747
minimum_protocol_version = "TLSv1"
4848
}
4949

5050
logging_config {
51-
bucket = "${aws_s3_bucket.static_website_log_bucket.bucket_domain_name}"
51+
bucket = aws_s3_bucket.static_website_log_bucket.bucket_domain_name
5252
prefix = "cloudfront/"
5353
}
5454

55-
tags = "${merge(map("Name", format("%s-cdn", var.site_name)), map("Site Name", var.site_name), var.cloudfront_tags, var.module_tags)}"
55+
tags = merge(map("Name", format("%s-cdn", var.site_name)), map("Site Name", var.site_name), var.cloudfront_tags, var.module_tags)
5656
}

examples/default/main.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ module "static_website_example" {
22
source = "../../"
33

44
providers = {
5-
aws = "aws"
5+
aws = aws
66
}
77

88
site_name = "bundle"
99
namespace = "dev.example.com"
1010

11-
url = "${var.url}"
12-
certificate_arn = "${var.certificate_arn}"
11+
url = var.url
12+
certificate_arn = var.certificate_arn
1313

1414
site_config_values = {
1515
"auth_url" = "www.google.com"
@@ -19,17 +19,17 @@ module "static_website_example" {
1919
cors_allowed_origins = ["*"]
2020
cors_allowed_headers = [""]
2121

22-
module_tags = "${map("Environment", "dev")}"
23-
s3_tags = "${map("s3", "true")}"
24-
cloudfront_tags = "${map("cloudfront", "true")}"
22+
module_tags = map("Environment", "dev")
23+
s3_tags = map("s3", "true")
24+
cloudfront_tags = map("cloudfront", "true")
2525

2626
wait_for_deployment = false
2727

2828
comment = "Example static website cloudfront distribution"
2929
}
3030

3131
provider "aws" {
32-
region = "${var.aws_region}"
32+
region = var.aws_region
3333
}
3434

3535
variable "aws_region" {
@@ -41,21 +41,21 @@ variable "url" {}
4141
variable "certificate_arn" {}
4242

4343
output "website_domain" {
44-
value = "${module.static_website_example.s3_bucket_website_domain}"
44+
value = module.static_website_example.s3_bucket_website_domain
4545
}
4646

4747
output "website_endpoint" {
48-
value = "${module.static_website_example.s3_bucket_website_endpoint}"
48+
value = module.static_website_example.s3_bucket_website_endpoint
4949
}
5050

5151
output "website_hosted_id" {
52-
value = "${module.static_website_example.s3_bucket_hosted_id}"
52+
value = module.static_website_example.s3_bucket_hosted_id
5353
}
5454

5555
output "cloudfront_url" {
56-
value = "${module.static_website_example.cloudfront_url}"
56+
value = module.static_website_example.cloudfront_url
5757
}
5858

5959
output "cloudfront_hosted_zone" {
60-
value = "${module.static_website_example.cloudfront_hosted_zone}"
60+
value = module.static_website_example.cloudfront_hosted_zone
6161
}

0 commit comments

Comments
 (0)