Repository contains a terraform module for ECS-Optimized instance deployment to your cluster.
In addition to standard deployment, it
- allows to define what cluster the instance must be deployed to
- turns on awslogs driver
- creates a record in internal Route 53 hosted zone
- attaches, formats and mounts an EBS volume for permanent data storage
Describe docker host configuration as a module in the terraform JSON config (*.tf.json):
{
"module": {
"docker_host_1": {
"source": "github.com/snatalenko/tf_docker_host//2016.09.g",
"app": "myapp",
"env": "production",
// where the instance should be deployed to
"region": "us-east-1",
"subnet_id": "${aws_subnet.public_1.id}",
"cluster_name": "${aws_ecs_cluster.web.name}",
"associate_public_ip_address": true,
"disable_api_termination": false,
// instance size
"instance_type": "t2.micro",
// data volume configuration (10Gb standard EBS volume mounted to /ecs/)
"volume_data_size": 10,
"volume_data_type": "gp2",
"volume_data_terminate": false,
// security configuration
"iam_instance_profile": "${aws_iam_instance_profile.docker_host.name}",
"vpc_security_group_ids": "${aws_security_group.web.id},${aws_security_group.admin.id}",
"key_name": "${aws_key_pair.admin.key_name}",
// instance location within an internal hosted zone (VPC DNS)
"route53_zone_id": "${aws_route53_zone.local.zone_id}",
"hostname": "my-ecs-host-1.internal.domain",
"instance_index": 1
}
}
}
The above configuration depends on the following services, which should be defined either in additional modules on in the main Terraform script:
{
"resource": {
"aws_ecs_cluster": {
"web": { /* ... */ }
},
"aws_subnet": {
"public_1": { /* ... */ }
},
"aws_key_pair": {
"admin": { /* ... */ }
},
"aws_security_group": {
"web": { /* ... */ },
"admin": { /* ... */ }
},
"aws_iam_instance_profile": {
"docker_host": { /* ... */ }
},
"aws_route53_zone": {
"local": { /* ... */ }
}
}
}
After the configuraton is complete, run terraform get
in terminal to download the module from github.
The following attributes are exported:
- id - ECS instance ID
- public_ip - instance public IP, if attached
- private_ip - instance private IP within VPC
- hostname - either defined in configuration or autogenerated instance hostname