Open lemiliomoreno opened 8 months ago
I also tried to set up the default values stored in the state file but still forces replacement
resource "awscc_ecs_task_definition" "db_task_definition" {
container_definitions = [
{
name = "${var.environment}-${var.application}-db"
image = "postgres:15"
port_mappings = [{
name = "${var.environment}-${var.application}-db-port"
container_port = 5432
protocol = "tcp"
}]
log_configuration = {
log_driver = "awslogs"
options = {
awslogs-group = "${var.environment}-${var.application}-db-log-group"
awslogs-region = "${var.aws_region}"
awslogs-stream-prefix = "ecs"
}
}
environment = [
{
name = "POSTGRES_DB"
value = "${data.aws_ssm_parameter.db_name.value}"
},
{
name = "POSTGRES_PASSWORD"
value = "${data.aws_ssm_parameter.db_password.value}"
},
{
name = "POSTGRES_USER"
value = "${data.aws_ssm_parameter.db_username.value}"
},
]
mount_points = [
{
source_volume = "${var.environment}-${var.application}-db-volume",
container_path = "/var/lib/postgresql",
read_only = false
}
]
}
]
cpu = 256
ephemeral_storage = {
size_in_gi_b = 30
}
execution_role_arn = aws_iam_role.db_execution_role.arn
family = "${var.environment}-${var.application}-db-task-definition"
inference_accelerators = null
ipc_mode = null
memory = 512
network_mode = "awsvpc"
pid_mode = null
placement_constraints = null
proxy_configuration = null
requires_compatibilities = [
"FARGATE",
]
runtime_platform = {
cpu_architecture = "X86_64"
operating_system_family = "LINUX"
}
tags = null
task_role_arn = aws_iam_role.db_task_role.arn
volumes = [
{
configured_at_launch = true
docker_volume_configuration = null
efs_volume_configuration = null
host = null
name = "${var.environment}-${var.application}-db-volume"
}
]
}
I was able to replicate the behavior on resource awscc_ecs_task_definition
.
It seemed that these attributes that forces replacement are declared in the Terraform state file as null
. On contrary, CCAPI GetResource is returning an empty value or empty list.
I suspect this is related to #1139
Problem with resource awscc_ecs_service
also seemed to stem from the same behavior as described in #1139
Community Note
Terraform CLI and Terraform AWS Cloud Control Provider Version
Affected Resource(s)
awscc_ecs_task_definition
awscc_ecs_service
Terraform Configuration Files
Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.
Debug Output
Panic Output
Expected Behavior
awscc_ecs_task_definition
andawscc_ecs_task_definition
should not be replaced/updated when no change has been made to the code.Actual Behavior
awscc_ecs_task_definition
andawscc_ecs_task_definition
are being updated/replaced when no change has been made to the code.Steps to Reproduce
This is my ecs_task and ecs_service definitions:
When I run
terraform plan
I get the following output even no chage has been made:I've found that if I change some values same as the one's returned by the provider, will not detect a change, i.e.:
If I just replace the subnets in the correct order, it won't show as change.
This still happens in https://github.com/hashicorp/terraform-provider-aws/issues/23726, https://github.com/hashicorp/terraform-provider-aws/issues/11526.
As this happens with ECS Task Definition, it's the same for ECS Service as it detects a change in Task Definition.
This might be a limitation with Cloud Control API, as it seems that there is not UpdateTask, only RegisterTask actions for the API.
Important Factoids
References