<p>Due to how that resource type is designed, from Terraform's standpoint <code>replication_task_settings</code> is just an opaque string and so Terraform can either detect that the string has changed (the default) or ignore changes to the string as a whole.</p>
<p>There is no way to ignore changes to only part of a string, because Terraform implements <code>ignore_changes</code> by taking the previous value of that argument instead of the new value. Terraform doesn't and can't know how to construct an new string that combines some characters from the old string and some characters from the new string, because it has no awareness of the meaning of that string.</p>

CC BY-SA 4.0
2020-12-09T00:13:48.153Z
2020-12-09T00:13:48.153Z
Martin Atkins
<p>I'm currently trying to get CloudWatch logging and DMS configuration working smoothly in my module by ignoring certain attributes on <code>replication_task_settings</code>. Right now, I have a DMS replication task that looks like the following:</p>
<pre><code>resource &quot;aws_dms_replication_task&quot; &quot;main&quot; {
  migration_type            = &quot;full-load-and-cdc&quot;
  replication_instance_arn  = var.replication_instance_arn
  replication_task_id       = &quot;${var.environment}-${var.customer}-dms-replication-task-ongoing-main-${var.engine}&quot;
  source_endpoint_arn       = var.source_endpoint_arn
  target_endpoint_arn       = var.target_endpoint_arn
  replication_task_settings = jsonencode(local.task_settings)
  table_mappings            = jsonencode(local.table_mappings)
  tags                      = merge({}, local.additional_labels)

  lifecycle {
    ignore_changes = [
      replication_task_settings
    ]
  }
}

</code></pre>
<p>With this configuration, I'm ignoring all future changes to <code>replication_task_settings</code>. What I would like to do is only ignore changes to only <code>Logging.CloudWatchLogGroup</code> and <code>Logging.CloudWatchLogStream</code> (not all of the task settings) since DMS creates these for you and you can't change them. The problem is that the <code>replication _task_settings</code> is a JSON-encoded attribute. If I try to do <code>ignore_changes = [replication_task_settings[&quot;Logging&quot;][&quot;CloudWatchLogStream&quot;]]</code>, I get this error:</p>
<pre><code>Error: Invalid index

  on modules/repl-ongoing/main.tf line 250, in resource &quot;aws_dms_replication_task&quot; &quot;main&quot;:
 250:       replication_task_settings[&quot;Logging&quot;][&quot;CloudWatchLogStream&quot;]

This value does not have any indices.
</code></pre>
<p>If I try to decode the JSON by doing: <code>ignore_changes = [jsondecode(replication_task_settings)[&quot;Logging&quot;][&quot;CloudWatchLogStream&quot;]]</code>, I get the following error:</p>
<pre><code>Error: Invalid expression

  on modules/repl-ongoing/main.tf line 250, in resource &quot;aws_dms_replication_task&quot; &quot;main&quot;:
 250:       jsondecode(replication_task_settings)[&quot;Logging&quot;][&quot;CloudWatchLogStream&quot;]

A single static variable reference is required: only attribute access and
indexing with constant keys. No calculations, function calls, template
expressions, etc are allowed here.
</code></pre>
<p>Is there a way I can ignore changes to specific properties of JSON-encoded attributes? Or is there another workaround with DMS tasks that I have to go with?</p>

<amazon-web-services><terraform>
Terraform ignore_changes block on JSON-encoded attribute
Zachary Delano
# Terraform ignore_changes block on JSON-encoded attribute

(Asked by: username_0 on 2020-12-08)

I'm currently trying to get CloudWatch logging and DMS configuration working smoothly in my module by ignoring certain attributes on replication_task_settings. Right now, I have a DMS replication task that looks like the following:
resource "aws_dms_replication_task" "main" {
  migration_type            = "full-load-and-cdc"
  replication_instance_arn  = var.replication_instance_arn
  replication_task_id       = "${var.environment}-${var.customer}-dms-replication-task-ongoing-main-${var.engine}"
  source_endpoint_arn       = var.source_endpoint_arn
  target_endpoint_arn       = var.target_endpoint_arn
  replication_task_settings = jsonencode(local.task_settings)
  table_mappings            = jsonencode(local.table_mappings)
  tags                      = merge({}, local.additional_labels)

  lifecycle {
    ignore_changes = [
      replication_task_settings
    ]
  }
}


With this configuration, I'm ignoring all future changes to replication_task_settings. What I would like to do is only ignore changes to only Logging.CloudWatchLogGroup and Logging.CloudWatchLogStream (not all of the task settings) since DMS creates these for you and you can't change them. The problem is that the replication _task_settings is a JSON-encoded attribute. If I try to do ignore_changes = [replication_task_settings["Logging"]["CloudWatchLogStream"]], I get this error:
Error: Invalid index

  on modules/repl-ongoing/main.tf line 250, in resource "aws_dms_replication_task" "main":
 250:       replication_task_settings["Logging"]["CloudWatchLogStream"]

This value does not have any indices.

If I try to decode the JSON by doing: ignore_changes = [jsondecode(replication_task_settings)["Logging"]["CloudWatchLogStream"]], I get the following error:
Error: Invalid expression

  on modules/repl-ongoing/main.tf line 250, in resource "aws_dms_replication_task" "main":
 250:       jsondecode(replication_task_settings)["Logging"]["CloudWatchLogStream"]

A single static variable reference is required: only attribute access and
indexing with constant keys. No calculations, function calls, template
expressions, etc are allowed here.

Is there a way I can ignore changes to specific properties of JSON-encoded attributes? Or is there another workaround with DMS tasks that I have to go with?

**Tags:** amazon-web-services, terraform


---

## 1 answers

### Answer by username_1 on 2020-12-09. Score: 3 | Accepted answer

Due to how that resource type is designed, from Terraform's standpoint `replication_task_settings` is just an opaque string and so Terraform can either detect that the string has changed (the default) or ignore changes to the string as a whole.

There is no way to ignore changes to only part of a string, because Terraform implements `ignore_changes` by taking the previous value of that argument instead of the new value. Terraform doesn't and can't know how to construct an new string that combines some characters from the old string and some characters from the new string, because it has no awareness of the meaning of that string.


---

