Replace_triggered_by on conditionally created resources

Hi @nomeelnoj1,

That’s an interesting situation, and I think what you’re asking would be still covered by one of the use cases for the terraform_data utility resource.

Because replace_triggered_by needs to be a list of references as opposed to values, there’s currently no way to dynamically process that as it needs to be static. What you could do however is point those references at an intermediary resource where you can do that data processing.

I think the simplest change might look something like this:

resource "terraform_data" "launch_templates" {
  # this way the terraform_data.launch_templates keys always align with 
  # aws_batch_compute_environment
  for_each = var.compute_environments
  input = try(aws_launch_template.default[each.key].id, null)
}
...
  # then within aws_batch_compute_environment you can point to the proxy
  # resource to look for changes.
  lifecycle {
    replace_triggered_by = [terraform_data.launch_templates[each.key]]
  }