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: ECS Task Definition container_definitions is invalid: decoding JSON: json: cannot unmarshal string into Go struct field PortMapping.PortMappings.ContainerPort of type int64 #38620

Open
PlusMinus0 opened this issue Jul 31, 2024 · 4 comments
Labels
bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service.

Comments

@PlusMinus0
Copy link

Terraform Core Version

1.9.3

AWS Provider Version

5.54.1

Affected Resource(s)

aws_ecs_task_definition

Expected Behavior

This configuration should work

  family             = var.service_name
  network_mode       = "awsvpc"
  execution_role_arn = var.execution_role_arn
  cpu                = 256
  memory             = 512
  container_definitions = jsonencode([
    {
      cpu         = 0
      environment = var.task_environment_variables
      mountPoints = []
      systemControls = []
      volumesFrom = []
      name        = var.service_name
      image       = var.environment == "DEV" ? replace(var.container_image, "/:.+$/", ":latest") : var.container_image
      repositoryCredentials = {
        credentialsParameter = var.repository_credentials_arn
      }
      essential   = true
      healthCheck = local.health_check_command == null ? null : {
        command  = local.health_check_command,
        interval = 30
        timeout  = 5
        retries  = 3
      }

      logConfiguration = {
        logDriver = "awslogs"
        options = {
          awslogs-group         = aws_cloudwatch_log_group.default.name
          awslogs-region        = var.region
          awslogs-stream-prefix = "ecs"
        }
      }
      portMappings = [
    {
      name          = lower(var.service_name)
      containerPort = var.service_port
      hostPort      = var.service_port
      protocol      = "tcp"
    }
  ]
    }
  ])
  requires_compatibilities = ["FARGATE"]
  runtime_platform {
    operating_system_family = "LINUX"
    cpu_architecture        = "X86_64"
  }
  # The following are set so terraform does not detect a diff when there is none (check if it worked)
  ipc_mode      = null
  pid_mode      = null
  tags = {}
  task_role_arn = ""
}

Actual Behavior

Once I add name to the port mapping, the run errors with:

Error: ECS Task Definition container_definitions is invalid: decoding JSON: json: cannot unmarshal string into Go struct field PortMapping.PortMappings.ContainerPort of type int64

It works without the name attribute.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

app.terraform.io

Steps to Reproduce

Add name to port mapping

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@PlusMinus0 PlusMinus0 added the bug Addresses a defect in current functionality. label Jul 31, 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 31, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jul 31, 2024
@justinretzolk
Copy link
Member

Hey @PlusMinus0 👋 Thank you for taking the time to raise this! There were some other issues with this argument that were fixed with #38622, to be included in 5.61.0, which should be out later today. Can you test with this new version once it's out and let us know if the issue persists?

@justinretzolk justinretzolk added the waiting-response Maintainers are waiting on response from community or contributor. label Aug 1, 2024
@PlusMinus0
Copy link
Author

I'll check it tomorrow morning (CEST)

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Aug 1, 2024
@PlusMinus0
Copy link
Author

No luck, unfortunately. Now, on app.terraform.io I see another error message in the plan before the diagnostics:

Failed generating plan JSON
Exit code: 1

Failed to marshal plan to json: error marshaling prior state: schema version 0 for aws_ecs_service.default in state does not match version 1 from the provider
Operation failed: 2 errors occurred:

  • failed running terraform plan (exit 1)
  • failed generating plan JSON: failed running command (exit 1)

And the type in the previous error message changed from Int64 to Int32:

Error: ECS Task Definition container_definitions is invalid: json: cannot unmarshal string into Go struct field PortMapping.PortMappings.ContainerPort of type int32

If I remove the name field, everything still works as expected.

@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

No branches or pull requests

2 participants