Creates an ECS cluster backed by an AutoScaling Group.
The cluster is minimally configured and expects any ECS service added will
use awsvpc
networking and Task IAM Roles for access control.
Creates the following resources:
- IAM role for the container instance.
- Launch Configuration and AutoScaling group.
- ECS cluster.
data "aws_ami" "ecs_ami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-*-amazon-ecs-optimized"]
}
}
module "app_ecs_cluster" {
source = "trussworks/ecs-cluster/aws"
name = "app"
environment = "prod"
image_id = "${data.aws_ami.ecs_ami.image_id}"
instance_type = "t2.micro"
vpc_id = "${module.vpc.id}"
subnet_ids = "${module.vpc.private_subnets}"
desired_capacity = 3
max_size = 3
min_size = 3
}
Terraform 0.13. Pin module version to ~> 3.0. Submit pull-requests to master branch.
Terraform 0.12. Pin module version to ~> 2.0. Submit pull-requests to terraform012 branch.
Terraform 0.11. Pin module version to ~> 1.0. Submit pull-requests to terraform011 branch.
Name | Version |
---|---|
terraform | >= 0.13.0 |
aws | ~> 3.0 |
Name | Version |
---|---|
aws | ~> 3.0 |
Name | Description | Type | Default | Required |
---|---|---|---|---|
desired_capacity | Desired instance count. | string |
2 |
no |
environment | Environment tag. | string |
n/a | yes |
image_id | Amazon ECS-Optimized AMI. | string |
n/a | yes |
instance_type | The instance type to use. | string |
"t2.micro" |
no |
max_size | Maxmimum instance count. | string |
2 |
no |
min_size | Minimum instance count. | string |
2 |
no |
name | The ECS cluster name this will launching instances for. | string |
n/a | yes |
security_group_ids | A list of security group ids to attach to the autoscaling group | list(string) |
[] |
no |
subnet_ids | A list of subnet IDs to launch resources in. | list(string) |
n/a | yes |
use_AmazonEC2ContainerServiceforEC2Role_policy | Attaches the AWS managed AmazonEC2ContainerServiceforEC2Role policy to the ECS instance role. | string |
true |
no |
vpc_id | The id of the VPC to launch resources in. | any |
n/a | yes |
Name | Description |
---|---|
ecs_cluster_arn | The ARN of the ECS cluster. |
ecs_cluster_name | The name of the ECS cluster. |
ecs_instance_role | The name of the ECS instance role. |
Install dependencies (macOS)
brew install pre-commit go terraform terraform-docs
pre-commit install --install-hooks
Terratest is being used for
automated testing with this module. Tests in the test
folder can be run
locally by running the following command:
make test
Or with aws-vault:
AWS_VAULT_KEYCHAIN_NAME=<NAME> aws-vault exec <PROFILE> -- make test