Skip to content

Commit bf618eb

Browse files
committed
Adding port variable
1 parent 2974a2a commit bf618eb

File tree

4 files changed

+72
-42
lines changed

4 files changed

+72
-42
lines changed

README.md

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,47 @@ This Terraform module deploys an AWS ECS Fargate service.
77
## Usage
88

99
Check valid versions on:
10-
* Github Releases: <https://github.com/jnonino/terraform-aws-ecs-fargate/releases>
11-
* Terraform Module Registry: <https://registry.terraform.io/modules/jnonino/ecs-fargate/aws>
10+
* Github Releases: <https://github.com/jnonino/terraform-aws-ecs-fargate-service/releases>
11+
* Terraform Module Registry: <https://registry.terraform.io/modules/jnonino/ecs-fargate-service/aws>
1212

1313
module "ecs-fargate-service":
14-
source = "jnonino/ecs-fargate/aws"
15-
version = "2.0.4"
14+
source = "jnonino/ecs-fargate-service/aws"
15+
version = "1.0.0"
1616
name_preffix = var.name_preffix
1717
profile = var.profile
1818
region = var.region
1919
vpc_id = module.networking.vpc_id
20-
availability_zones = module.networking.availability_zones
21-
public_subnets_ids = module.networking.public_subnets_ids
22-
private_subnets_ids = module.networking.private_subnets_ids
23-
container_name = "<CONTAINER_NAME>"
24-
container_image = "<IMAGE_NAME>:<IMAGE_TAG>"
25-
container_cpu = 1024
26-
container_memory = 8192
27-
container_memory_reservation = 2048
28-
essential = true
29-
container_port = 9000
30-
environment = [
31-
{
32-
name = "<VARIABLE_NAME>"
33-
value = "<VARIABLE_VALUE>"
34-
}
35-
]
20+
task_definition_arn = module.td.aws_ecs_task_definition_td_arn
21+
container_port = module.td.container_port
22+
ecs_cluster_arn = module.ecs-cluster.aws_ecs_cluster_cluster_arn
23+
subnets = module.networking.private_subnets_ids
3624
}
3725

3826
Check the section "Other modules that you may need to use this module" for details about modules mentioned in the usage example.
3927

