Add ignore_changes for dynamic gsi block

Hi All,
I am trying to add ignore_changes for GSI read and write capacity in the code block below. I have tried several methods to make it work, but with no luck. Could anyone kindly provide a solution on how to set ignore_changes for the read and write capacity of a dynamic GSI block?

main.tf :

resource "aws_dynamodb_table" "default" {
  count            = var.enabled ? 1 : 0
  name             = var.name
  billing_mode     = var.billing_mode
  read_capacity    = var.dynamodb_read_capacity
  write_capacity   = var.dynamodb_write_capacity
  hash_key         = var.hash_key
  range_key        = var.range_key
  stream_enabled   = var.enable_streams
  stream_view_type = var.enable_streams ? var.stream_view_type : ""

  server_side_encryption {
    enabled = var.enable_encryption
    kms_key_arn = var.kms_key_arn
  }

  point_in_time_recovery {
    enabled = var.enable_point_in_time_recovery
  }

  dynamic "attribute" {
    for_each = local.attributes_final
    content {
      name = attribute.value.name
      type = attribute.value.type
    }
  }

  dynamic "global_secondary_index" {
    for_each = var.global_secondary_index_map
    content {
      hash_key           = global_secondary_index.value.hash_key
      name               = global_secondary_index.value.name
      non_key_attributes = lookup(global_secondary_index.value, "non_key_attributes", null)
      projection_type    = global_secondary_index.value.projection_type
      range_key          = lookup(global_secondary_index.value, "range_key", null)
      read_capacity      = lookup(global_secondary_index.value, "read_capacity", null)
      write_capacity     = lookup(global_secondary_index.value, "write_capacity", null)
    }
  }

  ttl {
    attribute_name = var.ttl_attribute
    enabled        = var.ttl_attribute != "" && var.ttl_attribute != null ?  true : false
  }

  tags = var.tags

  lifecycle {
//    ignore_changes = [
//      read_capacity,
//      write_capacity,
//      global_secondary_index[*].read_capacity,
//      global_secondary_index[*].write_capacity
//    ]
    prevent_destroy = true
  }

}

module :

module "test" {
  source                        = "../tf-module/dynamodb"
  enabled                       = local.env == "uat" ? false : local.env == "lt" ? false : local.env == "prod" ? true : false
  name                          = "${local.env}-test"
  hash_key                      = "testhashkey"
  dynamodb_read_capacity        = local.test-read
  dynamodb_write_capacity       = local.test-write
  read_target_value             = local.test-read-target-value
  write_target_value            = local.test-write-target-value
  enable_point_in_time_recovery = local.env == "prod" ? true : false
  tags                          = merge(tomap({ "Name" = join("-", [local.env, local.project, "test"]) }), tomap({ "ResourceType" = "dynamodb" }), local.common_tags)
}

Hi @tisaiful31,

As far as I am aware this is not possible as the list provided to ignore_changes has to be a static list and it does not support parameterisation/interpolation/splats.

There is this issue open: Support for dynamic blocks and meta-arguments · Issue #24188 · hashicorp/terraform (github.com)
but has not had further comment for a year, even though it is 7th in the list of issues by :+1: [votes]( Issues · hashicorp/terraform (github.com)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.