Skip to content

Commit 90c7b93

Browse files
Nuruosterman
authored andcommitted
[0.11] Work around terraform issue 18359 (#21)
* Work around terraform issue 18359 * Revert bad merge * Revert bad merge, fix proces/process * Revert bad merge * Fix proces/process * Update README
1 parent f6f10a5 commit 90c7b93

File tree

5 files changed

+13
-34
lines changed

5 files changed

+13
-34
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
4444

4545
## Usage
4646

47+
48+
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
49+
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-acm-request-certificate/releases).
50+
51+
4752
This example will request an SSL certificate for `example.com` domain
4853

4954
```hcl
@@ -92,7 +97,6 @@ Available targets:
9297
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
9398
| ttl | The TTL of the record to add to the DNS zone to complete certificate validation | string | `300` | no |
9499
| validation_method | Which method to use for validation, DNS or EMAIL | string | `DNS` | no |
95-
| zone_name | The name of the desired Route53 Hosted Zone | string | `` | no |
96100

97101
## Outputs
98102

docs/terraform.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
99
| ttl | The TTL of the record to add to the DNS zone to complete certificate validation | string | `300` | no |
1010
| validation_method | Which method to use for validation, DNS or EMAIL | string | `DNS` | no |
11-
| zone_name | The name of the desired Route53 Hosted Zone | string | `` | no |
1211

1312
## Outputs
1413

main.tf

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,24 @@ resource "aws_acm_certificate" "default" {
33
validation_method = "${var.validation_method}"
44
subject_alternative_names = ["${var.subject_alternative_names}"]
55
tags = "${var.tags}"
6-
7-
lifecycle {
8-
create_before_destroy = true
9-
}
106
}
117

128
data "aws_route53_zone" "default" {
139
count = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? 1 : 0}"
14-
name = "${local.zone_name}."
10+
name = "${var.domain_name}."
1511
private_zone = false
1612
}
1713

1814
locals {
19-
domain_validation_options = "${aws_acm_certificate.default.domain_validation_options[0]}"
20-
zone_name = "${var.zone_name == "" ? var.domain_name : var.zone_name}"
21-
}
22-
23-
resource "null_resource" "default" {
24-
count = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? length(aws_acm_certificate.default.domain_validation_options) : 0}"
25-
26-
triggers = "${aws_acm_certificate.default.domain_validation_options[count.index]}"
27-
}
28-
29-
resource "aws_acm_certificate_validation" "default" {
30-
certificate_arn = "${aws_acm_certificate.default.arn}"
31-
32-
validation_record_fqdns = [
33-
"${distinct(compact(concat(aws_route53_record.default.fqdn, var.subject_alternative_names)))}",
34-
]
15+
# Workaround for https://github.com/hashicorp/terraform/issues/18359
16+
domain_validation_options = "${flatten(aws_acm_certificate.default.*.domain_validation_options)}"
3517
}
3618

3719
resource "aws_route53_record" "default" {
38-
count = "${length(null_resource.default.triggers)}"
20+
count = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? 1 : 0}"
3921
zone_id = "${data.aws_route53_zone.default.zone_id}"
40-
name = "${lookup("null_resource.default.${count.index}","resource_record_name")}"
41-
type = "${lookup("null_resource.default.${count.index}", "resource_record_type")}"
22+
name = "${lookup(local.domain_validation_options[count.index], "resource_record_name")}"
23+
type = "${lookup(local.domain_validation_options[count.index], "resource_record_type")}"
4224
ttl = "${var.ttl}"
43-
records = ["${lookup("null_resource.default.${count.index}","resource_record_value")}"]
25+
records = ["${lookup(local.domain_validation_options[count.index], "resource_record_value")}"]
4426
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ output "id" {
44
}
55

66
output "arn" {
7-
value = "${aws_acm_certificate_validation.default.certificate_arn}"
7+
value = "${aws_acm_certificate.default.arn}"
88
description = "The ARN of the certificate"
99
}
1010

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,3 @@ variable "subject_alternative_names" {
3232
default = []
3333
description = "A list of domains that should be SANs in the issued certificate"
3434
}
35-
36-
variable "zone_name" {
37-
type = "string"
38-
default = ""
39-
description = "The name of the desired Route53 Hosted Zone"
40-
}

0 commit comments

Comments
 (0)