Skip to content

Commit

Permalink
Merge pull request #2 from davedash/wildcard-support
Browse files Browse the repository at this point in the history
Add support for a wildcard domain name via ACM.
  • Loading branch information
jonathanio authored Sep 28, 2017
2 parents 2c048c0 + e534976 commit 2f7a860
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ provider "aws" {
module "website" {
source = "modules/terraform-module-s3-cloudfront"
name = "my-first-website"
hostname = "example.com"
name = "my-first-website"
hostname = "example.com"
wildcard_ssl = "*.example.com"
aliases = [
"example.net",
"example.org"
Expand Down Expand Up @@ -59,6 +61,7 @@ directory of this repository.
## Authors

Jonathan Wright <[email protected]>
Dave Dash <[email protected]>

## License

Expand Down
2 changes: 1 addition & 1 deletion certificate.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ provider "aws" {

data "aws_acm_certificate" "frontend" {
provider = "aws.us-east-1"
domain = "${var.hostname}"
domain = "${coalesce(var.wildcard_ssl, var.hostname)}"
}
28 changes: 28 additions & 0 deletions examples/wildcard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Example Usage

The example in this directory will utilize a Wildcard SSL certificate.

## Important

This module will create an encrypted (i.e. HTTPS) endpoint in CloudFront using
[Amazon Certificate Manager](https://aws.amazon.com/certificate-manager/). ACM
cannot be automated at this time as it requires manual steps in the approval
of the domain name before it can be added into the account. Please therefore
setup the certificate for the domain name you require (and any aliases you may
include as well) by following the
[Getting Started](http://docs.aws.amazon.com/acm/latest/userguide/gs.html) guide
in the AWS Documentation.

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example may create resources which can cost money (logs stored
within S3, for example). Run `terraform destroy` when you don't need these
resources.
16 changes: 16 additions & 0 deletions examples/wildcard/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "aws" {
region = "eu-west-2"
}

module "website" {
source = "../../"

name = "my-first-website"
hostname = "mysite.example.com"
wildcard_ssl = "*.example.com"

tags {
Domain = "mysite.example.com"
Owner = "[email protected]"
}
}
15 changes: 15 additions & 0 deletions examples/wildcard/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "hostname" {
value = "${module.website.hostname}"
}

output "s3_bucket_name" {
value = "${module.website.s3_bucket_name}"
}

output "cloudfront_distribution_id" {
value = "${module.website.cloudfront_distribution_id}"
}

output "cloudfront_distribution_hostname" {
value = "${module.website.cloudfront_distribution_hostname}"
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ output "cloudfront_distribution_hostname" {
description = "The hostname of the CloudFront Distribution (use for DNS CNAME)."
value = "${aws_cloudfront_distribution.website.domain_name}"
}

output "cloudfront_zone_id" {
description = "The Zone ID of the CloudFront Distribution (use for DNS Alias)."
value = "${aws_cloudfront_distribution.website.hosted_zone_id}"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ variable "hostname" {
default = "example.com"
}

variable "wildcard_ssl" {
description = "Wildcard SSL certificate domain name. E.g. *.example.com"
default = ""
}

variable "aliases" {
description = "Additional aliases to host this website for."
default = []
Expand Down

0 comments on commit 2f7a860

Please sign in to comment.