Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error: Provider produced inconsistent final plan │ aws_ecs_task_definition.container_definitions #38466

Closed
ThomasMarcelo opened this issue Jul 22, 2024 · 5 comments · Fixed by #38471
Labels
bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service.
Milestone

Comments

@ThomasMarcelo
Copy link

ThomasMarcelo commented Jul 22, 2024

Terraform Core Version

1.9.2

AWS Provider Version

4.52.0

Affected Resource(s)

resource "aws_ecs_task_definition"

Expected Behavior

The task definition should be created when running terraform apply for the first time. This was working up until today.

Actual Behavior

I got an error on the first terraform apply, but I get no errors when re-running, and the infrastructure is created. Since this is being done on a GitHub Actions workflow for 4 applications, I had to re-run it 4 times, which is not ideal.

Relevant Error/Panic Output Snippet

  │ Error: Provider produced inconsistent final plan
  │ 
  │ When expanding the plan for aws_ecs_task_definition.api to include new
  │ values learned so far during apply, provider
  │ "registry.terraform.io/hashicorp/aws" produced an invalid new value for
  │ .container_definitions: inconsistent values for sensitive attribute.
  │ 
  │ This is a bug in the provider, which should be reported in the provider's
  │ own issue tracker.

Terraform Configuration Files

terraform.tfvars

app_name            = "app"
database_env        = "dev"
postgresql_database = "database"

env_vars = {
    "POSTGRESQL_HOST" = "",
    "POSTGRESQL_DB" = "",
    "POSTGRESQL_PASSWORD" = ""
}

terraform.tf

variable "app_name" {
  type        = string
  description = "Application Name"
}

variable "database_env" {
  type     = string
  default = "dev"
}

variable "postgresql_database" {
  type     = string
}

variable "env_vars" {
  type = map
}

variable "secrets" {
  default = [
    "SECRET_A",
    "SECRET_B",
    "SECRET_C",
  ]
  type = list(string)
}

locals {
  urls={
    POSTGRESQL_HOST="${var.database_env}.url.us-east-1.rds.amazonaws.com",
    POSTGRESQL_DB="${var.postgresql_database}"
    POSTGRESQL_PASSWORD="${jsondecode(data.aws_secretsmanager_secret_version.latest_secrets.secret_string)[var.database_env == "prod" ? "POSTGRES_PROD_PASSWORD" : "POSTGRES_DEV_PASSWORD"]}",
  }
}

resource "aws_ecs_task_definition" "api" {
  family                   = "${var.app_name}-api"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  cpu                      = 512
  memory                   = 3072
  execution_role_arn       = data.aws_iam_role.ecs_execution_role.arn
  task_role_arn            = data.aws_iam_role.ecs_execution_role.arn

  // I even added this because I saw it as a solution for similar issues in the past, but no success
  lifecycle {
    ignore_changes = all
  }
  // -----

  container_definitions = jsonencode([
    {
      name   = "${var.app_name}-api"
      image  = "${aws_ecr_repository.api.repository_url}:latest"
      cpu    = 512
      memory = 3072
      portMappings = [
        {
          containerPort = 3100
          hostPort      = 3100
          protocol      = "tcp"
        }
      ]
      environment = [
        for k, v in var.env_vars : {
          name  = k
          value = (
            contains(keys(local.urls), k) ? local.urls[k] : v
          )
        }
      ]
      secrets = [for secret in var.secrets : {
        name      = "${secret}",
        valueFrom = "${data.aws_secretsmanager_secret.secrets.arn}:${secret}::"
      }]
      command = ["yarn", "workspace", "${var.app_name}-api", "run", "start"]
      healthCheck = {
        command  = ["CMD-SHELL", "curl -f -k http://localhost:3100/health"]
        interval = 30
        timeout  = 10
        retries  = 3
        startPeriod = 60
      }
      logConfiguration = {
        logDriver = "awslogs"
        options = {
          "awslogs-group"         = data.aws_cloudwatch_log_group.log-group.name
          "awslogs-region"        = var.aws_region
          "awslogs-stream-prefix" = "${var.app_name}-api"
        }
      }
    }
  ])
  tags = {
    Name = "${var.app_name}-api-task-definition"
  }
}

Steps to Reproduce

terraform apply

Would you like to implement a fix?

No

@ThomasMarcelo ThomasMarcelo added the bug Addresses a defect in current functionality. label Jul 22, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/ecs Issues and PRs that pertain to the ecs service. label Jul 22, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jul 22, 2024
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Jul 22, 2024
@ewbankkit
Copy link
Contributor

Relates #38461.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.60.0 milestone Jul 23, 2024
Copy link

This functionality has been released in v5.60.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
2 participants