terraform-aws-arc-ecs¶
Overview¶
SourceFuse's AWS Reference Architecture Terraform module leverages the terraform-aws-modules/terraform-aws-ecs GitHub repository to facilitate the deployment and management of an AWS ECS (Elastic Container Service) cluster. It streamlines the configuration of ECS tasks, services, and related components, providing a scalable and efficient solution for orchestrating containerized applications. With customizable settings for logging and load balancing the module promotes seamless deployment and management of containerized workloads on AWS.
The module assumes that upstream dependencies, namely networking dependencies, are created upstream and the values are passed into this module via mechanisms such as Terraform data source queries.
The module provisions
- ECS Cluster - we are focusing on the Fargate launch type, so we do not provision any underlying EC2 instances for the ECS launch type for the time being.
- Application Load Balancer - default port 80.
- Health Check Service - vanilla HTTP echo service that is used as the default target group for the load balancer. The purpose of the health check service is to ensure that the core infrastructure, networking, security groups, etc. are configured correctly.
- Task execution IAM role - used by downstream services for task execution.
- Tags - the module tags resources for easy reference in the AWS console.
Our approach to ECS Fargate clusters is to provision a cluster and allow downstream services to attach to it via convention based data source queries.
Prerequisites¶
Before using this module, ensure you have the following:
- AWS credentials configured.
- Terraform installed.
- A working knowledge of Terraform.
- Network
Getting Started¶
- Define the Module
Initially, it's essential to define a Terraform module, which is organized as a distinct directory encompassing Terraform configuration files. Within this module directory, input variables and output values must be defined in the variables.tf and outputs.tf files, respectively. The following illustrates an example directory structure:
- Define Input Variables
Inside the variables.tf
or in *.tfvars
file, you should define values for the variables that the module requires.
- Use the Module in Your Main Configuration In your main Terraform configuration file (e.g., main.tf), you can use the module. Specify the source of the module, and version, For Example
- Output Values
Inside the outputs.tf
file of the module, you can define output values that can be referenced in the main configuration. For example:
- Execute Terraform Commands
After defining your main configuration, navigate to the directory containing your Terraform files and run the following commands:
- Review and Confirm
Terraform will display a plan showing the changes it intends to make. Review the plan and confirm by typing 'yes' when prompted.
Requirements¶
Name | Version |
---|---|
terraform | ~> 1.5 |
aws | ~> 5.0 |
Providers¶
No providers.
Modules¶
Name | Source | Version |
---|---|---|
alb | ./modules/alb | n/a |
ecs_cluster | ./modules/ecs_cluster | n/a |
ecs_service | ./modules/ecs_service | n/a |
Resources¶
No resources.
Inputs¶
Name | Description | Type | Default | Required |
---|---|---|---|---|
alb | Configuration settings for the Application Load Balancer (ALB). This includes attributes related to the ALB itself, such as its name, port, protocol, and other optional settings like access logs and tags. | object({ |
n/a | yes |
alb_target_group | List of target groups to create | list(object({ |
n/a | yes |
capacity_provider | Configuration settings for the ECS capacity providers, including the capacity providers used for autoscaling and Fargate. This variable defines the properties of each capacity provider and how they are managed, such as scaling policies and termination protection. | object({ |
n/a | yes |
cidr_blocks | CIDR blocks for security group ingress rules | list(string) |
[ |
no |
ecs_cluster | The ECS-specific values to use such as cluster, service, and repository names. Keys: - cluster_name: The name of the ECS cluster. - cluster_configuration: The execute command configuration for the cluster. - cluster_settings: A list of cluster settings (e.g., container insights). Default is an empty list. - cluster_service_connect_defaults: Configures a default Service Connect namespace. - create_cloudwatch_log_group: Boolean flag to specify whether to create a CloudWatch log group for the ECS cluster. |
object({ |
n/a | yes |
ecs_service | The ECS-specific values to use such as cluster, service, and repository names. | object({ |
n/a | yes |
environment | The environment associated with the ECS service | string |
n/a | yes |
lb | ALB-related information (listening port, deletion protection, security group) | object({ |
n/a | yes |
listener_rules | List of listener rules to create | list(object({ |
n/a | yes |
task | Task-related information (vCPU, memory, # of tasks, port, and health check info.) | object({ |
n/a | yes |
vpc_id | ID of VPC in which all resources need to be created | string |
n/a | yes |
Outputs¶
Name | Description |
---|---|
alb_name | The names of the ALBs. |
ecs_cluster_name | The name of the ECS cluster. |
ecs_service_name | The service names of the ECS services. |
ecs_task_definition_arn | The ARNs of the ECS task definitions. |
Development¶
Versioning¶
while Contributing or doing git commit please specify the breaking change in your commit message whether its major,minor or patch
For Example
Prerequisites¶
Configurations¶
- Configure pre-commit hooks
Tests¶
- Tests are available in
test
directory - Configure the dependencies
- Now execute the test
Authors¶
This project is authored by: - SourceFuse ARC Team