28+
## Input values
29+
30+
* name_preffix: Name preffix for resources on AWS.
31+
* profile: AWS API key credentials to use.
32+
* region: AWS Region the infrastructure is hosted in.
33+
* vpc_id: ID of the VPC.
34+
* task_definition_arn: (Required) The full ARN of the task definition that you want to run in your service.
35+
* ecs_cluster_arn: ARN of an ECS cluster.
36+
* subnets: The subnets associated with the task or service.
37+
* container_port: Port on which the container is listening.
38+
* desired_count: (Optional) The number of instances of the task definition to place and keep running. Defaults to 1.
39+
* platform_version: (Optional) The platform version on which to run your service. Defaults to LATEST. More information about Fargate platform versions can be found in the AWS ECS User Guide.
40+
* deployment_maximum_percent: (Optional) 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.
41+
* deployment_minimum_healthy_percent: (Optional) 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.
42+
* enable_ecs_managed_tags: (Optional) Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
43+
* propagate_tags: (Optional) Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. Default to SERVICE.
44+
* ordered_placement_strategy: (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered_placement_strategy blocks is 5. This is a list of maps where each map should contain "id" and "field".
45+
* health_check_grace_period_seconds: (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers.
46+
* placement_constraints: (Optional) rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain "type" and "expression".
47+
* service_registries: (Optional) The service discovery registries for the service. The maximum number of service_registries blocks is 1. This is a map that should contain the following fields "registry_arn", "port", "container_port" and "container_name".
48+
* security_groups: (Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used.
49+
* assign_public_ip: (Optional) Assign a public IP address to the ENI (Fargate launch type only). Valid values are true or false. Default false.
50+
4051
## Output values
4152

4253
* aws_ecs_service_service_id: The Amazon Resource Name (ARN) that identifies the service.
@@ -77,3 +88,34 @@ Check versions for this module on:
7788
* Github Releases: <https://github.com/jnonino/terraform-aws-networking/releases>
7889
* Terraform Module Registry: <https://registry.terraform.io/modules/jnonino/networking/aws>
7990

91+
The ECS cluster module should look like this:
92+
93+
module "ecs-cluster":
94+
source = "jnonino/ecs-cluster/aws"
95+
version = "1.0.0"
96+
name_preffix = var.name_preffix
97+
profile = var.profile
98+
region = var.region
99+
}
100+
101+
Check versions for this module on:
102+
* Github Releases: <https://github.com/jnonino/terraform-aws-ecs-cluster/releases>
103+
* Terraform Module Registry: <https://registry.terraform.io/modules/jnonino/ecs-cluster/aws>
104+
105+
The task definition module should like this:
106+
107+
module "td" {
108+
source = "jnonino/ecs-fargate-task-definition/aws"
109+
version = "1.0.1"
110+
name_preffix = var.name_preffix
111+
profile = var.profile
112+
region = var.region
113+
container_name = "${var.name_preffix}-<NAME>"
114+
container_image = "<IMAGE_NAME>:<IMAGE_TAG>"
115+
container_port = <PORT>
116+
}
117+
118+
Check versions for this module on:
119+
* Github Releases: <https://github.com/jnonino/terraform-aws-ecs-fargate-task-definition/releases>
120+
* Terraform Module Registry: <https://registry.terraform.io/modules/jnonino/ecs-fargate-task-definition/aws>
121+

load-balancing.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "aws_lb" "lb" {
2929
name = "${var.name_preffix}-lb"
3030
internal = false
3131
load_balancer_type = "application"
32-
subnets = var.public_subnets_ids
32+
subnets = var.subnets
3333
security_groups = [aws_security_group.lb_sg.id]
3434
enable_deletion_protection = false
3535
enable_cross_zone_load_balancing = true

main.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ module "aws_cw_logs" {
2626
region = var.region
2727
}
2828

29-
# ---------------------------------------------------------------------------------------------------------------------
30-
# ECS CLUSTER
31-
# ---------------------------------------------------------------------------------------------------------------------
32-
module "ecs_cluster" {
33-
source = "jnonino/ecs-cluster/aws"
34-
version = "1.0.0"
35-
profile = var.profile
36-
region = var.region
37-
name = var.name_preffix
38-
}
39-
4029
# ---------------------------------------------------------------------------------------------------------------------
4130
# AWS SECURITY GROUP - ECS Tasks, allow traffic only from Load Balancer
4231
# ---------------------------------------------------------------------------------------------------------------------

variables.tf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ variable "vpc_id" {
2323
description = "ID of the VPC"
2424
}
2525

26-
variable "availability_zones" {
27-
type = list
28-
description = "List of Availability Zones"
29-
}
30-
3126
# ---------------------------------------------------------------------------------------------------------------------
3227
# AWS ECS SERVICE
3328
# ---------------------------------------------------------------------------------------------------------------------
@@ -39,6 +34,15 @@ variable "ecs_cluster_arn" {
3934
description = "ARN of an ECS cluster"
4035
}
4136

37+
variable "subnets" {
38+
description = "The subnets associated with the task or service."
39+
type = list
40+
}
41+
42+
variable "container_port" {
43+
description = "Port on which the container is listening"
44+
}
45+
4246
variable "desired_count" {
4347
description = "(Optional) The number of instances of the task definition to place and keep running. Defaults to 1."
4448
type = number
@@ -96,11 +100,6 @@ variable "service_registries" {
96100
default = {}
97101
}
98102

99-
variable "subnets" {
100-
description = "The subnets associated with the task or service."
101-
type = list
102-
}
103-
104103
variable "security_groups" {
105104
description = "(Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used."
106105
type = list

0 commit comments

Comments
 (0)