-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add aws_acm_certificate resource with automated verification with Route53 #2418
Comments
On second thought, maybe the new |
The ACM certificate resource would only be able to create the DNS record itself if you were using Route53. It would massively simplify the Terraform control flow though and there's precedent for it in a couple of other resources where IAM service roles are created automatically if they aren't already there. Of course that would only be possible if you are using R53 for your DNS but I'd guess that probably covers a large chunk of people who would like to use this resource. There was some talk on the old issue about maybe having a |
It's also possible to use the cloudflare plugin if using cloudflare instead of route53, but that's crossing plugin boundaries. The other thing though is that according to the amazon documentation, the verification domain name doesn't change for a domain name; which means once the verification txt is issued, as long as it remains live it doesn't need to be changed/updated, so the approval step could even be skipped in some cases. |
@pdecat I like your original solution. I think we could solve the "waiting for certificate issued" problem by moving it to the data source. The resource would make the resource "aws_route53_zone" "example" {
name = "example.com"
}
# NOTE: this resource does not exist yet
resource "aws_acm_certificate" "acm_tf" {
domain = "tf.example.com"
subject_alternative_names = [
"tf1.example.com",
"tf2.example.com",
]
}
resource "aws_route53_record" "acm_tf_verification" {
zone_id = "${aws_route53_zone.example.zone_id}"
name = "${aws_acm_certificate.acm_tf.dns_cname_name}.example.com"
type = "CNAME"
ttl = "30"
records = [
"${aws_acm_certificate.acm_tf.dns_cname_value}",
]
}
data "aws_acm_certificate" "acm_tf" {
statuses = ["ISSUED"]
# NOTE: this does not exist yet but would make sense to have an explicit dependency
# and reference the right certificate in case there's more than one for the same domain
certificate_arn = "${aws_acm_certificate.acm_tf.arn}"
# NOTE: this does not exist yet. Would cause the data source to poll until a timeout is reached or the certificate is in the correct status
wait_for_certificate = true
}
# USAGE: use the arn from the datasource to make sure you are using an issued certificate
resource "aws_lb_listener" "front_end" {
certificate_arn = "${data.aws_acm_certificate.acm_tf}"
} To me, this feels similar to what @vancluever proposed for the ACME provider. This should work in most cases where certificate is used via the data source. I'm a bit unsure what happens if the certificate is not used in the same terraform project, i.e. there's no immediate dependency that would block the apply. |
Hi everyone! Thanks for the great discussion here. Following the model proposed for ACME seems like a good idea, to separate the three steps:
Using polling and a timeout for the completion, rather than having a resource that explicitly declares the challenge as completed, is not ideal but indeed seems like the best thing that can be done with the design of this API, and should be okay as long as ACM is able to respond to the completion fast enough that Terraform won't appear to hang for a long time. Ideally we'd want to also be able to detect a failure quickly and return an explicit error message, rather than simply timing out, but perhaps that isn't possible. The Terraform Team at HashiCorp doesn't have any immediate plan to work on this due to our focus being elsewhere, but we'd be happy to review a PR if someone in the community has the time and motivation to work on it. Alternatively, feel free to upvote the original issue (not this comment!) if you'd find this feature useful since we use issue votes as one of the inputs into our prioritization process. |
Gave implementing this a shot. Here's the current state: #2801. |
any ideas which version this will be available in? this is my most wanted feature from terraform (my most wanted from aws is not to require a challenge if you're using route53, and the domain exists) |
@xenoterracide PR #2813 implements this feature, and is waiting for review. Unless there are fundamental problems I'll probably be able to address feedback quickly to get this ready to merge. |
As a heads up for anyone still watching here, I'm about to submit the first round of maintainer feedback on #2813. Feel free to follow along there! 😄 |
Hi everyone! Today is your lucky day as we have just merged in #2813 into master, which provides the two aforementioned new resources: HUGE shoutout to @flosell, @pdecat, @apparentlymart, and the others involved with making this a reality. 😂 |
This has been released in terraform-provider-aws version 1.9.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
have problems creating this with a cloudfront distribution at the same time, worked on a later run, my guess is need to wait for a read back
here's the module code
|
@xenoterracide you might be able to fix your situation by referring to the I'd try replacing this: acm_certificate_arn = "${aws_acm_certificate.Cert.arn}" With the below, which will ensure the certificate is fully acm_certificate_arn = "${aws_acm_certificate_validation.CertValidation.certificate_arn}" |
What @bflad mentioned above is exactly what works for me. I did it using the |
sorry for using this for what's essentially questions
is there any way to dry this up? I tried to use |
@xenoterracide this works for me:
|
thanks, made some tweaks, but this looks like it works
due to the fact that I think this should work independently of actual count on the cert I do think this should be shown in the docs, instead of simply how to do it with 1 domain. I was changing the domain names and encountered this (after previous discussion on cloudfront)
I worked around it by hand going in and changing the cert to use default cert, which allowed destruction/changes to proceed, but seems cludgy |
It works in validating ACM but terraform thinks that something is wrong. I am using the following (my domain swapped for example.com):
Problem is with having a wildcard in there. In my past experience I had issues with just having sans_domains with *.example.com. Maybe I am doing my certs wrong. |
So wildcard cert is a problem
|
I've tried the same and it does not work:
It does work if certificate is created beforehand, but if you'd like to do it in one run it does not. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Since 2017/11/22, AWS ACM now supports request verification via DNS records in addition to email verification:
https://aws.amazon.com/fr/about-aws/whats-new/2017/11/aws-certificate-manager-easier-certificate-validation-using-dns/
https://aws.amazon.com/certificate-manager/faqs/#dns_validation
http://docs.aws.amazon.com/acm/latest/userguide/gs-acm-validate-dns.html
This could be used with supported DNS resources from AWS provider (and probably others) to automatically request and verify ACM certificates.
Terraform Version
Terraform v0.11.0
Affected Resource(s)
Terraform Configuration Files
An example of what an automated ACM request and validation with Route53 would look like configuration wise:
The text was updated successfully, but these errors were encountered: