diff --git a/.travis.yml b/.travis.yml index 13e6ce0..05d13ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,10 @@ language: bash dist: xenial -addons: - snaps: - - terraform +before_install: + - curl -sLo /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip + - unzip /tmp/terraform.zip -d /tmp + - sudo mv /tmp/terraform /usr/local/bin/ env: - AWS_REGION=us-east-1 diff --git a/README.md b/README.md index 5cb1dee..523a25e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ You can literally copy and paste the following example, change the following att ```hcl # include this module and enter the values of input variables module "ecs-gitlab" { - source = "github.com/riboseinc/terraform-aws-ecs-gitlab" + source = "riboseinc/ecs-gitlab/aws" gitlab_domain = "gitlab.example.com" prefix = "ribose" aws_ecs_cluster_id = "arn:..." @@ -49,11 +49,11 @@ module "ecs-gitlab" { certificate_arn = "arn:..." } -output "Root Password" { - value = "${module.ecs-gitlab.gitlab_root_password}" +output "Root_Password" { + value = module.ecs-gitlab.gitlab_root_password } -output "Gitlab Address" { - value = "${module.ecs-gitlab.gitlab_web_endpoint}" +output "Gitlab_Address" { + value = module.ecs-gitlab.gitlab_web_endpoint } ``` diff --git a/main.tf b/main.tf index a885e0f..4d7cd5b 100644 --- a/main.tf +++ b/main.tf @@ -1,25 +1,12 @@ terraform { - required_version = "~> 0.11" -} - -provider "aws" { - version = "~> 1.56" -} - -provider "local" { - version = "~> 1.1" -} - -provider "random" { - version = "~> 2.0" -} - -provider "template" { - version = "~> 2.0" -} - -provider "tls" { - version = "~> 1.2" + required_version = ">= 0.12" + required_providers { + aws = "~> 2.16" + local = "~> 1.2" + random = "~> 2.1" + template = "~> 2.1" + tls = "~> 2.0" + } } data "aws_region" "current" {} diff --git a/resource-ec2.tf b/resource-ec2.tf index b6dc092..1ad817e 100644 --- a/resource-ec2.tf +++ b/resource-ec2.tf @@ -1,4 +1,4 @@ resource "aws_key_pair" "runners" { key_name_prefix = "${var.prefix}-runners" - public_key = "${tls_private_key.runners-ssh.public_key_openssh}" + public_key = tls_private_key.runners-ssh.public_key_openssh } diff --git a/resource-ecs.tf b/resource-ecs.tf index 129d7ee..2186bd6 100644 --- a/resource-ecs.tf +++ b/resource-ecs.tf @@ -5,7 +5,7 @@ resource "random_string" "gitlab_root_password" { number = true keepers = { - rds_id = "${aws_db_instance.main.id}" + rds_id = aws_db_instance.main.id } } @@ -25,8 +25,8 @@ resource "aws_ecs_task_definition" "gitlab" { family = "gitlab-${random_id.ecs_id.hex}" requires_compatibilities = ["EC2"] network_mode = "bridge" - task_role_arn = "${aws_iam_role.ecs_task.arn}" - execution_role_arn = "${aws_iam_role.ecs_task.arn}" + task_role_arn = aws_iam_role.ecs_task.arn + execution_role_arn = aws_iam_role.ecs_task.arn cpu = 2048 memory = 4096 @@ -196,20 +196,21 @@ resource "aws_ecs_task_definition" "gitlab" { ] } ] - EOF +EOF + volume { name = "gitlab-${random_id.ecs_id.hex}-server-data" docker_volume_configuration { autoprovision = true - scope = "shared" - driver = "local" + scope = "shared" + driver = "local" - driver_opts { - type = "nfs" + driver_opts = { + type = "nfs" device = "${aws_efs_file_system.gitlab.dns_name}:/server/data" - o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" + o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" } } } @@ -219,13 +220,13 @@ resource "aws_ecs_task_definition" "gitlab" { docker_volume_configuration { autoprovision = true - scope = "shared" - driver = "local" + scope = "shared" + driver = "local" - driver_opts { - type = "nfs" + driver_opts = { + type = "nfs" device = "${aws_efs_file_system.gitlab.dns_name}:/server/config" - o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" + o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" } } } @@ -235,13 +236,13 @@ resource "aws_ecs_task_definition" "gitlab" { docker_volume_configuration { autoprovision = true - scope = "shared" - driver = "local" + scope = "shared" + driver = "local" - driver_opts { - type = "nfs" + driver_opts = { + type = "nfs" device = "${aws_efs_file_system.gitlab.dns_name}:/runner" - o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" + o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" } } } @@ -251,35 +252,35 @@ resource "aws_ecs_task_definition" "gitlab" { docker_volume_configuration { autoprovision = true - scope = "shared" - driver = "local" + scope = "shared" + driver = "local" - driver_opts { - type = "nfs" + driver_opts = { + type = "nfs" device = "${aws_efs_file_system.gitlab.dns_name}:/" - o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" + o = "addr=${aws_efs_file_system.gitlab.dns_name},nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" } } } } resource "aws_ecs_service" "gitlab" { - name = "${var.prefix}-gitlab-${random_id.ecs_id.hex}" - cluster = "${var.aws_ecs_cluster_id}" - task_definition = "${aws_ecs_task_definition.gitlab.arn}" - desired_count = 1 - launch_type = "EC2" - iam_role = "${aws_iam_role.ecs_service.arn}" + name = "${var.prefix}-gitlab-${random_id.ecs_id.hex}" + cluster = var.aws_ecs_cluster_id + task_definition = aws_ecs_task_definition.gitlab.arn + desired_count = 1 + launch_type = "EC2" + iam_role = aws_iam_role.ecs_service.arn deployment_minimum_healthy_percent = 0 - deployment_maximum_percent = 100 + deployment_maximum_percent = 100 load_balancer { - target_group_arn = "${aws_lb_target_group.http.arn}" - container_name = "gitlab-server" - container_port = 80 + target_group_arn = aws_lb_target_group.http.arn + container_name = "gitlab-server" + container_port = 80 } } output "gitlab_root_password" { - value = "${random_string.gitlab_root_password.result}" + value = random_string.gitlab_root_password.result } diff --git a/resource-efs.tf b/resource-efs.tf index 932a270..1327987 100644 --- a/resource-efs.tf +++ b/resource-efs.tf @@ -1,14 +1,14 @@ resource "aws_efs_file_system" "gitlab" { - creation_token = "${var.prefix}" + creation_token = var.prefix } resource "aws_efs_mount_target" "gitlab" { - count = "${length(var.subnets)}" - file_system_id = "${aws_efs_file_system.gitlab.id}" - subnet_id = "${var.subnets[count.index]}" + count = length(var.subnets) + file_system_id = aws_efs_file_system.gitlab.id + subnet_id = var.subnets[count.index] security_groups = [ - "${aws_security_group.allow_all_egress.id}", - "${aws_security_group.allow_all_subnets_vpc.id}", + aws_security_group.allow_all_egress.id, + aws_security_group.allow_all_subnets_vpc.id, ] } diff --git a/resource-elasticache.tf b/resource-elasticache.tf index 894ab3a..0ff7185 100644 --- a/resource-elasticache.tf +++ b/resource-elasticache.tf @@ -1,19 +1,19 @@ resource "aws_elasticache_subnet_group" "main" { - name = "${var.prefix}" - subnet_ids = ["${var.subnets}"] + name = var.prefix + subnet_ids = var.subnets } resource "aws_elasticache_cluster" "main" { engine = "redis" - engine_version = "${var.elasticache["version"]}" + engine_version = var.elasticache["version"] port = 6379 - cluster_id = "${var.prefix}" - node_type = "${var.elasticache["node_type"]}" + cluster_id = var.prefix + node_type = var.elasticache["node_type"] num_cache_nodes = 1 - subnet_group_name = "${aws_elasticache_subnet_group.main.name}" + subnet_group_name = aws_elasticache_subnet_group.main.name security_group_ids = [ - "${aws_security_group.allow_all_egress.id}", - "${aws_security_group.allow_redis.id}", + aws_security_group.allow_all_egress.id, + aws_security_group.allow_redis.id, ] } diff --git a/resource-iam.tf b/resource-iam.tf index 26cdbdc..a49231a 100644 --- a/resource-iam.tf +++ b/resource-iam.tf @@ -1,5 +1,5 @@ resource "aws_iam_role" "ecs_task" { - name_prefix = "${var.prefix}" + name_prefix = var.prefix assume_role_policy = < 'https', 'X-Forwarded-Ssl' => 'on'}", "redis['enable'] = false", - "gitlab_rails['redis_host'] = '${aws_elasticache_cluster.main.cache_nodes.0.address}'", + "gitlab_rails['redis_host'] = '${aws_elasticache_cluster.main.cache_nodes[0].address}'", "gitlab_rails['redis_port'] = 6379", "postgresql['enable'] = false", "gitlab_rails['db_adapter'] = 'postgresql'",