LoginSignup
0
0

More than 1 year has passed since last update.

Terraform(ECS on Fargate作成)

Posted at

やってみたコード

############ ECR ############
resource "aws_ecr_repository" "ecr" {
  name = "${var.project}-${var.environment}-ecr"
}

############ ECS クラスター ############
resource "aws_ecs_cluster" "ecs-cluster" {
  name = "ecs-cluster-terraform"

  setting {
    name  = "containerInsights"
    value = "disabled"
  }
}

############ ECS サービス ############
resource "aws_ecs_service" "ecs-service" {
  name            = "ecs-service-front-terraform"
  cluster         = aws_ecs_cluster.ecs-cluster.id
  task_definition = aws_ecs_task_definition.ecs-front-fargate.arn
  desired_count   = 1
  launch_type     = "FARGATE"

  network_configuration {
    subnets          = ["${aws_subnet.public_subnet_1a.id}","${aws_subnet.public_subnet_1c.id}"]
    security_groups  = ["${aws_security_group.front-sg.id}"]
    assign_public_ip = "false"
  }
}

############ ECS タスク定義(フロント) ############
resource "aws_ecs_task_definition" "ecs-front-fargate" {
  family                   = "ecs-task-front-terraform"
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"
  cpu                      = 1024
  memory                   = 2048
  container_definitions    = <<TASK_DEFINITION
[
  {
    "name": "Nginx",
    "image": "nginx",
    "cpu": 1024,
    "memory": 2048,
    "essential": true
  }
]
TASK_DEFINITION
}

間違えたところ

考えすぎて、ドキュメント読み込むよりさっさと
terraform plan やってエラー確認している方がいいかな

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0