-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow validating the certificate with CloudFlare (#101)
- Loading branch information
1 parent
02ca0fa
commit a9a3c23
Showing
13 changed files
with
206 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
63 changes: 63 additions & 0 deletions
63
examples/complete-dns-validation-with-cloudflare/README.md
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,63 @@ | ||
# Complete ACM example with external CloudFlare DNS validation | ||
|
||
Configuration in this directory creates an ACM certificate (valid for the domain name and wildcard) while the DNS validation is done via an external DNS provider. | ||
|
||
For this example CloudFlare DNS is used but any DNS provider could be used instead. | ||
|
||
This is a complete example which fits most of scenarios. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.53 | | ||
| <a name="requirement_cloudflare"></a> [cloudflare](#requirement\_cloudflare) | >= 3.4.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_cloudflare"></a> [cloudflare](#provider\_cloudflare) | >= 3.4.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_acm"></a> [acm](#module\_acm) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [cloudflare_record.validation](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource | | ||
| [cloudflare_zone.this](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/zone) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_acm_certificate_arn"></a> [acm\_certificate\_arn](#output\_acm\_certificate\_arn) | The ARN of the certificate | | ||
| <a name="output_acm_certificate_domain_validation_options"></a> [acm\_certificate\_domain\_validation\_options](#output\_acm\_certificate\_domain\_validation\_options) | A list of attributes to feed into other resources to complete certificate validation. Can have more than one element, e.g. if SANs are defined. Only set if DNS-validation was used. | | ||
| <a name="output_acm_certificate_validation_emails"></a> [acm\_certificate\_validation\_emails](#output\_acm\_certificate\_validation\_emails) | A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used. | | ||
| <a name="output_distinct_domain_names"></a> [distinct\_domain\_names](#output\_distinct\_domain\_names) | List of distinct domains names used for the validation. | | ||
| <a name="output_validation_domains"></a> [validation\_domains](#output\_validation\_domains) | List of distinct domain validation options. This is useful if subject alternative names contain wildcards. | | ||
| <a name="output_validation_route53_record_fqdns"></a> [validation\_route53\_record\_fqdns](#output\_validation\_route53\_record\_fqdns) | List of FQDNs built using the zone domain and name. | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,44 @@ | ||
locals { | ||
domain = "terraform-aws-modules.modules.tf" | ||
|
||
# Removing trailing dot from domain - just to be sure :) | ||
domain_name = trimsuffix(local.domain, ".") | ||
} | ||
|
||
module "acm" { | ||
source = "../../" | ||
|
||
domain_name = local.domain_name | ||
zone_id = data.cloudflare_zone.this.id | ||
|
||
subject_alternative_names = [ | ||
"*.alerts.${local.domain_name}", | ||
"new.sub.${local.domain_name}", | ||
"*.${local.domain_name}", | ||
"alerts.${local.domain_name}", | ||
] | ||
|
||
create_route53_records = false | ||
validation_record_fqdns = cloudflare_record.validation.*.hostname | ||
|
||
tags = { | ||
Name = local.domain_name | ||
} | ||
} | ||
|
||
resource "cloudflare_record" "validation" { | ||
count = length(module.acm.distinct_domain_names) | ||
|
||
zone_id = data.cloudflare_zone.this.id | ||
name = element(module.acm.validation_domains, count.index)["resource_record_name"] | ||
type = element(module.acm.validation_domains, count.index)["resource_record_type"] | ||
value = replace(element(module.acm.validation_domains, count.index)["resource_record_value"], "/.$/", "") | ||
ttl = 60 | ||
proxied = false | ||
|
||
allow_overwrite = true | ||
} | ||
|
||
data "cloudflare_zone" "this" { | ||
name = local.domain_name | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/complete-dns-validation-with-cloudflare/outputs.tf
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,29 @@ | ||
output "acm_certificate_arn" { | ||
description = "The ARN of the certificate" | ||
value = module.acm.acm_certificate_arn | ||
} | ||
|
||
output "acm_certificate_domain_validation_options" { | ||
description = "A list of attributes to feed into other resources to complete certificate validation. Can have more than one element, e.g. if SANs are defined. Only set if DNS-validation was used." | ||
value = module.acm.acm_certificate_domain_validation_options | ||
} | ||
|
||
output "acm_certificate_validation_emails" { | ||
description = "A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used." | ||
value = module.acm.acm_certificate_validation_emails | ||
} | ||
|
||
output "validation_route53_record_fqdns" { | ||
description = "List of FQDNs built using the zone domain and name." | ||
value = module.acm.validation_route53_record_fqdns | ||
} | ||
|
||
output "distinct_domain_names" { | ||
description = "List of distinct domains names used for the validation." | ||
value = module.acm.distinct_domain_names | ||
} | ||
|
||
output "validation_domains" { | ||
description = "List of distinct domain validation options. This is useful if subject alternative names contain wildcards." | ||
value = module.acm.validation_domains | ||
} |
Empty file.
14 changes: 14 additions & 0 deletions
14
examples/complete-dns-validation-with-cloudflare/versions.tf
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,14 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 2.53" | ||
} | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = ">= 3.4.0" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
|
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
|