Skip to content

Commit

Permalink
Merge pull request #4 from riboseinc/feature/refactoring
Browse files Browse the repository at this point in the history
Refactoring to support terraform 0.12
  • Loading branch information
jackivanov authored Jun 21, 2019
2 parents 4a4018c + ae898e8 commit f13c7d0
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 177 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:..."
Expand All @@ -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
}
```
29 changes: 8 additions & 21 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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" {}
Expand Down
2 changes: 1 addition & 1 deletion resource-ec2.tf
Original file line number Diff line number Diff line change
@@ -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
}
71 changes: 36 additions & 35 deletions resource-ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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

Expand Down Expand Up @@ -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"
}
}
}
Expand All @@ -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"
}
}
}
Expand All @@ -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"
}
}
}
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions resource-efs.tf
Original file line number Diff line number Diff line change
@@ -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,
]
}
16 changes: 8 additions & 8 deletions resource-elasticache.tf
Original file line number Diff line number Diff line change
@@ -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,
]
}
46 changes: 26 additions & 20 deletions resource-iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_iam_role" "ecs_task" {
name_prefix = "${var.prefix}"
name_prefix = var.prefix

assume_role_policy = <<EOF
{
Expand All @@ -19,16 +19,17 @@ resource "aws_iam_role" "ecs_task" {
]
}
EOF

}

resource "aws_iam_role_policy_attachment" "ecs_task" {
role = "${aws_iam_role.ecs_task.name}"
role = aws_iam_role.ecs_task.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}

resource "aws_iam_role_policy" "ecs_task" {
name_prefix = "${var.prefix}"
role = "${aws_iam_role.ecs_task.id}"
name_prefix = var.prefix
role = aws_iam_role.ecs_task.id

policy = <<EOF
{
Expand Down Expand Up @@ -102,12 +103,13 @@ resource "aws_iam_role_policy" "ecs_task" {
]
}
EOF

}

resource "aws_iam_role" "ecs_service" {
name_prefix = "${var.prefix}"
name_prefix = var.prefix

assume_role_policy = <<-EOF
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
Expand All @@ -123,19 +125,20 @@ resource "aws_iam_role" "ecs_service" {
}
]
}
EOF
EOF

}

resource "aws_iam_role_policy_attachment" "ecs_service" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
role = "${aws_iam_role.ecs_service.id}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
role = aws_iam_role.ecs_service.id
}

resource "aws_iam_role_policy" "ecs_service" {
name_prefix = "${var.prefix}"
role = "${aws_iam_role.ecs_service.id}"
name_prefix = var.prefix
role = aws_iam_role.ecs_service.id

policy = <<EOF
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
Expand All @@ -152,14 +155,15 @@ resource "aws_iam_role_policy" "ecs_service" {
]
}
EOF

}

#
# GitLab runner instance
#

resource "aws_iam_role" "gitlab_runner_instance" {
name_prefix = "${var.prefix}"
name_prefix = var.prefix

assume_role_policy = <<-EOF
{
Expand All @@ -176,22 +180,23 @@ resource "aws_iam_role" "gitlab_runner_instance" {
}
]
}
EOF
EOF

}

resource "aws_iam_instance_profile" "gitlab_runner_instance" {
name_prefix = "${var.prefix}"
path = "/"
role = "${aws_iam_role.gitlab_runner_instance.name}"
name_prefix = var.prefix
path = "/"
role = aws_iam_role.gitlab_runner_instance.name

lifecycle {
create_before_destroy = true
}
}

resource "aws_iam_role_policy" "gitlab_runner_instance" {
name_prefix = "${var.prefix}"
role = "${aws_iam_role.gitlab_runner_instance.id}"
name_prefix = var.prefix
role = aws_iam_role.gitlab_runner_instance.id

policy = <<-EOF
{
Expand Down Expand Up @@ -236,5 +241,6 @@ resource "aws_iam_role_policy" "gitlab_runner_instance" {
}
]
}
EOF
EOF

}
Loading

0 comments on commit f13c7d0

Please sign in to comment.