Terraform ignore_changes on dynamic resources

Viewed 1030

I have TF project with application gateway, which has multiple dynamically generated HTTP listeners:

 dynamic "http_listener" {
    for_each = var.gateway_config
    iterator = cf
    content {
      name                           = "${cf.value["domain_name"]}-http"
      frontend_ip_configuration_name = local.frontend_ip_configuration_name
      frontend_port_name             = local.frontend_http_port_name
      protocol                       = "Http"
      host_name                      = cf.value["domain_name"]
    }
  }

I'd like to apply ignore_changes lifecycle on all of those HTTP listeners "firewall_policy_id" paremeters.

Things that I've tried:

(...)
      ignore_changes = [
          http_listener[firewall_policy_id],
      ]

this ends in error - single static variable is required

      ignore_changes = [
          http_listener["firewall_policy_id"],
      ]

this doesn't do anything at all

      ignore_changes = [
          http_listener.*.firewall_policy_id,
      ]

this returns error, as * is not correct in this place

My only solution for now is to add all possible HTTP listeners (all 200 of them), but it looks really ugly and takes up way to much space in the code:

ignore_changes = [
          http_listener[0].firewall_policy_id,
          http_listener[1].firewall_policy_id,
          http_listener[2].firewall_policy_id,
          ...
          http_listener[200].firewall_policy_id,
      ]

Tried with some for list comprehensions with range(200) but again - error, Terraform needs to have a static value in that place.

1 Answers

Option 1. Just remove target from state file.

example

terraform state rm your_resource_want_to_ignore

Option 2.

Try refresh state

terraform refresh

I have been searched this subject but realized not yet no neat solution.

This problem looks like to similar ignoring task definition change in ecs service.

Even on github repo discussion, I couldn't find good way.

https://github.com/hashicorp/terraform-provider-aws/issues/258

Related