Skip to content

Add initial configuration files and tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jobs:
build:
docker:
- image: hashicorp/terraform:0.11.11
environment:
TERRAFORM_VERSION: v0.11
steps:
- checkout
- run:
command: terraform init
test:
docker:
- image: hashicorp/terraform:0.11.11
steps:
- checkout
- run:
command: |
terraform fmt -check=true
terraform validate
go test -v ./...
version: 2
workflows:
build-test:
jobs:
- build
- test:
requires:
- build
version: 2
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf
86 changes: 86 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/gruntwork-io/terratest"
version = "0.14.2"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"

[prune]
go-tests = true
unused-packages = true
145 changes: 145 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
locals {
command = "${jsonencode(var.command)}"
dnsSearchDomains = "${jsonencode(var.dnsSearchDomains)}"
dnsServers = "${jsonencode(var.dnsServers)}"
dockerLabels = "${jsonencode(var.dockerLabels)}"
dockerSecurityOptions = "${jsonencode(var.dockerSecurityOptions)}"
entryPoint = "${jsonencode(var.entryPoint)}"
environment = "${jsonencode(var.environment)}"
extraHosts = "${jsonencode(var.extraHosts)}"

healthCheck = "${
replace(
jsonencode(var.healthCheck),
local.classes["digit"],
"$1"
)
}"

links = "${jsonencode(var.links)}"

linuxParameters = "${
replace(
replace(
replace(
jsonencode(var.linuxParameters),
"/\"1\"/",
"true"
),
"/\"0\"/",
"false"
),
local.classes["digit"],
"$1"
)
}"

logConfiguration = "${jsonencode(var.logConfiguration)}"

mountPoints = "${
replace(
replace(
jsonencode(var.mountPoints),
"/\"1\"/",
"true"
),
"/\"0\"/",
"false"
)
}"

portMappings = "${
replace(
jsonencode(var.portMappings),
local.classes["digit"],
"$1"
)
}"

repositoryCredentials = "${jsonencode(var.repositoryCredentials)}"
resourceRequirements = "${jsonencode(var.resourceRequirements)}"
secrets = "${jsonencode(var.secrets)}"
systemControls = "${jsonencode(var.systemControls)}"

ulimits = "${
replace(
jsonencode(var.ulimits),
local.classes["digit"],
"$1"
)
}"

volumesFrom = "${
replace(
replace(
jsonencode(var.volumesFrom),
"/\"1\"/",
"true"
),
"/\"0\"/",
"false"
)
}"

# re2 ASCII character classes
# https://github.com/google/re2/wiki/Syntax
classes = {
digit = "/\"([[:digit:]]+)\"/"
}

container_definitions = "${replace(data.template_file.container_definitions.rendered, "/\"(null)\"/", "$1")}"
}

data "template_file" "container_definitions" {
template = "${file("${path.module}/templates/container-definitions.json.tmpl")}"

vars = {
command = "${local.command == "[]" ? "null" : local.command}"
cpu = "${var.cpu == 0 ? "null" : var.cpu}"
disableNetworking = "${var.disableNetworking ? true : false}"
dnsSearchDomains = "${local.dnsSearchDomains == "[]" ? "null" : local.dnsSearchDomains}"
dnsServers = "${local.dnsServers == "[]" ? "null" : local.dnsServers}"
dockerLabels = "${local.dockerLabels == "{}" ? "null" : local.dockerLabels}"
dockerSecurityOptions = "${local.dockerSecurityOptions == "[]" ? "null" : local.dockerSecurityOptions}"
entryPoint = "${local.entryPoint == "[]" ? "null" : local.entryPoint}"
environment = "${local.environment == "[]" ? "null" : local.environment}"
essential = "${var.essential ? true : false}"
extraHosts = "${local.extraHosts == "[]" ? "null" : local.extraHosts}"
healthCheck = "${local.healthCheck == "{}" ? "null" : local.healthCheck}"
hostname = "${var.hostname == "" ? "null" : var.hostname}"
image = "${var.image == "" ? "null" : var.image}"
interactive = "${var.interactive ? true : false}"
links = "${local.links == "[]" ? "null" : local.links}"
linuxParameters = "${local.linuxParameters == "{}" ? "null" : local.linuxParameters}"
logConfiguration = "${local.logConfiguration == "{}" ? "null" : local.logConfiguration}"
memory = "${var.memory == 0 ? "null" : var.memory}"
memoryReservation = "${var.memoryReservation == 0 ? "null" : var.memoryReservation}"
mountPoints = "${local.mountPoints == "[]" ? "null" : local.mountPoints}"
name = "${var.name == "" ? "null" : var.name}"
portMappings = "${local.portMappings == "[]" ? "null" : local.portMappings}"
privileged = "${var.privileged ? true : false}"
pseudoTerminal = "${var.pseudoTerminal ? true : false}"
readonlyRootFilesystem = "${var.readonlyRootFilesystem ? true : false}"
repositoryCredentials = "${local.repositoryCredentials == "{}" ? "null" : local.repositoryCredentials}"
resourceRequirements = "${local.resourceRequirements == "[]" ? "null" : local.resourceRequirements}"
secrets = "${local.secrets == "[]" ? "null" : local.secrets}"
systemControls = "${local.systemControls == "[]" ? "null" : local.systemControls}"
ulimits = "${local.ulimits == "[]" ? "null" : local.ulimits}"
user = "${var.user == "" ? "null" : var.user}"
volumesFrom = "${local.volumesFrom == "[]" ? "null" : local.volumesFrom}"
workingDirectory = "${var.workingDirectory == "" ? "null" : var.workingDirectory}"
}
}

resource "aws_ecs_task_definition" "ecs_task_definition" {
container_definitions = "${local.container_definitions}"
execution_role_arn = "${var.execution_role_arn}"
family = "${var.family}"
ipc_mode = "${var.ipc_mode}"
network_mode = "${var.network_mode}"
pid_mode = "${var.pid_mode}"
placement_constraints = "${var.placement_constraints}"
requires_compatibilities = "${var.requires_compatibilities}"
task_role_arn = "${var.task_role_arn}"
volume = "${var.volumes}"
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "container_definitions" {
description = "A list of container definitions in JSON format that describe the different containers that make up your task"
value = "${local.container_definitions}"
}
38 changes: 38 additions & 0 deletions templates/container-definitions.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"command": ${command},
"cpu": ${cpu},
"disableNetworking": ${disableNetworking},
"dnsSearchDomains": ${dnsSearchDomains},
"dnsServers": ${dnsServers},
"dockerLabels": ${dockerLabels},
"dockerSecurityOptions": ${dockerSecurityOptions},
"entryPoint": ${entryPoint},
"environment": ${environment},
"essential": ${essential},
"extraHosts": ${extraHosts},
"healthCheck": ${healthCheck},
"hostname": "${hostname}",
"image": "${image}",
"interactive": ${interactive},
"links": ${links},
"linuxParameters": ${linuxParameters},
"logConfiguration": ${logConfiguration},
"memory": ${memory},
"memoryReservation": ${memoryReservation},
"mountPoints": ${mountPoints},
"name": "${name}",
"portMappings": ${portMappings},
"privileged": ${privileged},
"pseudoTerminal": ${pseudoTerminal},
"readonlyRootFilesystem": ${readonlyRootFilesystem},
"repositoryCredentials": ${repositoryCredentials},
"resourceRequirements": ${resourceRequirements},
"secrets": ${secrets},
"systemControls": ${systemControls},
"ulimits": ${ulimits},
"user": "${user}",
"volumesFrom": ${volumesFrom},
"workingDirectory": "${workingDirectory}"
}
]
Loading