Skip to content

Commit cf7b257

Browse files
committed
Initial Commit
0 parents  commit cf7b257

File tree

8 files changed

+161
-0
lines changed

8 files changed

+161
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.terraform
2+
*.tfstate*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-present HazelOps OÜ https://hazelops.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
@echo "TBD: Linter"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AWS ECS Nginx Terraform Module
2+
3+
TBD

main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
data "aws_region" "current" {}
2+
3+
locals {
4+
secret_names = concat(var.secret_names, [
5+
"PASSWORD"
6+
])
7+
8+
environment = merge(var.environment,
9+
{
10+
ECS_FARGATE = var.ecs_launch_type == "FARGATE" ? "true" : "false"
11+
}
12+
)
13+
14+
container_definition = {
15+
name = var.name
16+
image = "${var.docker_image_name}:${var.docker_image_tag}",
17+
memoryReservation = var.docker_memory_reservation,
18+
essential = true,
19+
resourceRequirements = var.resource_requirements
20+
21+
environment = [for k, v in local.environment : { name = k, value = v }]
22+
secrets = module.ssm.secrets
23+
24+
portMappings = [{
25+
containerPort = var.docker_container_port,
26+
// In case of bridge an host use a dynamic port (0)
27+
hostPort = var.ecs_network_mode == "awsvpc" ? var.docker_container_port : 0
28+
}]
29+
30+
// This is used to make sure the app container has started before starting proxy (for nginx config to be copied to a volume and for port reachibility)
31+
dependsOn = [{
32+
containerName = var.app_name,
33+
condition = "START"
34+
}],
35+
36+
// This is used to map nginx config template from a volume (which can be created by the original app container)
37+
mountPoints = var.enabled ? [
38+
{
39+
sourceVolume = "nginx-templates",
40+
containerPath = "/etc/nginx/templates/"
41+
}
42+
] : []
43+
44+
logConfiguration = var.cloudwatch_log_group == "" ? {
45+
logDriver = "json-file"
46+
options = {}
47+
} : {
48+
logDriver = "awslogs",
49+
options = {
50+
awslogs-group = var.cloudwatch_log_group
51+
awslogs-region = data.aws_region.current.name
52+
awslogs-stream-prefix = var.name
53+
}
54+
}
55+
}
56+
}
57+
58+
module "ssm" {
59+
source = "hazelops/ssm-secrets/aws"
60+
version = "~> 1.0"
61+
env = var.env
62+
app_name = var.app_name
63+
names = var.enabled ? local.secret_names : []
64+
}

output.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "container_definition" {
2+
value = local.container_definition
3+
}

variables.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
variable "env" {
2+
}
3+
4+
variable "name" {
5+
default = "nginx"
6+
}
7+
8+
variable "app_name" {
9+
type = string
10+
}
11+
12+
13+
variable "environment" {
14+
type = map(string)
15+
default = {}
16+
}
17+
18+
variable "secret_names" {
19+
type = list(string)
20+
default = []
21+
}
22+
23+
//variable "ecs_cluster" {
24+
// type = string
25+
//}
26+
27+
variable "docker_image_name" {
28+
type = string
29+
default = "nginx"
30+
}
31+
32+
variable "docker_image_tag" {
33+
type = string
34+
default = "1.19.2-alpine"
35+
}
36+
37+
variable "ecs_launch_type" {
38+
39+
}
40+
41+
variable "cloudwatch_log_group" {
42+
default = ""
43+
}
44+
45+
variable "docker_container_port" {
46+
default = 80
47+
}
48+
49+
variable "ecs_network_mode" {
50+
}
51+
52+
variable "resource_requirements" {
53+
default = []
54+
}
55+
56+
variable "docker_memory_reservation" {
57+
default = 128
58+
}
59+
60+
61+
variable "enabled" {
62+
default = true
63+
}

versions.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = "~> 0.12.0"
3+
}

0 commit comments

Comments
 (0)