From 8588e13405ed23bbfcca810af12567e034f7bdd6 Mon Sep 17 00:00:00 2001 From: pradeepbhadani Date: Thu, 4 Apr 2019 15:14:31 +0100 Subject: [PATCH] Refactor code. (#55) * Refactor code. * fix typo * fix as per comments --- CHANGELOG.md | 3 + cloudwatch.tf | 10 ++ common.tf | 2 +- ecs-service-discovery.tf | 36 ++++++ ecs.tf | 39 ++++++ endpoints.tf | 2 +- iam-ecs.tf | 88 ++++++++++++++ main.tf | 257 --------------------------------------- outputs.tf | 6 - sg.tf | 32 +++++ templates.tf | 77 ++++++++++++ variables.tf | 2 +- version.tf | 2 +- 13 files changed, 289 insertions(+), 267 deletions(-) create mode 100644 cloudwatch.tf create mode 100644 ecs-service-discovery.tf create mode 100644 ecs.tf create mode 100644 iam-ecs.tf delete mode 100644 main.tf delete mode 100644 outputs.tf create mode 100644 sg.tf create mode 100644 templates.tf diff --git a/CHANGELOG.md b/CHANGELOG.md index 15a917a..7c75a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Improved error handling in scripts/endpoint_dns_name.sh - see [#17](https://github.com/ExpediaInc/apiary-federation/issues/17). - Support for Docker private registry. +### Changed +- Refactor code to multiple `tf` files. + ## [1.0.5] - 2019-03-12 diff --git a/cloudwatch.tf b/cloudwatch.tf new file mode 100644 index 0000000..093bca8 --- /dev/null +++ b/cloudwatch.tf @@ -0,0 +1,10 @@ +/** + * Copyright (C) 2018-2019 Expedia Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + */ + +resource "aws_cloudwatch_log_group" "waggledance_ecs" { + name = "${local.instance_alias}" + tags = "${var.tags}" +} diff --git a/common.tf b/common.tf index f638b0e..f794eae 100644 --- a/common.tf +++ b/common.tf @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Expedia Inc. + * Copyright (C) 2018-2019 Expedia Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); */ diff --git a/ecs-service-discovery.tf b/ecs-service-discovery.tf new file mode 100644 index 0000000..13a6d0c --- /dev/null +++ b/ecs-service-discovery.tf @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2018-2019 Expedia Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + */ + +resource "aws_service_discovery_private_dns_namespace" "waggledance" { + name = "${local.instance_alias}-${var.aws_region}.${var.domain_extension}" + vpc = "${var.vpc_id}" +} + +resource "aws_service_discovery_service" "metastore_proxy" { + name = "metastore-proxy" + + dns_config { + namespace_id = "${aws_service_discovery_private_dns_namespace.waggledance.id}" + + dns_records { + ttl = 10 + type = "A" + } + + routing_policy = "MULTIVALUE" + } + + health_check_custom_config { + failure_threshold = 1 + } +} + +resource "aws_route53_zone_association" "secondary" { + count = "${length(var.secondary_vpcs)}" + zone_id = "${aws_service_discovery_private_dns_namespace.waggledance.hosted_zone}" + vpc_id = "${element(var.secondary_vpcs,count.index)}" + vpc_region = "${var.aws_region}" +} diff --git a/ecs.tf b/ecs.tf new file mode 100644 index 0000000..c53d3b1 --- /dev/null +++ b/ecs.tf @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2018-2019 Expedia Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + */ + +resource "aws_ecs_cluster" "waggledance" { + name = "${local.instance_alias}" + tags = "${var.tags}" +} + +resource "aws_ecs_service" "waggledance_service" { + name = "${local.instance_alias}-service" + launch_type = "FARGATE" + cluster = "${aws_ecs_cluster.waggledance.id}" + task_definition = "${aws_ecs_task_definition.waggledance.arn}" + desired_count = "${var.wd_ecs_task_count}" + + network_configuration { + security_groups = ["${aws_security_group.wd_sg.id}"] + subnets = ["${var.subnets}"] + } + + service_registries { + registry_arn = "${aws_service_discovery_service.metastore_proxy.arn}" + } +} + +resource "aws_ecs_task_definition" "waggledance" { + family = "${local.instance_alias}" + task_role_arn = "${aws_iam_role.waggledance_task.arn}" + execution_role_arn = "${aws_iam_role.waggledance_task_exec.arn}" + network_mode = "awsvpc" + memory = "${var.memory}" + cpu = "${var.cpu}" + requires_compatibilities = ["EC2", "FARGATE"] + container_definitions = "${data.template_file.waggledance.rendered}" + tags = "${var.tags}" +} diff --git a/endpoints.tf b/endpoints.tf index 50f2537..f9cb824 100644 --- a/endpoints.tf +++ b/endpoints.tf @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Expedia Inc. + * Copyright (C) 2018-2019 Expedia Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); */ diff --git a/iam-ecs.tf b/iam-ecs.tf new file mode 100644 index 0000000..ff6b4df --- /dev/null +++ b/iam-ecs.tf @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2018-2019 Expedia Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + */ + +resource "aws_iam_role" "waggledance_task_exec" { + name = "${local.instance_alias}-ecs-task-exec-${var.aws_region}" + + assume_role_policy = <