ECS agent error after creating instance using terraform.

480 views
Skip to first unread message

Dmitry Molotkov

unread,
Jan 3, 2016, 7:25:14 PM1/3/16
to Terraform

Im trying to use EC2 Container service. Im using terraform for creating it. I have defined a ecs cluster, autoscaling group, launch configuration. All seems to work. Except one thing. The ec2 instances are creating, but they are not register in the cluster, cluster just says no instances available.

In ecs agent log on created instance i found logs flooded with one error:

Error registering: NoCredentialProviders: no valid providers in chain

The ec2 instances are created with a proper role ecs_role. This role has two policies, one of them is following, like docs required:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ecs:CreateCluster",
        "ecs:DeregisterContainerInstance",
        "ecs:DiscoverPollEndpoint",
        "ecs:Poll",
        "ecs:RegisterContainerInstance",
        "ecs:StartTelemetrySession",
        "ecs:Submit*",
        "ecs:StartTask"
      ],
      "Resource": "*"
    }
  ]
}

Im using ami ami-6ff4bd05 . Latest terraform.

What is wrong?


resource "aws_launch_configuration" "ecs" {
name_prefix = "ecs-rentapp-launch-"
image_id = "${lookup(var.ecs_amis, var.AWS_REGION)}"
/* @todo - split out to a variable */
instance_type = "${var.ecs_instance_type}"
key_name = "${aws_key_pair.deployer.key_name}"
iam_instance_profile = "${aws_iam_instance_profile.ecs.id}"
security_groups = ["${aws_security_group.ecs_node.id}"]
user_data = "#!/bin/bash\necho ECS_CLUSTER=rentapp-cluster >> /etc/ecs/ecs.config"
lifecycle {
create_before_destroy = true
}
}



Mahesh Subramanian

unread,
Jan 6, 2016, 2:07:07 PM1/6/16
to Terraform
Try attaching AmazonEC2ContainerServiceFullAccess policy to your instance iam instance role
Reply all
Reply to author
Forward
0 new messages