/terraform_module_ecs_fargate

Módulo para provisionar VPC com subnets públicas e privadas, Elastic Load Balancer, ECR e ECS Fargate(Cluster,Service,TaskDefinition)

Primary LanguageHCLGNU General Public License v3.0GPL-3.0

Terraform module for ECS Fargate

Requirements

How to use this module

Clone this repo

git clone https://github.com/chnacib/terraform_module_ecs_fargate
cd terraform_module_ecs_fargate/module

Edit terrafile.tf and replace variables in module

module "ecs_fargate" {
  source                = "../"
  fargate_cpu           = 512
  fargate_memory        = 1024
  proj_name             = "exemplo"
  ecs_service_name      = "svc-exemplo"
  service_desired_count = 1
  ecs_cluster_name      = "cluster-exemplo"
  task_name             = "task-exemplo"
  container_name        = "container-exemplo"
  container_port        = 80
  ecr_name              = "repository-exemplo"
  vpc_cidr              = "10.0.0.0/16"
  log_retention_days     = 7
  public_subnet_1_cidr  = "10.0.1.0/24"
  public_subnet_2_cidr  = "10.0.2.0/24"
  public_subnet_3_cidr  = "10.0.3.0/24"
  private_subnet_1_cidr = "10.0.11.0/24"
  private_subnet_2_cidr = "10.0.22.0/24"
  private_subnet_3_cidr = "10.0.33.0/24"
  environment = [
    {
      "name" : "EXEMPLO1",
      "value" : "exemplo1"
    },
    {
      "name" : "EXEMPLO2",
      "value" : "b"
    }#Adicionar variáveis adicionando vírgula e chaves
  ]

}

Deploy terraform module

terraform init

terraform plan

terraform apply -auto-approve

Providers

Name Version
aws n/a

Modules

Name Source Version
ecs_fargate ../ n/a

Resources

Name Type
aws_alb.ecs_cluster_alb resource
aws_alb_listener.listener_http resource
aws_alb_target_group.ecs_app_target_group resource
aws_appautoscaling_policy.cpu resource
aws_appautoscaling_target.ecs_target resource
aws_cloudwatch_log_group.main resource
aws_ecr_repository.fargate resource
aws_ecs_cluster.fargate-cluster resource
aws_ecs_service.service_terraform resource
aws_ecs_task_definition.terraform-task-definition resource
aws_eip.elastic-ip-for-nat-gw resource
aws_iam_role.ecs_cluster_role resource
aws_iam_role.fargate_iam_role resource
aws_iam_role_policy.ecs_cluster_policy resource
aws_iam_role_policy.fargate_iam_policy resource
aws_internet_gateway.terraform-igw resource
aws_nat_gateway.nat-gw resource
aws_route.nat-gw-route resource
aws_route.public-internet-igw-route resource
aws_route_table.private-route-table resource
aws_route_table.public-route-table resource
aws_route_table_association.private-route-1-association resource
aws_route_table_association.private-route-2-association resource
aws_route_table_association.private-route-3-association resource
aws_route_table_association.public-route-1-association resource
aws_route_table_association.public-route-2-association resource
aws_route_table_association.public-route-3-association resource
aws_security_group.ecs_alb_security_group resource
aws_security_group.sg_ecs_service_terraform resource
aws_subnet.private-subnet-1 resource
aws_subnet.private-subnet-2 resource
aws_subnet.private-subnet-3 resource
aws_subnet.public-subnet-1 resource
aws_subnet.public-subnet-2 resource
aws_subnet.public-subnet-3 resource
aws_vpc.terraform-vpc resource

Inputs

Name Description Type Default Required
container_name Container name string n/a yes
container_port Container port number n/a yes
ecr_name ECR repository name string n/a yes
ecs_cluster_name ECS Cluster name string n/a yes
ecs_service_name ECS service name string n/a yes
environment Container environment variable any n/a yes
fargate_cpu Task definition CPU number n/a yes
fargate_memory Task definition Memory number n/a yes
log_retention_days Cloudwatch logs retention days number 7 no
private_subnet_1_cidr Private subnet az1 CIDR string n/a yes
private_subnet_2_cidr Private subnet az2 CIDR string n/a yes
private_subnet_3_cidr Private subnet az3 CIDR string n/a yes
proj_name Project name string n/a yes
public_subnet_1_cidr Public subnet az1 CIDR string n/a yes
public_subnet_2_cidr Public subnet az2 CIDR string n/a yes
public_subnet_3_cidr Public subnet az3 CIDR string n/a yes
region AWS Region string "us-east-1" no
service_desired_count Service desired count number n/a yes
task_name ECS Task definition name string n/a yes
vpc_cidr VPC CIDR string n/a yes