Skip to content

jkobejs/terraform-ecs-web-services

Repository files navigation

AWS Elastic Container Service (ECS) Terraform configuration

Terraform configuration which creates EC2 lauch type ECS resources on AWS together with postgres RDS.

asciicast

Usage

You will first need to install terraform and configure aws cli profile.

brew install terraform

By default both, free tier and default configuration use default profile. If you want to specify different profile you can to that by specifiying variables on the commandline using -var option

terraform apply -var-file="free-tier.tfvars" -var="profile=jkobejs"
terraform apply -var="profile=jkobejs"

Free tier

This configuration creates working ECS cluster with RDS using AWS Free Tier offering.

To create free tier infrastructure run

terraform apply -var-file="free-tier.tfvars"

command. It will create virtual private network in eu-central-1 region that contains:

  • 2 availability zones
  • 2 subnets (public, database)
  • application load balancer (public subnet)
  • auto scaling group (public subnet)
  • RDS (database subnet)

free-tier-vpc

Besides VPC command will create:

  • ECS cluster
  • container instances
  • user ecs task and servic

Using this command auto scaling group that contains EC2 container intances will be placed in public subnet. Usually desired place to place container instances would be private subnet. Since container instances need to communicate with ECS cluster over internet only way to satify this using Free Tier resources is to put it in public subnet because NAT gateways are not part of Free Tier.

Default (you will be billed for some resources)

By default terraform

terraform apply

command will create virtual private network in eu-central-1 region that contains:

  • 2 availability zones
  • 3 subnets (public, private, database)
  • application load balancer (public subnet)
  • NAT gateway per availability zone (public subnet)
  • auto scaling group (private subnet)
  • RDS (database subnet)

default-vpc

Besides VPC command will create:

  • ECS cluster
  • container instances
  • user ecs task and service

Requirements

No requirements.

Providers

No provider.

Inputs

Name Description Type Default Required
asg_desired_capacity The number of Amazon EC2 instances that should be running in the group number 0 no
asg_max_size The maximum size of the auto scale group number 1 no
asg_min_size The minimum size of the auto scale group number 0 no
asg_wait_for_capacity_timeout Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over min_elb_capacity behavior. number 0 no
azs Availability zones, at least 2 availability zones should be specified list
[
"eu-central-1a",
"eu-central-1b"
]
no
cidr VPC's cidr string "10.1.0.0/16" no
database_subnets Subnet in which database services will be deployed list
[
"10.1.13.0/24",
"10.1.23.0/24"
]
no
db_instance_type Database instance type string "db.t2.micro" no
db_name Database name string "master" no
db_password Database password string "ChangeMe!" no
db_username Database username string "db_user" no
ec2_instance_type EC2 instance type string "t2.micro" no
enable_nat_gateway Flag that determines if NAT gateway will be created bool true no
environment Environment in which resources will be created string "dev" no
name Base name for all resources string "ecs-terraform" no
one_nat_gateway_per_az Flag that determines if one NAT gateway will be created per AZ bool true no
private_subnets Subnet in which private services will be deployed list
[
"10.1.12.0/24",
"10.1.22.0/24"
]
no
profile Named profile, more on https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html string "default" no
public_container_instances Flag that determines if container instances are in public subnet (useful in free tier) bool false no
public_subnets Subnet in which public services will be deployed list
[
"10.1.11.0/24",
"10.1.21.0/24"
]
no
region AWS region string "eu-central-1" no

Outputs

Name Description
alb_arn ALB arn
alb_dns_name ALB DNS name
alb_ecs_role_arn ALB role
alb_traget_group_arns ALB target groups arns
asg_arn ASG arn
ecr_arn ECR arn
ecr_id ECR id
ecs_cluster_arn ECS cluster arn
ecs_cluster_id ECS cluster id
ecs_cluster_name ECS cluster name
erc_url ECR url
rds_arn RDS arn
rds_host RDS host
vpc_id VPC id

Authors

Module managed by jkobejs

License

Apache 2 Licensed. See LICENSE for full details.

About

AWS Elastic Container Service (ECS) Terraform configuration for deploying web services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published