Terraform module which creates ECS Fargate resources on AWS.
terraform-aws-ecs-fargate
Terraform module which creates ECS Fargate resources on AWS.
Description
Provision ECS Service and ECS Task Definition.
This module provides recommended settings:
- Fargate launch type
- Disable assign public ip address
Usage
Minimal
module "ecs_fargate" {
source = "git::https://github.com/tmknom/terraform-aws-ecs-fargate.git?ref=tags/2.0.0"
name = "example"
container_name = "nginx"
container_port = "80"
cluster = var.ecsclusterarn
subnets = var.subnets
targetgrouparn = var.targetgrouparn
vpcid = var.vpcid
containerdefinitions = var.containerdefinitions
}
Complete
module "ecs_fargate" {
source = "git::https://github.com/tmknom/terraform-aws-ecs-fargate.git?ref=tags/2.0.0"
name = "example"
container_name = "nginx"
container_port = "80"
cluster = var.ecsclusterarn
subnets = var.subnets
targetgrouparn = var.targetgrouparn
vpcid = var.vpcid
containerdefinitions = var.containerdefinitions
desired_count = 2 deploymentmaximumpercent = 200 deploymentminimumhealthy_percent = 100 deploymentcontrollertype = "ECS" assignpublicip = true healthcheckgraceperiodseconds = 10 platform_version = "1.4.0" sourcecidrblocks = ["0.0.0.0/0"] cpu = 256 memory = 512 requires_compatibilities = ["FARGATE"] iampath = "/servicerole/" description = "This is example" enabled = true
createecstaskexecutionrole = false ecstaskexecutionrolearn = var.ecstaskexecutionrolearn
tags = { Environment = "prod" } }
Examples
Requirements
| Name | Version | | --------- | ------- | | terraform | >= 0.12 |
Providers
| Name | Version | | ---- | ------- | | aws | n/a |
Inputs
| Name | Description | Type | Default | Required | | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | --------------------------------- | :------: | | cluster | ARN of an ECS cluster. | string | n/a | yes | | container_definitions | A list of valid container definitions provided as a single valid JSON document. | string | n/a | yes | | container_name | The name of the container to associate with the load balancer (as it appears in a container definition). | string | n/a | yes | | container_port | The port on the container to associate with the load balancer. | string | n/a | yes | | name | The name of ecs service. | string | n/a | yes | | subnets | The subnets associated with the task or service. | list(string) | n/a | yes | | targetgrouparn | The ARN of the Load Balancer target group to associate with the service. | string | n/a | yes | | vpc_id | VPC Id to associate with ECS Service. | string | n/a | yes | | assignpublicip | Assign a public IP address to the ENI (Fargate launch type only). Valid values are true or false. | string | false | no | | cpu | The number of cpu units used by the task. | string | "256" | no | | createecstaskexecutionrole | Specify true to indicate that ECS Task Execution IAM Role creation. | string | true | no | | deploymentcontrollertype | Type of deployment controller. Valid values: CODE_DEPLOY, ECS. | string | "ECS" | no | | deploymentmaximumpercent | The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. | string | 200 | no | | deploymentminimumhealthy_percent | The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. | string | 100 | no | | description | The description of the all resources. | string | "Managed by Terraform" | no | | desired_count | The number of instances of the task definition to place and keep running. | string | 0 | no | | ecstaskexecutionrolearn | The ARN of the ECS Task Execution IAM Role. | string | "" | no | | enabled | Set to false to prevent the module from creating anything. | string | true | no | | healthcheckgraceperiodseconds | Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. | string | 60 | no | | iam_path | Path in which to create the IAM Role and the IAM Policy. | string | "/" | no | | memory | The amount (in MiB) of memory used by the task. | string | "512" | no | | platform_version | The platform version on which to run your service. | string | "1.4.0" | no | | requires_compatibilities | A set of launch types required by the task. The valid values are EC2 and FARGATE. | list(string) |
[| no | | sourcecidrblocks | List of source CIDR blocks. |
"FARGATE"
]
list(string) | [| no | | tags | A mapping of tags to assign to all resources. |
"0.0.0.0/0"
]
map(string) | {} | no |
Outputs
| Name | Description | | ---------------------------- | --------------------------------------------------------------------- | | ecsservicecluster | The Amazon Resource Name (ARN) of cluster which the service runs on. | | ecsservicedesired_count | The number of instances of the task definition. | | ecsserviceiam_role | The ARN of IAM role used for ELB. | | ecsserviceid | The Amazon Resource Name (ARN) that identifies the service. | | ecsservicename | The name of the service. | | ecstaskdefinition_arn | Full ARN of the Task Definition (including both family and revision). | | ecstaskdefinition_family | The family of the Task Definition. | | ecstaskdefinition_revision | The revision of the task in a particular family. | | iampolicyarn | The ARN assigned by AWS to this IAM Policy. | | iampolicydescription | The description of the IAM Policy. | | iampolicydocument | The policy document of the IAM Policy. | | iampolicyid | The IAM Policy's ID. | | iampolicyname | The name of the IAM Policy. | | iampolicypath | The path of the IAM Policy. | | iamrolearn | The Amazon Resource Name (ARN) specifying the IAM Role. | | iamrolecreate_date | The creation date of the IAM Role. | | iamroledescription | The description of the IAM Role. | | iamrolename | The name of the IAM Role. | | iamroleunique_id | The stable and unique string identifying the IAM Role. | | securitygrouparn | The ARN of the ECS Service security group. | | securitygroupdescription | The description of the ECS Service security group. | | securitygroupegress | The egress rules of the ECS Service security group. | | securitygroupid | The ID of the ECS Service security group. | | securitygroupingress | The ingress rules of the ECS Service security group. | | securitygroupname | The name of the ECS Service security group. | | securitygroupowner_id | The owner ID of the ECS Service security group. | | securitygroupvpc_id | The VPC ID of the ECS Service security group. |
Development
Development Requirements
Configure environment variables
export AWSACCESSKEY_ID=AKIAIOSFODNN7EXAMPLE
export AWSSECRETACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWSDEFAULTREGION=ap-northeast-1
Installation
git clone git@github.com:tmknom/terraform-aws-ecs-fargate.git
cd terraform-aws-ecs-fargate
make install
Makefile targets
apply-complete Run terraform apply examples/complete
apply-minimal Run terraform apply examples/minimal
check-format Check format code
clean Clean .terraform
destroy-complete Run terraform destroy examples/complete
destroy-minimal Run terraform destroy examples/minimal
diff Word diff
docs Generate docs
format Format code
help Show help
install Install requirements
lint Lint code
plan-complete Run terraform plan examples/complete
plan-minimal Run terraform plan examples/minimal
release Release GitHub and Terraform Module Registry
upgrade Upgrade makefile
Releasing new versions
Bump VERSION file, and run make release.
Terraform Module Registry
License
Apache 2 Licensed. See LICENSE for full details.