hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.79k stars 9.14k forks source link

Changes to aws_ecs_task_definition are completely undocumented in upgrade guide or changelog #14575

Open damusix opened 4 years ago

damusix commented 4 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Latest AWS to date (3.2) Latest Terraform to date (0.13)

Terraform Configuration Files

resource "aws_ecs_task_definition" "default" {
  ...
  volume {
      name = "myvol"

      docker_volume_configuration = {

        scope         = "shared"
        autoprovision = true
        driver        = "local"

        driver_opts = {
            type   = "nfs"
            device = "${aws_efs_file_system.default.dns_name}:/pgdata"
            o      = "addr=${aws_efs_file_system.default.dns_name},rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport"
        }
      }
  }
}

References

Wanted to update my TF to all the latest things include AWS 3. I have ECS containers that depend on the volume block to mount an EFS volume on fargate. Version 2 has documentation on how to add volumes to aws_ecs_task_definition. Version 3 apparently has completely gutted that configuration block with no clear description of how to set up.

ljluestc commented 12 months ago
resource "aws_ecs_task_definition" "example" {
  family                   = "example-family"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  execution_role_arn        = aws_iam_role.execution_role.arn

  container_definitions = jsonencode([
    {
      name  = "example-container"
      image = "nginx:latest"

      portMappings = [
        {
          containerPort = 80
          hostPort      = 80
        },
      ]
    },
  ])

  volume {
    name = "example-volume"

    efs_volume_configuration {
      file_system_id          = aws_efs_file_system.example.id
      root_directory          = "/example"
      transit_encryption     = "ENABLED"
      transit_encryption_port = 2999
    }
  }
}

resource "aws_efs_file_system" "example" {
  creation_token = "example"
  lifecycle      = "AFTER_7_DAYS"
}

resource "aws_iam_role" "execution_role" {
  name = "example-role"

  assume_role_policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Action = "sts:AssumeRole",
        Effect = "Allow",
        Principal = {
          Service = "ecs-tasks.amazonaws.com"
        }
      },
    ]
  })
}