Open damusix opened 4 years 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"
}
},
]
})
}
Community Note
Terraform CLI and Terraform AWS Provider Version
Latest AWS to date (3.2) Latest Terraform to date (0.13)
Terraform Configuration Files
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 toaws_ecs_task_definition
. Version 3 apparently has completely gutted that configuration block with no clear description of how to set up.