Giter Site home page Giter Site logo

cloudposse / terraform-aws-acm-request-certificate Goto Github PK

View Code? Open in Web Editor NEW
103.0 19.0 68.0 336 KB

Terraform module to request an ACM certificate for a domain name and create a CNAME record in the DNS zone to complete certificate validation

Home Page: https://cloudposse.com/accelerate

License: Apache License 2.0

Makefile 10.65% HCL 66.74% Go 22.61%
terraform terraform-modules aws acm request-certificate tls ssl ssl-certificates hcl2

terraform-aws-acm-request-certificate's Introduction

terraform-aws-acm-request-certificate

Latest ReleaseLast UpdatedSlack Community

Terraform module to request an ACM certificate for a domain and add a CNAME record to the DNS zone to complete certificate validation

Tip

πŸ‘½ Use Atmos with Terraform

Cloud Posse uses atmos to easily orchestrate multiple environments using Terraform.
Works with Github Actions, Atlantis, or Spacelift.

Watch demo of using Atmos with Terraform
Example of running atmos to manage infrastructure from our Quick Start tutorial.

Usage

This example will request an SSL certificate for example.com domain

module "acm_request_certificate" {
  source = "cloudposse/acm-request-certificate/aws"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"
  domain_name                       = "example.com"
  process_domain_validation_options = true
  ttl                               = "300"
}

This example will request an SSL certificate for example.com domain and all its subdomains *.example.com

module "acm_request_certificate" {
  source = "cloudposse/acm-request-certificate/aws"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"
  domain_name                       = "example.com"
  process_domain_validation_options = true
  ttl                               = "300"
  subject_alternative_names         = ["*.example.com"]
}

Important

In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version you're using. This practice ensures the stability of your infrastructure. Additionally, we recommend implementing a systematic approach for updating versions to avoid unexpected changes.

Makefile Targets

Available targets:

  help                                Help screen
  help/all                            Display help for all targets
  help/short                          This help short screen
  lint                                Lint terraform code

Requirements

Name Version
terraform >= 0.14
aws >= 4.40

Providers

Name Version
aws >= 4.40

Modules

Name Source Version
this cloudposse/label/null 0.25.0

Resources

Name Type
aws_acm_certificate.default resource
aws_acm_certificate_validation.default resource
aws_route53_record.default resource
aws_route53_zone.default data source

Inputs

Name Description Type Default Required
additional_tag_map Additional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string) {} no
attributes ID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string) [] no
certificate_authority_arn ARN of an ACM PCA string null no
certificate_transparency_logging_preference Specifies whether certificate details should be added to a certificate transparency log bool true no
context Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
delimiter Delimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
string null no
descriptor_formats Describe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br> format = string<br> labels = list(string)<br>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any {} no
domain_name A domain name for which the certificate should be issued string n/a yes
enabled Set to false to prevent the module from creating any resources bool null no
environment ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' string null no
id_length_limit Limit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
number null no
key_algorithm Specifies the algorithm of the public and private key pair that your Amazon issued certificate uses to encrypt data string null no
label_key_case Controls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
string null no
label_order The order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string) null no
label_value_case Controls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
string null no
labels_as_tags Set of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
name ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
string null no
namespace ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique string null no
process_domain_validation_options Flag to enable/disable processing of the record to add to the DNS zone to complete certificate validation bool true no
regex_replace_chars Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
string null no
stage ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' string null no
subject_alternative_names A list of domains that should be SANs in the issued certificate list(string) [] no
tags Additional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string) {} no
tenant ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for string null no
ttl The TTL of the record to add to the DNS zone to complete certificate validation string "300" no
validation_method Method to use for validation, DNS or EMAIL string "DNS" no
wait_for_certificate_issued Whether to wait for the certificate to be issued by ACM (the certificate status changed from Pending Validation to Issued) bool false no
zone_id The zone id of the Route53 Hosted Zone which can be used instead of var.zone_name. string null no
zone_name The name of the desired Route53 Hosted Zone string "" no

