compliance.tf

ACM: known Terraform limitations

Some things people ask the terraform-aws-modules/acm/aws module for cannot be implemented by any module, in any registry. They are limits of Terraform itself. This page collects the recurring ones for this module, says plainly what causes each, gives the native workaround in full, and - where one exists - shows the Operational Rule that removes the need for a fork.

Read the native option first

Every problem below names the workaround you can apply today without compliance.tf. Several of them are the right answer on their own. The rule is an alternative to maintaining a fork, not a replacement for a control AWS already offers you.


Replacing an ACM certificate takes the listener down

Changing a certificate's domains or validation method forces replacement. Terraform destroys the old certificate before creating the new one, and the listener referencing it has nothing valid to serve in between - or the destroy fails outright because the certificate is still in use.

Why Terraform cannot fix this

lifecycle is a meta-argument block, and Terraform evaluates it before it evaluates the rest of the configuration. Its arguments therefore cannot reference a variable, a local, or anything else that is computed. That is the whole reason no module can expose prevent_destroy, ignore_changes, or create_before_destroy as an input: there is no expression a module author could put there that Terraform would accept.

This is a property of Terraform, not of this module. The request to lift the restriction has been open since 2015, it is one of the most-supported requests in the tracker, and OpenTofu carries the same request. Until one of them ships a way to set a meta-argument from outside the resource block, every module in every registry has the same limitation.

RepositoryIssueTitle
hashicorp/terraform#3116Cannot use interpolations in lifecycle attributes
hashicorp/terraform#18367Feature request: support prevent_destroy for modules
hashicorp/terraform#21546Passing ignore_changes into a module
hashicorp/terraform#24188Support for dynamic blocks and meta-arguments
hashicorp/terraform#27360A method to override configuration and meta arguments within a module
opentofu/opentofu#1329Support variables in lifecycle blocks

The native workaround

The fix is create_before_destroy = true on the certificate, which is a lifecycle argument and cannot be passed in. Fork this module and add the lifecycle block to the resource yourself. That works, and it is the honest answer - it is what module maintainers do when they need it. The cost is ongoing rather than one-off: the fork has to be re-synced with every upstream release, and each sync needs a review to confirm the block still lands on the resource it was meant for. A wrapper module does not avoid this, because the lifecycle block still has to sit inside the resource block, which is inside the module you did not write.

The operational alternative is to do it in two applies: create the replacement certificate under a new resource address, move the listener onto it, then remove the old one.

Managed fix

Native option only, today. compliance.tf has no rule for this yet, so the workaround above is the whole answer. create_before_destroy is not yet available as a rule.

Using the maintained alternative

compliance.tf serves this module from a registry that applies the rules above during terraform init. The change is the source line; the inputs and outputs are the upstream module's.

module "acm" {
  source = "https://cis.compliance.tf/terraform-aws-modules/acm/aws"

  # ... the same inputs you pass today ...
}

None of the limitations above has a rule yet, so this module is served with compliance controls only. The ?add_rules= parameter takes the ids of rules that do exist - see Operational Rule Definitions.


On this page

Ask AI about this

Help improve this page