-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cf7b257
Showing
8 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.terraform | ||
*.tfstate* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020-present HazelOps OÜ https://hazelops.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test: | ||
@echo "TBD: Linter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# AWS ECS Nginx Terraform Module | ||
|
||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
data "aws_region" "current" {} | ||
|
||
locals { | ||
secret_names = concat(var.secret_names, [ | ||
"PASSWORD" | ||
]) | ||
|
||
environment = merge(var.environment, | ||
{ | ||
ECS_FARGATE = var.ecs_launch_type == "FARGATE" ? "true" : "false" | ||
} | ||
) | ||
|
||
container_definition = { | ||
name = var.name | ||
image = "${var.docker_image_name}:${var.docker_image_tag}", | ||
memoryReservation = var.docker_memory_reservation, | ||
essential = true, | ||
resourceRequirements = var.resource_requirements | ||
|
||
environment = [for k, v in local.environment : { name = k, value = v }] | ||
secrets = module.ssm.secrets | ||
|
||
portMappings = [{ | ||
containerPort = var.docker_container_port, | ||
// In case of bridge an host use a dynamic port (0) | ||
hostPort = var.ecs_network_mode == "awsvpc" ? var.docker_container_port : 0 | ||
}] | ||
|
||
// 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) | ||
dependsOn = [{ | ||
containerName = var.app_name, | ||
condition = "START" | ||
}], | ||
|
||
// This is used to map nginx config template from a volume (which can be created by the original app container) | ||
mountPoints = var.enabled ? [ | ||
{ | ||
sourceVolume = "nginx-templates", | ||
containerPath = "/etc/nginx/templates/" | ||
} | ||
] : [] | ||
|
||
logConfiguration = var.cloudwatch_log_group == "" ? { | ||
logDriver = "json-file" | ||
options = {} | ||
} : { | ||
logDriver = "awslogs", | ||
options = { | ||
awslogs-group = var.cloudwatch_log_group | ||
awslogs-region = data.aws_region.current.name | ||
awslogs-stream-prefix = var.name | ||
} | ||
} | ||
} | ||
} | ||
|
||
module "ssm" { | ||
source = "hazelops/ssm-secrets/aws" | ||
version = "~> 1.0" | ||
env = var.env | ||
app_name = var.app_name | ||
names = var.enabled ? local.secret_names : [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "container_definition" { | ||
value = local.container_definition | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
variable "env" { | ||
} | ||
|
||
variable "name" { | ||
default = "nginx" | ||
} | ||
|
||
variable "app_name" { | ||
type = string | ||
} | ||
|
||
|
||
variable "environment" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "secret_names" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
//variable "ecs_cluster" { | ||
// type = string | ||
//} | ||
|
||
variable "docker_image_name" { | ||
type = string | ||
default = "nginx" | ||
} | ||
|
||
variable "docker_image_tag" { | ||
type = string | ||
default = "1.19.2-alpine" | ||
} | ||
|
||
variable "ecs_launch_type" { | ||
|
||
} | ||
|
||
variable "cloudwatch_log_group" { | ||
default = "" | ||
} | ||
|
||
variable "docker_container_port" { | ||
default = 80 | ||
} | ||
|
||
variable "ecs_network_mode" { | ||
} | ||
|
||
variable "resource_requirements" { | ||
default = [] | ||
} | ||
|
||
variable "docker_memory_reservation" { | ||
default = 128 | ||
} | ||
|
||
|
||
variable "enabled" { | ||
default = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
required_version = "~> 0.12.0" | ||
} |
cf7b257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ability to run nginx as a sidecar