Outputs

Name Description
arn The ARN of the certificate
domain_validation_options CNAME records that are added to the DNS zone to complete certificate validation
id The ID of the certificate
validation_certificate_arn Certificate ARN from the aws_acm_certificate_validation resource
validation_id The ID of the certificate validation

Related Projects

Check out these related projects.

Tip

Use Terraform Reference Architectures for AWS

Use Cloud Posse's ready-to-go terraform architecture blueprints for AWS to get up and running quickly.

βœ… We build it with you.
βœ… You own everything.
βœ… Your team wins.

Request Quote

πŸ“š Learn More

Cloud Posse is the leading DevOps Accelerator for funded startups and enterprises.

Your team can operate like a pro today.

Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.

Day-0: Your Foundation for Success

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Deployment Strategy. Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
  • Site Reliability Engineering. Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
  • Security Baseline. Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
  • GitOps. Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.

Request Quote

Day-2: Your Operational Mastery

  • Training. Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
  • Support. Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
  • Troubleshooting. Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
  • Code Reviews. Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration.
  • Bug Fixes. Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
  • Migration Assistance. Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
  • Customer Workshops. Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.

Request Quote

✨ Contributing

This project is under active development, and we encourage contributions from our community.

Many thanks to our outstanding contributors:

For πŸ› bug reports & feature requests, please use the issue tracker.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Review our Code of Conduct and Contributor Guidelines.
  2. Fork the repo on GitHub
  3. Clone the project to your own machine
  4. Commit changes to your own branch
  5. Push your work back up to your fork
  6. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

🌎 Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

πŸ“° Newsletter

Sign up for our newsletter and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. Dropped straight into your Inbox every week β€” and usually a 5-minute read.

πŸ“† Office Hours

Join us every Wednesday via Zoom for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a live Q&A that you can’t find anywhere else. It's FREE for everyone!

License

License

Preamble to the Apache License, Version 2.0

Complete license is available in the LICENSE file.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.


Copyright Β© 2017-2024 Cloud Posse, LLC

README footer

Beacon

terraform-aws-acm-request-certificate's People

Contributors

aknysh avatar alexandrusavin avatar cloudpossebot avatar dlundgren avatar dylanbannon avatar gowiem avatar jamie-bitflight avatar joke avatar korenyoni avatar max-lobur avatar maximmi avatar nitrocode avatar nuru avatar osterman avatar philwinder avatar pjaudiomv avatar reixd avatar shovelwagon avatar solairerove avatar sweetops avatar tbpoetke avatar vadim-hleif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-acm-request-certificate's Issues

Add Example Usage

what

  • Add example invocation

why

  • We need this so we can soon enable automated continuous integration testing of module

Wrongly used local instead of variable

Hi,

In the latest release a local is wrongly used instead of a var:

name = "${local.zone_name}."

This breaks using this module with the error:

Error: Error asking for user input: 1 error(s) occurred:

* module.default_wildcard_cert.local.zone_name: local.zone_name: 1:25: unknown variable accessed: var.domain_name in:

${var.zone_name == "" ? var.domain_name : var.zone_name}

external DNS validation (e.g. Cloudflare)

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

