Reputation: 11
i'm using terraform to create a cluster on aws. When i run my code it spins up an ec2 instance but it doesn't show up in my container instances even though i have a capacity provider and autoscaling group in my terraform code. When i run the code i expect for the ec2 instance to show as the infrastructure for my Ecs cluster. At the moment it creates the ec2 but the my cluster hasn't registered the ec2 container instance so I can’t run any tasks.
https://github.com/Dandiggas/FirstWebApp/blob/main/terraform.txt
Upvotes: 1
Views: 683
Reputation: 297
Most likely your EC2 instance is not joining the cluster. You can do this by setting up the following userdata for the EC2 instance (where MyCluster is the name of your cluster):
#!/bin/bash
echo "ECS_CLUSTER=MyCluster" >> /etc/ecs/ecs.config
Also make sure your EC2 instance has internet access or a VPC endpoint to communicate with the ECS API.
See for more information:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html
Upvotes: 1