-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Terraform AWS ACM Multiple Hosted Zone Example | ||
|
||
This example provides guides on how to use terraform-aws-acm-multiple-hosted-zone with external certificate validation. | ||
You may have a case where some of domains in the certificate is located in different AWS account. | ||
In this case, you can provision the ACM certificate using this module and do the certificate validation in the root project. | ||
|
||
This module will ignore registering domain to Route53 when there is no `zone` key in the domain object. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```terraform | ||
terraform init | ||
terraform plan -out=tfplan.out | ||
terraform apply tfplan.out | ||
``` | ||
|
||
Note that this example may create resources that cost money. | ||
Run `terraform destroy` to clean up the resources. | ||
|
||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws.example\_org | n/a | | ||
| aws.xendit | n/a | | ||
|
||
## Inputs | ||
|
||
No input. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| certificate\_arn | n/a | | ||
| certificate\_domains | n/a | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
locals { | ||
outside_domains = ["example.org", "*.example.org"] | ||
|
||
outside_record_validation = { | ||
for dvo in module.acm.certificate_domain_validation_options : dvo.domain_name => { | ||
name = dvo.resource_record_name | ||
record = dvo.resource_record_value | ||
type = dvo.resource_record_type | ||
} if contains(local.outside_domains, dvo.domain_name) | ||
} | ||
} | ||
|
||
module "acm" { | ||
source = "../../" | ||
|
||
providers = { | ||
aws.acm = aws | ||
aws.route53 = aws | ||
} | ||
|
||
domain_name = { | ||
zone = "example.com" | ||
domain = "example.com" | ||
} | ||
|
||
subject_alternative_names = [ | ||
{ | ||
zone = "example.com" | ||
domain = "*.example.com" | ||
}, | ||
{ | ||
domain = "example.org" | ||
}, | ||
{ | ||
domain = "*.example.org" | ||
} | ||
] | ||
|
||
validate_certificate = false | ||
|
||
tags = { | ||
Name = "ACM request external validation" | ||
} | ||
} | ||
|
||
data "aws_route53_zone" "example_org" { | ||
provider = aws.example_org | ||
|
||
name = "example.org" | ||
private_zone = false | ||
} | ||
|
||
resource "aws_route53_record" "example_org_validation" { | ||
provider = aws.example_org | ||
for_each = local.outside_record_validation | ||
|
||
zone_id = data.aws_route53_zone.example_org.zone_id | ||
name = each.value.name | ||
type = each.value.type | ||
records = [each.value.record] | ||
ttl = 60 | ||
allow_overwrite = true | ||
} | ||
|
||
resource "aws_acm_certificate_validation" "self" { | ||
certificate_arn = module.acm.certificate_arn | ||
validation_record_fqdns = [for dvo in module.acm.certificate_domain_validation_options : dvo.resource_record_name] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "certificate_arn" { | ||
value = module.acm.certificate_arn | ||
} | ||
|
||
output "certificate_domains" { | ||
value = module.acm.certificate_domains | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
||
provider "aws" { | ||
region = "us-west-2" | ||
alias = "example_org" | ||
profile = "example_org" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters