From 6a832447b7b21afa79a52d18e79764efcb3d477c Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Thu, 7 May 2020 22:50:54 +0200 Subject: [PATCH] Initial --- .gitignore | 2 ++ LICENSE | 21 ++++++++++++++++++ Makefile | 2 ++ README.md | 3 +++ main.tf | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ output.tf | 3 +++ variables.tf | 50 ++++++++++++++++++++++++++++++++++++++++++ versions.tf | 3 +++ 8 files changed, 146 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 main.tf create mode 100644 output.tf create mode 100644 variables.tf create mode 100644 versions.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e9c81c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.terraform +*.tfstate* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..963d300 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1a1ec0c --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test: + @echo "TBD: Linter" diff --git a/README.md b/README.md new file mode 100644 index 0000000..297fdde --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# AWS ECS Cloud9 IDE Terraform Module + +TBD diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a35c0ea --- /dev/null +++ b/main.tf @@ -0,0 +1,62 @@ +data "aws_region" "current" {} + +locals { + secret_names = concat(var.secret_names, [ + ]) + + environment = merge(var.environment, + { + PUID: "1000" + PGID: "1000" + TZ: "America/Los_Angeles" + USERNAME: "admin" + PASSWORD: "Vr4KqHBgjLMMk92fsMkLd^ibHCJsy" +// ECS_FARGATE = var.ecs_launch_type == "FARGATE" ? "true" : "false" + } + ) + + container_definition = { + name = var.name + image = "${var.docker_image_name}:${var.docker_image_tag}", + memoryReservation = 128, + essential = true, + + 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 dynamid port (0) + hostPort = var.ecs_network_mode == "awsvpc" ? var.docker_container_port : 0 + }] + + volumeMappings = var.ecs_launch_type == "FARGATE" ? [] : [ + { + containerVolume = "/var/run/docker.sock", + hostVolume = "/var/run/docker.sock" + } + ], + + + +// logConfiguration = var.cloudwatch_log_group == "" ? { +// logDriver = "json-file" +// } : { +// logDriver = "awslogs", +// options = { +// awslogs-group = var.cloudwatch_log_group +// awslogs-region = data.aws_region.current.name +// awslogs-stream-prefix = var.name +// } +// } + } + + +} + +module "ssm" { + source = "../ssm-secrets" + env = var.env + app_name = var.app_name + names = local.secret_names +} diff --git a/output.tf b/output.tf new file mode 100644 index 0000000..148b804 --- /dev/null +++ b/output.tf @@ -0,0 +1,3 @@ +output "container_definition" { + value = local.container_definition +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..cf70c77 --- /dev/null +++ b/variables.tf @@ -0,0 +1,50 @@ +variable "env" { +} + +variable "name" { + default = "cloud9" +} + +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 = "linuxserver/cloud9" +} + +variable "docker_image_tag" { + type = string + default = "latest" +} + +variable "ecs_launch_type" { + +} + +variable "cloudwatch_log_group" { + default = "" +} + +variable "docker_container_port" { + default = 8000 +} + +variable "ecs_network_mode" { +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..7000b05 --- /dev/null +++ b/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = "~> 0.12.0" +}