Skip to content

Commit 8588e13

Browse files
Refactor code. (#55)
* Refactor code. * fix typo * fix as per comments
1 parent 91d0168 commit 8588e13

13 files changed

+289
-267
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
99
- Improved error handling in scripts/endpoint_dns_name.sh - see [#17](https://github.com/ExpediaInc/apiary-federation/issues/17).
1010
- Support for Docker private registry.
1111

12+
### Changed
13+
- Refactor code to multiple `tf` files.
14+
1215

1316
## [1.0.5] - 2019-03-12
1417

cloudwatch.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (C) 2018-2019 Expedia Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
*/
6+
7+
resource "aws_cloudwatch_log_group" "waggledance_ecs" {
8+
name = "${local.instance_alias}"
9+
tags = "${var.tags}"
10+
}

common.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2018 Expedia Inc.
2+
* Copyright (C) 2018-2019 Expedia Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
*/

ecs-service-discovery.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (C) 2018-2019 Expedia Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
*/
6+
7+
resource "aws_service_discovery_private_dns_namespace" "waggledance" {
8+
name = "${local.instance_alias}-${var.aws_region}.${var.domain_extension}"
9+
vpc = "${var.vpc_id}"
10+
}
11+
12+
resource "aws_service_discovery_service" "metastore_proxy" {
13+
name = "metastore-proxy"
14+
15+
dns_config {
16+
namespace_id = "${aws_service_discovery_private_dns_namespace.waggledance.id}"
17+
18+
dns_records {
19+
ttl = 10
20+
type = "A"
21+
}
22+
23+
routing_policy = "MULTIVALUE"
24+
}
25+
26+
health_check_custom_config {
27+
failure_threshold = 1
28+
}
29+
}
30+
31+
resource "aws_route53_zone_association" "secondary" {
32+
count = "${length(var.secondary_vpcs)}"
33+
zone_id = "${aws_service_discovery_private_dns_namespace.waggledance.hosted_zone}"
34+
vpc_id = "${element(var.secondary_vpcs,count.index)}"
35+
vpc_region = "${var.aws_region}"
36+
}

ecs.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (C) 2018-2019 Expedia Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
*/
6+
7+
resource "aws_ecs_cluster" "waggledance" {
8+
name = "${local.instance_alias}"
9+
tags = "${var.tags}"
10+
}
11+
12+
resource "aws_ecs_service" "waggledance_service" {
13+
name = "${local.instance_alias}-service"
14+
launch_type = "FARGATE"
15+
cluster = "${aws_ecs_cluster.waggledance.id}"
16+
task_definition = "${aws_ecs_task_definition.waggledance.arn}"
17+
desired_count = "${var.wd_ecs_task_count}"
18+
19+
network_configuration {
20+
security_groups = ["${aws_security_group.wd_sg.id}"]
21+
subnets = ["${var.subnets}"]
22+
}
23+
24+
service_registries {
25+
registry_arn = "${aws_service_discovery_service.metastore_proxy.arn}"
26+
}
27+
}
28+
29+
resource "aws_ecs_task_definition" "waggledance" {
30+
family = "${local.instance_alias}"
31+
task_role_arn = "${aws_iam_role.waggledance_task.arn}"
32+
execution_role_arn = "${aws_iam_role.waggledance_task_exec.arn}"
33+
network_mode = "awsvpc"
34+
memory = "${var.memory}"
35+
cpu = "${var.cpu}"
36+
requires_compatibilities = ["EC2", "FARGATE"]
37+
container_definitions = "${data.template_file.waggledance.rendered}"
38+
tags = "${var.tags}"
39+
}

endpoints.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2018 Expedia Inc.
2+
* Copyright (C) 2018-2019 Expedia Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
*/

iam-ecs.tf

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Copyright (C) 2018-2019 Expedia Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
*/
6+
7+
resource "aws_iam_role" "waggledance_task_exec" {
8+
name = "${local.instance_alias}-ecs-task-exec-${var.aws_region}"
9+
10+
assume_role_policy = <<EOF
11+
{
12+
"Version": "2012-10-17",
13+
"Statement": [
14+
{
15+
"Sid": "",
16+
"Effect": "Allow",
17+
"Principal": {
18+
"Service": "ecs-tasks.amazonaws.com"
19+
},
20+
"Action": "sts:AssumeRole"
21+
}
22+
]
23+
}
24+
EOF
25+
26+
tags = "${var.tags}"
27+
}
28+
29+
resource "aws_iam_role_policy_attachment" "task_exec_managed" {
30+
role = "${aws_iam_role.waggledance_task_exec.id}"
31+
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
32+
}
33+
34+
resource "aws_iam_role_policy" "secretsmanager_for_ecs_task_exec" {
35+
count = "${var.docker_registry_auth_secret_name == "" ? 0 : 1}"
36+
name = "secretsmanager-exec"
37+
role = "${aws_iam_role.waggledance_task_exec.id}"
38+
39+
policy = <<EOF
40+
{
41+
"Version": "2012-10-17",
42+
"Statement": {
43+
"Effect": "Allow",
44+
"Action": "secretsmanager:GetSecretValue",
45+
"Resource": [ "${join("\",\"",concat(data.aws_secretsmanager_secret.docker_registry.*.arn))}" ]
46+
}
47+
}
48+
EOF
49+
}
50+
51+
resource "aws_iam_role" "waggledance_task" {
52+
name = "${local.instance_alias}-ecs-task-${var.aws_region}"
53+
54+
assume_role_policy = <<EOF
55+
{
56+
"Version": "2012-10-17",
57+
"Statement": [
58+
{
59+
"Sid": "",
60+
"Effect": "Allow",
61+
"Principal": {
62+
"Service": "ecs-tasks.amazonaws.com"
63+
},
64+
"Action": "sts:AssumeRole"
65+
}
66+
]
67+
}
68+
EOF
69+
70+
tags = "${var.tags}"
71+
}
72+
73+
resource "aws_iam_role_policy" "secretsmanager_for_waggledance_task" {
74+
count = "${ var.bastion_ssh_key_secret_name == "" ? 0 : 1}"
75+
name = "secretsmanager"
76+
role = "${aws_iam_role.waggledance_task.id}"
77+
78+
policy = <<EOF
79+
{
80+
"Version": "2012-10-17",
81+
"Statement": {
82+
"Effect": "Allow",
83+
"Action": "secretsmanager:GetSecretValue",
84+
"Resource": "${data.aws_secretsmanager_secret.bastion_ssh_key.arn}"
85+
}
86+
}
87+
EOF
88+
}

0 commit comments

Comments
 (0)