Skip to content

Commit 29bd9f7

Browse files
JonRomaddriddle
authored andcommitted
Migrate to Terraform 0.12 (techservicesillinois#34)
1 parent 346d66e commit 29bd9f7

22 files changed

+815
-419
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.swp
2+
3+
terraform.tfstate
4+
terraform.tfstate.*
5+
6+
.terraform
7+
.terragrunt-cache

.drone.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pipeline:
2+
build:
3+
image: hashicorp/terraform
4+
commands:
5+
- apk add make
6+
- make tfc
7+
linter:
8+
image: python:3
9+
commands:
10+
- pip3 install --extra-index-url https://pip-test.techservices.illinois.edu/index/test tflint
11+
- make test

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
#Pipenv files
2-
Pipfile
1+
*.swp
2+
3+
terraform.tfstate
4+
terraform.tfstate.*
5+
6+
.terraform
7+
.terragrunt-cache

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM hashicorp/terraform
2+
3+
RUN apk add make
4+
5+
WORKDIR /tmp
6+
COPY . /tmp
7+
8+
ENTRYPOINT [ "/usr/bin/make", "tfc" ]
9+
10+
FROM python:3
11+
12+
RUN pip3 install --extra-index-url https://pip-test.techservices.illinois.edu/index/test tflint
13+
14+
WORKDIR /tmp
15+
COPY . /tmp
16+
17+
ENTRYPOINT [ "/usr/bin/make", "test" ]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 by the Board of Trustees of the University of Illinois.
3+
Copyright (c) 2019 by the Board of Trustees of the University of Illinois.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.PHONY: test tfc clean docker sh shell
2+
3+
REPO := $(shell basename $(shell git remote get-url origin) .git)
4+
5+
GOPTS := -lR . -e
6+
GREP := grep $(GOPTS)
7+
EGREP := egrep $(GOPTS)
8+
SRCS := --include=*.tf
9+
DOCS := --include=README.md
10+
11+
all: tfc test
12+
13+
tfc: .terraform
14+
@# Basic Terraform validation and formating checks
15+
terraform version
16+
AWS_DEFAULT_REGION=us-east-2 terraform validate
17+
terraform fmt -check
18+
19+
# Create .terraform if does not exist
20+
# A terraform init is requried to run a validate :-(
21+
.terraform:
22+
terraform init -backend=false
23+
terraform version
24+
25+
test:
26+
@####################################################
27+
! $(EGREP) "TF-UPGRADE-TODO|cites-illinois|as-aws-modules" $(SRCS) $(DOCS)
28+
# Do NOT put terraform-aws in the title of the top-level README
29+
! grep "#\s*terraform-aws-" README.md
30+
# Do NOT use type string when you can use type number or bool!
31+
! $(EGREP) '"\d+"|"true"|"false"' $(SRCS) $(DOCS)
32+
# Do NOT use old style maps in docs
33+
! $(EGREP) "\w+\s*\{" $(DOCS)
34+
# Do NOT drop the "s" in outputs.tf or variables.tf!
35+
! find . -name output.tf -o -name variable.tf | grep '.*'
36+
# Do NOT define an output in files other than outputs.tf
37+
! $(EGREP) 'output\s+"\w+"\s*\{' $(SRCS) --exclude=outputs.tf
38+
# Do NOT define a variable in files other than variables.tf
39+
! $(EGREP) 'variable\s+"\w+"\s*\{' $(SRCS) --exclude=variables.tf
40+
# DO put a badge in top-level README.md
41+
grep -q "\[\!\[Build Status\]([^)]*$(REPO)/status.svg)\]([^)]*$(REPO))" README.md
42+
# Do NOT split a source line over more than one line
43+
! $(GREP) 'source\s*=\s*$$' $(SRCS) $(DOCS)
44+
# Do NOT use ?ref= in source lines in a README.md!
45+
! $(GREP) 'source\s*=.*?ref=' $(DOCS)
46+
# Do NOT start a source line with git::
47+
! $(GREP) 'source\s*=\s*"git::' $(SRCS) $(DOCS)
48+
# Do NOT use .git in a source line
49+
! $(GREP) 'source\s*=.*\.git.*"' $(SRCS) $(DOCS)
50+
# Do NOT use double slashes with top-level modules
51+
! $(GREP) 'source\s*=.*//?ref=.*"' $(SRCS) $(DOCS)
52+
# Do NOT leave extra whitespace at the end of a line
53+
! $(EGREP) '\s+$$' $(SRCS)
54+
# Do NOT leave empty lines at the start or end of a file
55+
! find . -type f -name "*.tf" -exec sh -c "awk 'NR==1; END{print}' {} | egrep -q '^\s*$$' && echo {}" \; | grep '.*'
56+
@# Run tflint if it is installed
57+
@if which tflint >/dev/null; then tflint ; fi
58+
59+
# Launches the Makefile inside a container
60+
docker:
61+
docker build . -t test/$(REPO)
62+
docker run --rm test/$(REPO)
63+
64+
# Create alias
65+
sh: shell
66+
67+
# Launches the shell inside a container for debugging the Makefile
68+
shell:
69+
docker build . -t test/$(REPO)
70+
docker run -it --rm --entrypoint=sh test/$(REPO)
71+
72+
clean:
73+
-rm -rf .terraform
74+
-docker rmi -f test/$(REPO) >/dev/null 2>&1

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ecs-service
22

3+
[![Build Status](https://drone.techservices.illinois.edu/api/badges/techservicesillinois/terraform-aws-ecs-service/status.svg)](https://drone.techservices.illinois.edu/techservicesillinois/terraform-aws-ecs-service)
4+
35
Provides an ECS service - effectively a task that is expected to
46
run until an error occurs or a user terminates it (typically a
57
webserver or a database). This module's primary intent is to make
@@ -57,21 +59,21 @@ module "service_name" {
5759
5860
name = "service_name"
5961
60-
load_balancer {
62+
load_balancer = {
6163
name = "load_balancer_name"
6264
port = 443
6365
container_name = "main_container_name"
6466
container_port = 8080
6567
host_header = "myservice.example.com"
6668
}
6769
68-
alias {
70+
alias = {
6971
domain = "example.com"
7072
hostname = "myservice"
7173
}
7274
73-
network_configuration {
74-
assign_public_ip = "true"
75+
network_configuration = {
76+
assign_public_ip = true
7577
tier = "public"
7678
vpc = "my-vpc"
7779
}
@@ -85,11 +87,11 @@ module "service_name" {
8587
8688
name = "service_name"
8789
88-
service_discovery {
90+
service_discovery = {
8991
namespace_id = "ns-cxn6fqejoygbxan5"
9092
}
9193
92-
network_configuration {
94+
network_configuration = {
9395
tier = "nat"
9496
vpc = "my-vpc"
9597
}
@@ -105,20 +107,20 @@ module "service_name" {
105107
name = "service_name"
106108
launch_type = "EC2"
107109
108-
load_balancer {
110+
load_balancer = {
109111
name = "load_balancer_name"
110112
port = 443
111113
container_name = "main_container_name"
112114
container_port = 8080
113115
host_header = "myservice.example.com"
114116
}
115117
116-
alias {
118+
alias = {
117119
domain = "example.com"
118120
hostname = "myservice"
119121
}
120122
121-
task_definition {
123+
task_definition = {
122124
network_mode = "bridge"
123125
}
124126
}
@@ -136,15 +138,15 @@ module "service_name" {
136138
task_definition_arn = "task_definition_name:revision"
137139
desired_count = 3
138140
139-
load_balancer {
141+
load_balancer = {
140142
name = "load_balancer_name"
141143
port = 443
142144
container_name = "main_container_name"
143145
container_port = 8080
144146
host_header = "myservice.example.com"
145147
}
146148
147-
alias {
149+
alias = {
148150
domain = "example.com"
149151
hostname = "myservice"
150152
}
@@ -166,28 +168,28 @@ module "service_name" {
166168
```
167169
### Configure autoscaling policy and cloudwatch alarms for ECS service
168170
```hcl
169-
autoscale {
170-
autoscale_max_capacity = "5"
171+
autoscale = {
172+
autoscale_max_capacity = 5
171173
metric_name = "CPUUtilization"
172-
datapoints_to_alarm = "1"
173-
evaluation_periods = "1"
174-
period = "60"
175-
cooldown = "60"
174+
datapoints_to_alarm = 1
175+
evaluation_periods = 1
176+
period = 60
177+
cooldown = 60
176178
adjustment_type = "ChangeInCapacity"
177179
178180
### Cloudwatch Alaram Scale up and Scale down ###
179-
scale_up_threshold = "70"
180-
scale_down_threshold = "40"
181+
scale_up_threshold = 70
182+
scale_down_threshold = 40
181183
182184
### AutoScale Policy Scale up ###
183185
scale_up_comparison_operator = "GreaterThanOrEqualToThreshold"
184-
scale_up_interval_lower_bound = "1"
185-
scale_up_adjustment = "1"
186+
scale_up_interval_lower_bound = 1
187+
scale_up_adjustment = 1
186188
187189
### AutoScale Policy Scale down ###
188190
scale_down_comparison_operator = "LessThanThreshold"
189-
scale_down_interval_lower_bound = "0"
190-
scale_down_adjustment = "-1"
191+
scale_down_interval_lower_bound = 0
192+
scale_down_adjustment = -1
191193
192194
}
193195
```

0 commit comments

Comments
 (0)