Skip to content

Commit ff7c478

Browse files
update complete example
1 parent 33027a5 commit ff7c478

File tree

6 files changed

+212
-1
lines changed

6 files changed

+212
-1
lines changed

.github/workflows/linter.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,20 @@ jobs:
3333

3434
- name: terraform validate
3535
run: terraform validate
36+
37+
tflint:
38+
name: "tflint"
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: actions/cache@v2
43+
name: Cache tflint plugin dir
44+
with:
45+
path: ~/.tflint.d/plugins
46+
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
47+
- uses: terraform-linters/setup-tflint@v1
48+
name: Setup TFLint
49+
- name: Init TFLint
50+
run: tflint --init --config tflint.hcl
51+
- name: Run TFLint
52+
run: tflint -f compact --config tflint.hcl

examples/basic/locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,3 @@ data "aws_subnets" "private" {
8383
data "aws_ecs_cluster" "this" {
8484
cluster_name = local.cluster_name
8585
}
86-
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "AccessSecretsWithTag",
6+
"Effect": "Allow",
7+
"Action": [
8+
"ssm:GetParameters"
9+
],
10+
"Resource": [
11+
"*"
12+
],
13+
"Condition": {
14+
"StringEquals": {
15+
"ssm:ResourceTag/env": "${env}"
16+
}
17+
}
18+
},
19+
{
20+
"Sid": "SSMExecAccess",
21+
"Effect": "Allow",
22+
"Action": [
23+
"ssmmessages:CreateControlChannel",
24+
"ssmmessages:CreateDataChannel",
25+
"ssmmessages:OpenControlChannel",
26+
"ssmmessages:OpenDataChannel"
27+
],
28+
"Resource": [
29+
"*"
30+
]
31+
}
32+
]
33+
}

examples/complete/locals.tf

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
locals {
2+
name = "example-ecs"
3+
env = "sandbox"
4+
tags = {
5+
Stack = "ecs-services"
6+
GithubRepo = "terraform-aws-ecs"
7+
GithubOrg = "terraform-module"
8+
}
9+
10+
private_subnets = data.aws_subnets.private.ids
11+
public_subnets = data.aws_subnets.public.ids
12+
cluster_id = data.aws_ecs_cluster.this.id
13+
cluster_name = var.name
14+
15+
proxy = {
16+
name = "proxy"
17+
create = true
18+
create_log_group = true
19+
description = "Public proxy service"
20+
visibility = "public"
21+
exposed_port = 80
22+
health_check = {
23+
path = "/healtz"
24+
}
25+
lb_condition_rule = {
26+
host_headers = ["*.${local.env}"]
27+
}
28+
min_capacity = 1
29+
max_capacity = 2 // Will scale out up to 2 replicas
30+
desired_count = 1
31+
cpu = 256
32+
memory = 512
33+
tags = { service = "proxy", visibility = "public" }
34+
container_definitions = [{
35+
name = "proxy"
36+
image = "cloudkats/hello-world-rest:61fe8342"
37+
essential = true
38+
environment = [
39+
{ name : "APP_NAME", value : "proxy" },
40+
{ name : "APP_VISIBILITY", value : "private" },
41+
]
42+
linuxParameters : {
43+
initProcessEnabled : true
44+
},
45+
healthCheck : {
46+
command : [
47+
"CMD-SHELL",
48+
"curl -f http://localhost:80/healthz || exit 1"
49+
],
50+
retries : 3,
51+
timeout : 5,
52+
interval : 10,
53+
startPeriod : 10
54+
},
55+
portMappings = [{
56+
protocol = "tcp"
57+
containerPort = 80
58+
hostPort = 80
59+
}]
60+
secrets = [],
61+
logConfiguration = {
62+
logDriver = "awslogs"
63+
options = {
64+
awslogs-group = "/ecs/proxy-dev-task"
65+
awslogs-stream-prefix = "proxy"
66+
awslogs-region = "us-west-2"
67+
}
68+
}
69+
}]
70+
}
71+
}
72+
73+
data "aws_subnets" "private" {
74+
filter {
75+
name = "vpc-id"
76+
values = [var.vpc_id]
77+
}
78+
filter {
79+
name = "tag:Visibility"
80+
values = ["private"]
81+
}
82+
}
83+
84+
data "aws_ecs_cluster" "this" {
85+
cluster_name = local.cluster_name
86+
}

examples/complete/main.tf

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
################################################################################
2+
# ECS Resources
3+
################################################################################
4+
module "ecs" {
5+
source = "terraform-module/ecs/aws"
6+
version = "~> 1"
7+
8+
name = var.name
9+
10+
container_insights = false
11+
capacity_providers = ["FARGATE_SPOT"]
12+
13+
default_capacity_provider_strategy = [
14+
{
15+
capacity_provider = "FARGATE_SPOT"
16+
}
17+
]
18+
19+
tags = merge({ Module = "terraform-module/ecs/aws" })
20+
}
21+
22+
################################################################################
23+
# LB Resources
24+
################################################################################
25+
resource "aws_lb" "this" {
26+
name = "${var.name}-alb"
27+
internal = false
28+
29+
load_balancer_type = "application"
30+
security_groups = [aws_security_group.alb.id]
31+
subnets = local.public_subnets
32+
enable_http2 = "true"
33+
34+
enable_cross_zone_load_balancing = true
35+
enable_deletion_protection = false
36+
tags = { Service = "alb", AlbType = "application" }
37+
}
38+
39+
resource "aws_security_group" "alb" {
40+
name = "${var.name}-sg-alb-${var.env}"
41+
vpc_id = var.vpc_id
42+
43+
ingress {
44+
protocol = "tcp"
45+
from_port = 80
46+
to_port = 80
47+
cidr_blocks = ["0.0.0.0/0"]
48+
description = "Allow internet to access port 80 for redirect."
49+
}
50+
51+
ingress {
52+
protocol = "tcp"
53+
from_port = 443
54+
to_port = 443
55+
cidr_blocks = ["0.0.0.0/0"]
56+
description = "Allow internet to communicate with services over HTTPS."
57+
}
58+
59+
egress {
60+
# TEMP for testing, should be locked to just services protocols
61+
protocol = "-1"
62+
from_port = 0
63+
to_port = 0
64+
cidr_blocks = ["0.0.0.0/0"] # TODO: make sure only vpc cidr or private sunets cidrs
65+
description = "Allow internal communitcations."
66+
}
67+
}

examples/complete/vars.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "name" {
2+
description = "Project Name"
3+
type = string
4+
}
5+
6+
variable "vpc_id" {
7+
description = "VPC id where to deploy platform."
8+
type = string
9+
}

0 commit comments

Comments
 (0)