Skip to content

Commit

Permalink
Refactor examples to work with provider 4.0.0+ (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul Wahid authored Mar 11, 2022
1 parent 466529d commit 88dfdde
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.1.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
Expand All @@ -18,7 +18,7 @@ repos:
args: ['--allow-missing-credentials']
- id: trailing-whitespace
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.61.0
rev: v1.64.0
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]

- fix: setting task_health_command to null
- fix: setting `task_health_command` to null ([#49](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/49))


<a name="6.4.1"></a>
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- markdownlint-disable MD041 -->
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/umotif-public/terraform-aws-ecs-fargate?style=social)](https://github.com/umotif-public/terraform-aws-ecs-fargate/releases/latest)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/umotif-public/terraform-aws-ecs-fargate)](https://github.com/umotif-public/terraform-aws-ecs-fargate/releases/latest)

# Terraform AWS ECS Fargate

Expand All @@ -17,16 +16,20 @@ Terraform 0.13. Pin module version to `~> v6.0`. Submit pull-requests to `master
resource "aws_ecs_cluster" "cluster" {
name = "example-ecs-cluster"
setting {
name = "containerInsights"
value = "disabled"
}
}
resource "aws_ecs_cluster_capacity_providers" "cluster" {
cluster_name = aws_ecs_cluster.cluster.name
capacity_providers = ["FARGATE_SPOT", "FARGATE"]
default_capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
}
setting {
name = "containerInsights"
value = "disabled"
}
}
module "ecs-fargate" {
Expand Down Expand Up @@ -81,7 +84,7 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.34 |

## Providers
Expand Down
15 changes: 7 additions & 8 deletions examples/core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ data "aws_vpc" "default" {
default = true
}

data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

#####
Expand All @@ -24,7 +27,7 @@ module "alb" {
load_balancer_type = "application"
internal = false
vpc_id = data.aws_vpc.default.id
subnets = data.aws_subnet_ids.all.ids
subnets = data.aws_subnets.all.ids
}

resource "aws_lb_listener" "alb_80" {
Expand Down Expand Up @@ -87,7 +90,7 @@ module "fargate" {
# sg_name_prefix = "my-security-group-name" # uncomment if you want to name security group with specific name

vpc_id = data.aws_vpc.default.id
private_subnet_ids = data.aws_subnet_ids.all.ids
private_subnet_ids = data.aws_subnets.all.ids
cluster_id = aws_ecs_cluster.cluster.id

wait_for_steady_state = true
Expand All @@ -108,10 +111,6 @@ module "fargate" {
}
]

task_health_check = {
timeout = 60
}

health_check = {
port = "traffic-port"
path = "/"
Expand Down
27 changes: 17 additions & 10 deletions examples/fargate-efs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ data "aws_vpc" "default" {
default = true
}

data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

#####
Expand All @@ -24,7 +27,7 @@ module "alb" {
load_balancer_type = "application"
internal = false
vpc_id = data.aws_vpc.default.id
subnets = data.aws_subnet_ids.all.ids
subnets = data.aws_subnets.all.ids
}

resource "aws_lb_listener" "alb_80" {
Expand Down Expand Up @@ -75,25 +78,29 @@ resource "aws_efs_file_system" "efs" {
# ECS cluster and fargate
#####
resource "aws_ecs_cluster" "cluster" {
name = "ecs-spot-test"
name = "ecs-spot-test"
setting {
name = "containerInsights"
value = "disabled"
}
}

resource "aws_ecs_cluster_capacity_providers" "cluster" {
cluster_name = aws_ecs_cluster.cluster.name

capacity_providers = ["FARGATE_SPOT", "FARGATE"]

default_capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
}

setting {
name = "containerInsights"
value = "disabled"
}
}

module "fargate" {
source = "../../"

name_prefix = "ecs-fargate-example"
vpc_id = data.aws_vpc.default.id
private_subnet_ids = data.aws_subnet_ids.all.ids
private_subnet_ids = data.aws_subnets.all.ids
cluster_id = aws_ecs_cluster.cluster.id

platform_version = "1.4.0"
Expand Down
28 changes: 18 additions & 10 deletions examples/fargate-spot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ data "aws_vpc" "default" {
default = true
}

data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

#####
Expand All @@ -24,7 +27,7 @@ module "alb" {
load_balancer_type = "application"
internal = false
vpc_id = data.aws_vpc.default.id
subnets = data.aws_subnet_ids.all.ids
subnets = data.aws_subnets.all.ids
}

resource "aws_lb_listener" "alb_80" {
Expand Down Expand Up @@ -64,25 +67,30 @@ resource "aws_security_group_rule" "task_ingress_80" {
# ECS cluster and fargate
#####
resource "aws_ecs_cluster" "cluster" {
name = "ecs-spot-test"
capacity_providers = ["FARGATE_SPOT", "FARGATE"]

default_capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
}
name = "ecs-spot-test"

setting {
name = "containerInsights"
value = "disabled"
}
}

resource "aws_ecs_cluster_capacity_providers" "cluster" {
cluster_name = aws_ecs_cluster.cluster.name

capacity_providers = ["FARGATE_SPOT", "FARGATE"]

default_capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
}
}

module "fargate" {
source = "../../"

name_prefix = "ecs-fargate-example"
vpc_id = data.aws_vpc.default.id
private_subnet_ids = data.aws_subnet_ids.all.ids
private_subnet_ids = data.aws_subnets.all.ids

cluster_id = aws_ecs_cluster.cluster.id

Expand Down
13 changes: 8 additions & 5 deletions examples/multiple-target-groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ data "aws_vpc" "default" {
default = true
}

data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

#####
Expand All @@ -24,7 +27,7 @@ module "external-alb" {
load_balancer_type = "application"
internal = false
vpc_id = data.aws_vpc.default.id
subnets = data.aws_subnet_ids.all.ids
subnets = data.aws_subnets.all.ids
}

resource "aws_lb_listener" "external_alb_80" {
Expand All @@ -46,7 +49,7 @@ module "internal-alb" {
load_balancer_type = "application"
internal = false
vpc_id = data.aws_vpc.default.id
subnets = data.aws_subnet_ids.all.ids
subnets = data.aws_subnets.all.ids
}

resource "aws_lb_listener" "internal_alb_80" {
Expand Down Expand Up @@ -128,7 +131,7 @@ module "fargate" {
# sg_name_prefix = "my-security-group-name" # uncomment if you want to name security group with specific name

vpc_id = data.aws_vpc.default.id
private_subnet_ids = data.aws_subnet_ids.all.ids
private_subnet_ids = data.aws_subnets.all.ids
cluster_id = aws_ecs_cluster.cluster.id
target_groups = [
{
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 0.13.7"

required_providers {
aws = ">= 3.34"
Expand Down

0 comments on commit 88dfdde

Please sign in to comment.