Erro silencioso quando o Terraform é implementado no ECS

0

Eu sou novo no Terraform e tenho problemas para configurar uma configuração básica. Eu quero algo que traga minha imagem "docker-whale" . Olhando para Hashicorp e AWS docs, parece que preciso de um “ aws_ecs_service ” que use um “ aws_ecs_task_definition ”.

Usando este exemplo , criei a configuração abaixo.

variable "access_key" {}
variable "secret_key" {}

provider "aws" {
  alias = "west"
  region = "us-west-1"
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
}

resource "aws_ecs_cluster" "default" {
  name = "whale"
}

resource "aws_ecs_service" "whale-service" {
  name            = "whale-service"
  cluster         = "${aws_ecs_cluster.default.id}"
  task_definition = "${aws_ecs_task_definition.whale-task.arn}"
  desired_count   = 1
}

resource "aws_ecs_task_definition" "whale-task" {
  family = "whale"
  container_definitions = "${file("task-definitions/whale.json")}"
  volume {
    name = "whale-home"
    host_path = "/ecs/whale-home"
  }
}

Agora, quando eu corro terraform apply ( access_key & secret_key redacted ), tudo parece funcionar bem. Mas não vejo uma definição de cluster ou tarefa do ECS correspondente no meu console da web do AWS. Estou faltando alguma coisa?

$ terraform apply 
provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Default: us-east-1
  Enter a value: 

aws_ecs_task_definition.whale-task: Refreshing state... (ID: whale)
aws_ecs_cluster.default: Creating...
  name: "" => "whale"
aws_ecs_cluster.default: Creation complete
aws_ecs_service.whale-service: Creating...
  cluster:                            "" => "arn:aws:ecs:us-east-1:186598327969:cluster/whale"
  deployment_maximum_percent:         "" => "200"
  deployment_minimum_healthy_percent: "" => "100"
  desired_count:                      "" => "1"
  name:                               "" => "whale-service"
  task_definition:                    "" => "arn:aws:ecs:us-east-1:186598327969:task-definition/whale:1"
aws_ecs_service.whale-service: Creation complete

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the 'terraform show' command.

State path: terraform.tfstate
    
por Nutritioustim 10.04.2016 / 21:40

1 resposta

0

Você não iniciou nenhuma instância para estar em seu cluster, mas acredito que ainda conseguirá ver o cluster no gerenciador do ECS.

Comecei a trabalhar com este arquivo: link

Onde há um grupo de escalonamento automático que inicia instâncias para o cluster e usa user_data para marcar a máquina como parte do cluster

/* SSH key pair */
resource "aws_key_pair" "ecs" {
  key_name   = "${var.key_name}"
  public_key = "${file(var.key_file)}"
}

/**
 * Launch configuration used by autoscaling group
 */
resource "aws_launch_configuration" "ecs" {
  name                 = "ecs"
  image_id             = "${lookup(var.amis, var.region)}"
  /* @todo - split out to a variable */
  instance_type        = "${var.instance_type}"
  key_name             = "${aws_key_pair.ecs.key_name}"
  iam_instance_profile = "${aws_iam_instance_profile.ecs.id}"
  security_groups      = ["${aws_security_group.ecs.id}"]
  iam_instance_profile = "${aws_iam_instance_profile.ecs.name}"
  user_data            = "#!/bin/bash\necho ECS_CLUSTER=${aws_ecs_cluster.default.name} > /etc/ecs/ecs.config"
}

/**
 * Autoscaling group.
 */
resource "aws_autoscaling_group" "ecs" {
  name                 = "ecs-asg"
  availability_zones   = ["${split(",", var.availability_zones)}"]
  launch_configuration = "${aws_launch_configuration.ecs.name}"
  /* @todo - variablize */
  min_size             = 1
  max_size             = 10
  desired_capacity     = 1
}

/* ecs service cluster */
resource "aws_ecs_cluster" "default" {
  name = "${var.ecs_cluster_name}"
}
    
por 13.06.2016 / 23:00