Reputation: 71
Anyone managed to do ignore changes for specific variable inside container_definitions on resource aws_ecs_task_definition. To be precise, doing terraform as IaC, but CI/CD part for testing environments are done with third party tool which allows people to deploy new version of app. Deployment is creating new version of task definition with new image id. So after some time there is drift changes between terraform and actual infrastructure. I tried to do ignore changes for specific env variable but it actually ignores fully container definition then.
Simple code:
resource "aws_ecs_task_definition" "task" {
family = local.short_name
container_definitions = jsonencode([
{
],
image : "XXXXXX"
name : local.short_name,
}
])
tags = local.base_tags
lifecycle {
ignore_changes = [
something like this should work
aws_ecs_task_definition.task.container_definitions.image
]
}
}
resource "aws_ecs_task_definition" "task" {
family = local.short_name
container_definitions = jsonencode([
{
],
image : "XXXXXX"
name : local.short_name,
}
])
tags = local.base_tags
lifecycle {
ignore_changes = [
something like this should work
aws_ecs_task_definition.task.container_definitions.image
]
}
}
Upvotes: 6
Views: 4622
Reputation: 74694
It seems that the container_definitions
argument is, as far as Terraform Core is concerned, just a big string. Terraform Core doesn't know that the provider is going to interpret the string as JSON, and so Terraform doesn't understand what it would mean to ignore an attribute inside that string.
Therefore I think ignore_changes
is not a suitable answer to your problem here. If you expect this object to be managed by software outside of Terraform then I would recommend having that software be responsible for creating it in the first place too, and not manage it with Terraform at all. If you do decide to manage this with Terraform and use ignore_changes
, it will only be possible to ask Terraform to ignore changes to the entire container_definitions
argument, and not for any specific sub-portion of it.
Upvotes: 7