ECSのタスク定義
from ECS
コンテナの実行に必要な設定を定義する
例えば、
使用するイメージ
必要なCPUやメモリの量
ポートマッピング
環境変数
ボリューム
など
https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task_definition_parameters.html
container definition
https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definitions
resource "aws_ecs_task_definition"
docs
code:tf
resource "aws_ecs_task_definition" "example" {
family = "example" # A unique name for your task definition.
cpu = "256"
memory = "512"
network_mode = "awsvpc"
requires_compatibilities = "FARGATE"
execution_role_arn = aws_iam_role.example.arn
container_definitions = jsonencode([
{
name = "example-container"
image = "nginx"
cpu = 256
memory = 512
essential = true
portMappings = [
{
containerPort = 80
hostPort = 80
protocol = "tcp"
},
]
},
])
}
Terraform: jsonencode()
https://developer.hashicorp.com/terraform/language/functions/jsonencode
HCLをJSONにencodeする関数
https://qiita.com/kanga/items/1ae96b7da2a7d76b070e
良くも悪くも割と雑に書いても動くっぽい