This module creates Amazon ECS (Elastic Container Service) cluster on EC2 with Auto Scaling Group.
# main.tf
module "ecs_cluster" {
source = "git::https://github.com/lpavliuk/Terraform-Modules.git//aws_ecs_cluster"
name = "example"
subnet_ids = var.subnet_group_subnets_ids
node_image_id = data.aws_ssm_parameter.ecs_node_ami.value
node_instance_type = "t4g.micro"
node_min_count = 2
node_security_group_ids = [ aws_security_group.ecs_node.id ]
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "ecs_node" {
name_prefix = "ecs-node-example-"
vpc_id = var.vpc_id
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter
data "aws_ssm_parameter" "ecs_node_ami" {
# Retrieving Amazon ECS-Optimized AMI metadata:
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/retrieve-ecs-optimized_AMI.html
name = "/aws/service/ecs/optimized-ami/amazon-linux-2023/arm64/recommended/image_id"
}
Name | Version |
---|---|
terraform | < 2.0.0, >= 1.6.6 |
aws | < 6.0, >= 5.22 |
Name | Description | Type | Default | Required |
---|---|---|---|---|
name | Name of the ECS Cluster NOTE! Must contain alphanumeric characters or hyphens ( - ). |
string |
n/a | yes |
subnet_ids | Subnet IDs | list(string) |
n/a | yes |
node_image_id | Node Image (AMI) ID. NOTE! Changing this will trigger instance refresh! |
string |
n/a | yes |
node_instance_type | Node Instance Type | string |
"t4g.micro" |
no |
node_min_count | Minimum number of Nodes in Auto Scaling Group | number |
2 |
no |
node_max_count | Maximum number of Nodes in Auto Scaling Group. Default is the min_nodes_count |
number |
null |
no |
node_security_group_ids | Security Groups IDs attached to the Node | list(string) |
[] |
no |
node_extra_tags | Node Extra Tags | list(object({ |
[] |
no |
Name | Description |
---|---|
id | ECS Cluster ID |
name | ECS Cluster Name |
capacity_provider_name | ECS Capacity Provider Name |
auto_scaling_group_name | Auto Scaling Group Name |
node_launch_template_id | Node Launch Template ID |
node_launch_template_latest_version | Node Launch Template Latest Version |
node_launch_template_image_id | Node Launch Template Image ID |
node_iam_role | Node IAM Role Name |
node_iam_profile | Node IAM Instance Profile Name |
Name | Type |
---|---|
aws_autoscaling_group.ecs | resource |
aws_ecs_capacity_provider.this | resource |
aws_ecs_cluster.this | resource |
aws_ecs_cluster_capacity_providers.this | resource |
aws_iam_instance_profile.ecs_node | resource |
aws_iam_role.ecs_node | resource |
aws_iam_role_policy_attachment.this_iam_role | resource |
aws_launch_template.ecs_node | resource |
aws_iam_policy_document.ecs_node_role_policy | data source |