It would be great if the module could be used with external DNS validation (e.g. Cloudflare).
This is already implemented in [https://registry.terraform.io/modules/terraform-aws-modules/acm/aws/latest](similar module)

Add ability to specify key_algorithm for certs setup with this module

Describe the Feature

As described in this blog post (https://aws.amazon.com/blogs/security/how-to-evaluate-and-use-ecdsa-certificates-in-aws-certificate-manager/), it is now possible to issue ECDSA certs using ACM. And the underlying Terraform module (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) supports the key_algorithm option that lets us set that. However this module doesn't currently allow passing that value in

Expected Behavior

I'd expect to be able to pass key_algorithm=EC_prime256v1 and see the appropriate cert generated in ACM

Use Case

ECDSA certs use less bandwidth and computation power to work. They're starting to be used more heavily in IoT deploys as described in the above blog post

Describe Ideal Solution

We'd add a new option to this module

Alternatives Considered

No response

Additional Context

No response

`wait_for_certificate_issued` input not waiting until the certificate is issued

Describe the Bug

First time applying my Terraform stack ends in:

Error: creating ELBv2 Listener (arn:aws:elasticloadbalancing:eu-central-1:128840427886:loadbalancer/app/XXX/9202ae7b846a2e1c): UnsupportedCertificate: The certificate 'arn:aws:acm:eu-central-1:128840427886:certificate/e7050367-4b27-4582-8157-3fa96710fccd' must have a fully-qualified domain name, a supported signature, and a supported key size.

after waiting some minutes the next apply show the change of the validation:

module.acm.module.acm_request_certificate.aws_acm_certificate.default[0] has changed
  ~ resource "aws_acm_certificate" "default" {
        id                        = "arn:aws:acm:eu-central-1:128840427886:certificate/e7050367-4b27-4582-8157-3fa96710fccd"
      ~ status                    = "PENDING_VALIDATION" -> "ISSUED"
      + tags                      = {}
        # (7 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

The next apply was sucessfully completed .

I have set wait_for_certificate_issued = true
it should not prevent this ?

Choosing the right zone for each SAN when attaching validation records

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

When you have two SANs that belong to different zones, the module tries to add validation records to the incorrect zone.

Expected Behavior

It should add validation records to zones:

foo.baz.bar.com and bar.com

Steps to Reproduce

Steps to reproduce the behavior:
Say you have these two zones:

zone 1: bar.com
zone 2: foo.baz.bar.com

You want a cert that allows you to use both zones so you do this:

module "acm_request_certificate_east_coast" {
  source = "cloudposse/acm-request-certificate/aws"

  domain_name                       = "foo.baz.bar.com"
  process_domain_validation_options = true
  ttl                               = "300"
  subject_alternative_names         = ["*.foo.baz.bar.com", "*.bar.com"]

  providers = {
    aws = aws.use1
  }
}

When I terraform apply, the module does a data lookup for the zone:

  • baz.bar.com

The expectation is that the zones it should look up:

  • foo.baz.bar.com
  • bar.com

Screenshots

N/A

Environment (please complete the following information):

Mac OS

Additional Notes

In chatting on Slack I suggested this:

Instead of trying to guess what zone to put each SAN in, just have the user specify it manually:

module "cert_request" {
  subject_alternative_names = [
    {
      zone_to_lookup = "foo.baz.com",
      names          = ["a.foo.baz.com", "b.foo.baz.com"]
    },
   {
      zone_to_lookup = "*.baz.com",
      names          = ["bob.baz.com", "alice.baz.com"]
    }
  ]
  # etc etc

Warnings on provider version

What is the provider null used for? I didn't find related usage in the code.

$ terraform init                                                                                                                   ξ‚² Initializing modules...
- module.acm_request_certificate
  Getting source "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=0.2.2"

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "null" (1.0.0)...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.null: version = "~> 1.0"

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

terraform
versions.tf
  • hashicorp/terraform >= 0.13
  • aws >= 3.0

  • Check this box to trigger a request for Renovate to run again on this repository

Error using lookup

Hi there, A lookup is failing for me. See below. Thanks, Phil.

module "acm_request_certificate" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=0.2.0"
  domain_name                       = "example.com"
  process_domain_validation_options = "true"
  ttl                               = "60"
  subject_alternative_names         = ["*.example.com", "*.foo.example.com"]
}
$ terraform version
Terraform v0.11.8
+ provider.aws v1.35.0
+ provider.local v1.1.0
+ provider.null v1.0.0
+ provider.random v2.0.0

$ terraform apply
...
* module.acm_request_certificate.aws_route53_record.default: At column 3, line 1: lookup: argument 1 should be type map, got type string in:

${lookup("null_resource.default.${count.index}","resource_record_name")}

`aws_route53_record.default` errror

Error: module.acm_request_certificate.aws_route53_record.default: 1 error(s) occurred:

* module.acm_request_certificate.aws_route53_record.default: At column 3, line 1: lookup: argument 1 should be type map, got type string in:

${lookup("null_resource.default.${count.index}", "resource_record_type")}

Sorry i just copy pasting my error because i'm a beginner with terraform,

(i'm using the configuration on the readme (with my domain name)

Error: value of 'count' cannot be computed

Even after fixing #16 (dup of #8), release 0.3.0 of this module does not work with Terraform v0.11.13

* module.certificate.null_resource.default: null_resource.default: value of 'count' cannot be computed

This is due to an attempt to allow the module to be disabled, which is probably not possible in Terraform v0.11.

Workaround: reverting to release 0.1.1

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Feature Request - Timeout for wait_for_certificate_issued

Describe the Feature

As of now if one set wait_for_certificate_issued to true, terraform waits forever. It would be good to have some timeout defined.

Describe Ideal Solution

Maybe we can have some timeouts defined in a variable like below and configure it.

wait_for_certificate_issued_timeout: "10m"

Alternatives Considered

None as of now, I had to hit Ctrl + C and re-run the terraform job with wait_for_certificate_issued as false.

Support SANs with multiple hosted zones

Found a feature? Maybe our Slack Community can help.

Slack Community

Describe the Feature

process_domain_validation_options breaks if subject_alternative_names contains different zones

I am using distinct domains in my subject_alternative_names variable...

  domain_name                       = "website.foundation"
  process_domain_validation_options = true
  subject_alternative_names         = [
    "*.website.foundation",
    "websitefoundation.org",
    "*.websitefoundation.org",
  ]

Expected Behavior

It would be nice to process domain validation options across multiple hosted zones.

Certificate validation exception

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

A clear and concise description of what the bug is.

I have a certificate.tf in which I have a domain + subject_alternative_names. This worked well until the aws provider (hashicorp/aws) version was changed to 4.12.0

Expected Behavior

A clear and concise description of what you expected to happen.

Terraform doesn't error while planning or applying

Steps to Reproduce

Steps to reproduce the behavior:

Requesting a certificate where the aws provider is at version 4.12.0 will fail with an error. A snippet of my main.tf where the aws provider is used is shown below:

...
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "4.12.0"
    }
    http = {
      source  = "terraform-aws-modules/http"
      version = "2.4.1"
    }
  }
...

The error:

β•·
β”‚ Error: reading ACM Certificate (2022-04-01 04:14:15.359 +0000 UTC): ValidationException: 1 validation error detected: Value '2022-04-01 04:14:15.359 +0000 UTC' at 'certificateArn' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:[\w+=/,.@-]+:acm:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*
β”‚
β”‚   with module.acm_request_certificate.aws_acm_certificate_validation.default[0],
β”‚   on .terraform/modules/acm_request_certificate/main.tf line 49, in resource "aws_acm_certificate_validation" "default":
β”‚   49: resource "aws_acm_certificate_validation" "default" {

If I change the version of the provider to be >= 4.11.0, terraform completes successfully.

Below is the TF configuration (domain and other data has been redacted):

provider "aws" {
  region  = var.region
  profile = var.profile
}


terraform {
  required_version = ">= 1.1.4"

  backend "s3" {
  # s3 specific parameters
  }

  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "4.12.0"
    }
    http = {
      source  = "terraform-aws-modules/http"
      version = "2.4.1"
    }
  }

}

module "acm_request_certificate" {
  source = "cloudposse/acm-request-certificate/aws"
  version                           = "v0.16.0"
  domain_name                       = aws_route53_zone.SOME_ZONE.name
  process_domain_validation_options = true
  ttl                               = "300"
  subject_alternative_names         = ["*.SOME_ZONE.com", "*.SUBDOMAIN.SOME_ZONE.com"]
  wait_for_certificate_issued       = true
}


resource "aws_route53_zone" "SOME_ZONE" {
  name = "SOME_ZONE.com"
}

Screenshots

If applicable, add screenshots or logs to help explain your problem.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: [e.g. Linux, OSX, WSL, etc]
  • Version [e.g. 10.15]

Additional Context

Add any other context about the problem here.

Module broken if only passing domain name

Describe the Bug

Just passing the domain_name to request the certificate will end in error:

aws_route53_zone.root: Creating...
aws_route53_zone.root: Still creating... [10s elapsed]
aws_route53_zone.root: Still creating... [20s elapsed]
aws_route53_zone.root: Still creating... [30s elapsed]
aws_route53_zone.root: Still creating... [40s elapsed]
aws_route53_zone.root: Creation complete after 44s [id=Z100510839VMYCIY3X0FZ]
module.acm.data.aws_route53_zone.default["io"]: Reading...
module.acm.data.aws_route53_zone.default["example.io"]: Reading...
module.acm.aws_acm_certificate.default[0]: Creating...
module.acm.data.aws_route53_zone.default["example.io"]: Read complete after 1s [id=Z100510839VMYCIY3X0FZ]
module.acm.aws_acm_certificate.default[0]: Creation complete after 6s [id=arn:aws:acm:us-west-2:976668483278:certificate/5a505039-cec1-4407-a629-a71fd18f227a]
β•·
β”‚ Error: no matching Route53Zone found
β”‚
β”‚   with module.acm.data.aws_route53_zone.default["io"],
β”‚   on .terraform/modules/acm/main.tf line 38, in data "aws_route53_zone" "default":
β”‚   38: data "aws_route53_zone" "default" {
β”‚
β•΅

It seems to be trying to get the hosted zone for both "example.io" and just "io" even if I am just passing "example.io" as domain_name. Because the 2nd hosted zone doesn't exist, the module fails.

This works fine if we pick version 0.16.3 of the module.

Expected Behavior

ACM certificate gets created.

Steps to Reproduce

This small code snippet should do it:

resource "aws_route53_zone" "root" {

  name    = "example.io"
  comment = "DNS zone for the root domain"
}

module "acm" {

  source  = "cloudposse/acm-request-certificate/aws"
  version = "0.17.0"

  enabled = true

  domain_name                       = "example.io"
  process_domain_validation_options = true
  ttl                               = 300
  subject_alternative_names         = [format("*.%s", "example.io")]

  depends_on = [aws_route53_zone.root]
}

Screenshots

No response

Environment

  • linux_amd64
  • Module version: 0.0.17
  • Terraform version: Terraform v1.3.8

Additional Context

No response

Issue when creating certificate with wildcards

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

The below causes an invalid index error (see screenshots section for output)

module "acm_internal" {
  source  = "cloudposse/acm-request-certificate/aws"
  version = "0.8.0"

  domain_name                       = "*.internal.example_com"
  zone_name                         = aws_route53_zone.example_com.name
  subject_alternative_names = [
    "*.example_com"
  ]

  process_domain_validation_options = true
  ttl                               = "60"

  tags = module.tagging.tags
}

Expected Behavior

Having wildcards in the domain_name and subject_alternative_names is valid; it should not cause the issue above.

Steps to Reproduce

Plan and apply the given example.

Screenshots


  on .terraform/modules/acm_internal/main.tf line 30, in resource "aws_route53_record" "default":
  30:   name            = lookup(local.domain_validation_options_list[count.index], "resource_record_name")
    |----------------
    | count.index is 0
    | local.domain_validation_options_list is set of object with 2 elements

This value does not have any indices.


Error: Invalid index

  on .terraform/modules/acm_internal/main.tf line 30, in resource "aws_route53_record" "default":
  30:   name            = lookup(local.domain_validation_options_list[count.index], "resource_record_name")
    |----------------
    | count.index is 1
    | local.domain_validation_options_list is set of object with 2 elements

This value does not have any indices.


Error: Invalid index

  on .terraform/modules/acm_internal/main.tf line 31, in resource "aws_route53_record" "default":
  31:   type            = lookup(local.domain_validation_options_list[count.index], "resource_record_type")
    |----------------
    | count.index is 0
    | local.domain_validation_options_list is set of object with 2 elements

This value does not have any indices.


Error: Invalid index

  on .terraform/modules/acm_internal/main.tf line 31, in resource "aws_route53_record" "default":
  31:   type            = lookup(local.domain_validation_options_list[count.index], "resource_record_type")
    |----------------
    | count.index is 1
    | local.domain_validation_options_list is set of object with 2 elements

This value does not have any indices.


Error: Invalid index

  on .terraform/modules/acm_internal/main.tf line 32, in resource "aws_route53_record" "default":
  32:   records         = [lookup(local.domain_validation_options_list[count.index], "resource_record_value")]
    |----------------
    | count.index is 0
    | local.domain_validation_options_list is set of object with 2 elements

This value does not have any indices.


Error: Invalid index

  on .terraform/modules/acm_internal/main.tf line 32, in resource "aws_route53_record" "default":
  32:   records         = [lookup(local.domain_validation_options_list[count.index], "resource_record_value")]
    |----------------
    | count.index is 1
    | local.domain_validation_options_list is set of object with 2 elements


Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: Linux
  • Version 0.13.4
  • Terraform AWS provider 3.11.0

Additional Context

Add any other context about the problem here.

Does not work if Route53 Zone is not created yet and no depends_on strategy implemented - Error: no matching Route53Zone found

The module works fine after having route53 zone created.
Switching now to a new/fresh workspace, and I get the error

Error: no matching Route53Zone found

  on .terraform/modules/dns.public_acm_request_certificate/main.tf line 19, in data "aws_route53_zone" "default":
  19: data "aws_route53_zone" "default" {

This snippet of my TF plan :

resource "aws_route53_zone" "publiczone" {
  lifecycle {
    prevent_destroy = true
  }
  count     = length(var.public_zone_name) > 0 ? 1 : 0
  comment   = "Public Hosted Zone for ${terraform.workspace} environment"
  name      = var.public_zone_name
  tags      = {
    Environment = terraform.workspace
  }
}

module "public_acm_request_certificate" {
  source                                                         = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=0.4.0"
  domain_name                                           = var.public_zone_name
  process_domain_validation_options = true
  ttl                                                                  = "300"
  subject_alternative_names                   = ["*.${var.public_zone_name}"]
  tags = {
      ZoneId                                                   = join("", aws_route53_zone.publiczone.*.zone_id)
  }
}

As workaround, and as you can see in the snippet, I tried to link the module with the zone by assigning the zone_id attribute as value for tags (module variable).. But the same issue , the same error.

Provide extra variable for the route53_zone data source

Problem

I want to create this certificate:

domain_name                  = "site.example.org"
subject_alternative_names = ["www.site.example.org"]

My existing Route53 hosted zone is example.org.

The module fails because it looks for the site.example.org zone, which does not exist. I want to keep my example.org zone and I don't want to create a wildcard certificate.

Solution

  • add extra variable zone_name
  • use variable zone_name as name for the route53_zone data source if it exists:
variable "zone_name" {
  type        = "string"
  default     = ""
  description = "The Hosted Zone name of the desired Hosted Zone"
}

data "aws_route53_zone" "default" {
  count        = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? 1 : 0}"
  name         = "${local.zone_name}"
  private_zone = false
}

locals {
  zone_name = "${var.zone_name == "" ? var.domain_name. : var.zone_name}"
}

I am happy to write a PR if you agree with the proposed solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.