Dynamic lifecycle ignore_changes?

Hi,

Is it possible (with terraform 0.12) to have a dynamic ignore_changes in a lifecycle block?
What I’m hoping to achieve is to make ignoring changes to “user_data” optional in one of our modules.

I’ve tried variants of this:

lifecycle {
  ignore_changes = [<<-EOT
     tags.FQDN,
     tags.InstanceInfo,
     tags,
     var.extra_lifecycle_ignore
EOT
]

But get the error “A static list expression is required”.

I’ve also tried dynamic blocks but get the error “Unsupported block type … Blocks of type “lifecycle” are not expected here”

Kind regards,
Magnus

HI Magnus, as I read the documentation the ignore_changes list should not be written as a heredoc.

If you’re ignoring the entire tags maps, it seem unneccessary to also ignore specific elements.

lifecycle {
  ignore_changes = [
     tags,
     var.extra_lifecycle_ignore
]}

Thanks for the reply @bentterp. I get a different error if I try your suggestion:

This object has no argument, nested block, or exported attribute named "var".
Did you mean "arn"?

Thanks for pointing out the ignoring of all tags. It was a terraform 0.11->0.12 conversion error.

Maybe I should also read the documentation I link to :roll_eyes:

“list of attribute names”, so no we can’t put a variable in there, that’s not an attribute to the instancwe resource.

Can you try setting userdata as ignore?

lifecycle {
  ignore_changes = [
     tags,
     userdata
]}

So we ignore not the changes in input parameters but the resulting changes in tags and userdata. That’s probably how it’s intended to work.

Yes that works but my goal was to make ignoring user_data optional. For most use cases of our module we don’t want to ignore user_data changes but for some we do.

That doesn’t seem possible: “The lifecycle settings all effect how Terraform constructs and traverses the dependency graph. As a result, only literal values can be used because the processing happens too early for arbitrary expression evaluation.”

They might not close&reject such a feature request right away, but I think it’s unlikely that it would be resolved quickly.

Closest I can think of, right now, is to have duplicate resource declarations in the module, and use one for the case where you ignore changes to userdata and the other where you don’t. But if you change your mind, it’s destroy and recreate.

FYI, I’ve raised this as an FR in https://github.com/hashicorp/terraform/issues/24188.