Skip to content

Commit

Permalink
Feature/tf format (#184)
Browse files Browse the repository at this point in the history
* terraform fmt

* configure required providers

* update changelog

Co-authored-by: Raj Poluri <[email protected]>
  • Loading branch information
rpoluri and Raj Poluri authored Mar 1, 2021
1 parent 3aa0215 commit e18570a
Show file tree
Hide file tree
Showing 27 changed files with 198 additions and 186 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ terraform.tfstate.backup
*.plan
terraform.tfstate
.terraform.tfstate.lock.info
.terraform.lock.hcl

# Netbeans files
nbactions.xml
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [6.7.3] - 2021-03-01
### Changed
- Terraform 0.12+ formatting.
- Add required version(1.x) for kubernetes provider,to fix issues with 2.x provider.

## [6.7.2] - 2021-01-04
### Fixed
- Fix colliding Grafana dashboard names for multiple Apiary instances.
Expand Down
26 changes: 13 additions & 13 deletions cloudwatch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

data "template_file" "s3_widgets" {
count = "${length(local.schemas_info)}"
count = length(local.schemas_info)

template = <<EOF
{
Expand Down Expand Up @@ -92,7 +92,7 @@ EOF
}

data "template_file" "ecs_widgets" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0

template = <<EOF
{
Expand Down Expand Up @@ -129,7 +129,7 @@ EOF
}

data "template_file" "nlb_widgets" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0

template = <<EOF
{
Expand Down Expand Up @@ -262,7 +262,7 @@ locals {
},
]

ecs_cluster_name = "${join("", aws_ecs_cluster.apiary.*.name)}"
ecs_cluster_name = join("", aws_ecs_cluster.apiary.*.name)

dimensions = [
{
Expand All @@ -288,18 +288,18 @@ locals {
}

resource "aws_cloudwatch_metric_alarm" "apiary_alert" {
count = "${var.hms_instance_type == "ecs" ? length(local.alerts) : 0}"
alarm_name = "${lookup(local.alerts[count.index], "alarm_name")}"
comparison_operator = "${lookup(local.alerts[count.index], "comparison_operator", "GreaterThanOrEqualToThreshold")}"
metric_name = "${lookup(local.alerts[count.index], "metric_name")}"
namespace = "${lookup(local.alerts[count.index], "namespace")}"
period = "${lookup(local.alerts[count.index], "period", "120")}"
evaluation_periods = "${lookup(local.alerts[count.index], "evaluation_periods", "2")}"
count = var.hms_instance_type == "ecs" ? length(local.alerts) : 0
alarm_name = lookup(local.alerts[count.index], "alarm_name")
comparison_operator = lookup(local.alerts[count.index], "comparison_operator", "GreaterThanOrEqualToThreshold")
metric_name = lookup(local.alerts[count.index], "metric_name")
namespace = lookup(local.alerts[count.index], "namespace")
period = lookup(local.alerts[count.index], "period", "120")
evaluation_periods = lookup(local.alerts[count.index], "evaluation_periods", "2")
statistic = "Average"
threshold = "${lookup(local.alerts[count.index], "threshold")}"
threshold = lookup(local.alerts[count.index], "threshold")

#alarm_description = "This metric monitors apiary ecs ec2 cpu utilization"
insufficient_data_actions = []
dimensions = "${local.dimensions[count.index]}"
dimensions = local.dimensions[count.index]
alarm_actions = ["${aws_sns_topic.apiary_ops_sns.arn}"]
}
12 changes: 6 additions & 6 deletions common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

locals {
instance_alias = "${var.instance_name == "" ? "apiary" : format("apiary-%s", var.instance_name)}"
instance_alias = var.instance_name == "" ? "apiary" : format("apiary-%s", var.instance_name)
apiary_bucket_prefix = "${local.instance_alias}-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
apiary_assume_role_bucket_prefix = [for assumerole in var.apiary_assume_roles : "${local.instance_alias}-${data.aws_caller_identity.current.account_id}-${lookup(assumerole, "allow_cross_region_access", false) ? "*" : data.aws_region.current.name}"]
enable_route53_records = var.apiary_domain_name == "" ? false : true
Expand All @@ -23,11 +23,11 @@ locals {
schema)
]

gluedb_prefix = "${var.instance_name == "" ? "" : "${var.instance_name}_"}"
gluedb_prefix = var.instance_name == "" ? "" : "${var.instance_name}_"
cw_arn = "arn:aws:swf:${var.aws_region}:${data.aws_caller_identity.current.account_id}:action/actions/AWS_EC2.InstanceId.Reboot/1.0"
assume_allowed_principals = split(",", join(",", [for role in var.apiary_assume_roles : join(",", [for principal in role.principals : replace(principal, "/:role.*/", ":root")])]))
producer_allowed_principals = split(",", join(",", values(var.apiary_producer_iamroles)))
final_atlas_cluster_name = "${var.atlas_cluster_name == "" ? local.instance_alias : var.atlas_cluster_name}"
final_atlas_cluster_name = var.atlas_cluster_name == "" ? local.instance_alias : var.atlas_cluster_name
s3_inventory_prefix = "EntireBucketDaily"
s3_inventory_bucket = var.s3_enable_inventory ? "${local.apiary_bucket_prefix}-s3-inventory" : ""
create_sqs_data_event_queue = contains([for schema in local.schemas_info : lookup(schema, "enable_data_events_sqs", "0")], "1") ? true : false
Expand All @@ -54,11 +54,11 @@ data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

data "aws_vpc" "apiary_vpc" {
id = "${var.vpc_id}"
id = var.vpc_id
}

data "aws_route53_zone" "apiary_zone" {
count = local.enable_route53_records ? 1 : 0
name = "${var.apiary_domain_name}"
vpc_id = "${var.vpc_id}"
name = var.apiary_domain_name
vpc_id = var.vpc_id
}
44 changes: 22 additions & 22 deletions db.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

resource "aws_db_subnet_group" "apiarydbsg" {
count = "${var.external_database_host == "" ? 1 : 0}"
count = var.external_database_host == "" ? 1 : 0
name = "${local.instance_alias}-dbsg"
subnet_ids = var.private_subnets
description = "Apiary DB Subnet Group"

tags = "${merge(map("Name", "Apiary DB Subnet Group"), var.apiary_tags)}"
tags = merge(map("Name", "Apiary DB Subnet Group"), var.apiary_tags)
}

resource "aws_security_group" "db_sg" {
count = "${var.external_database_host == "" ? 1 : 0}"
count = var.external_database_host == "" ? 1 : 0
name = "${local.instance_alias}-db"
vpc_id = "${var.vpc_id}"
tags = "${var.apiary_tags}"
vpc_id = var.vpc_id
tags = var.apiary_tags

ingress {
from_port = 0
Expand All @@ -31,7 +31,7 @@ resource "aws_security_group" "db_sg" {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = "${var.ingress_cidr}"
cidr_blocks = var.ingress_cidr
}

egress {
Expand All @@ -44,28 +44,28 @@ resource "aws_security_group" "db_sg" {
}

resource "random_id" "snapshot_id" {
count = "${var.external_database_host == "" ? 1 : 0}"
count = var.external_database_host == "" ? 1 : 0
byte_length = 8
}

resource "random_string" "db_master_password" {
count = "${var.external_database_host == "" ? 1 : 0}"
count = var.external_database_host == "" ? 1 : 0
length = 16
special = false
}

resource "aws_rds_cluster" "apiary_cluster" {
count = "${var.external_database_host == "" ? 1 : 0}"
count = var.external_database_host == "" ? 1 : 0
cluster_identifier = "${local.instance_alias}-cluster"
database_name = "${var.apiary_database_name}"
master_username = "${var.db_master_username}"
master_password = "${random_string.db_master_password[0].result}"
backup_retention_period = "${var.db_backup_retention}"
preferred_backup_window = "${var.db_backup_window}"
preferred_maintenance_window = "${var.db_maintenance_window}"
db_subnet_group_name = "${aws_db_subnet_group.apiarydbsg[0].name}"
database_name = var.apiary_database_name
master_username = var.db_master_username
master_password = random_string.db_master_password[0].result
backup_retention_period = var.db_backup_retention
preferred_backup_window = var.db_backup_window
preferred_maintenance_window = var.db_maintenance_window
db_subnet_group_name = aws_db_subnet_group.apiarydbsg[0].name
vpc_security_group_ids = compact(concat(list(aws_security_group.db_sg[0].id), var.apiary_rds_additional_sg))
tags = "${var.apiary_tags}"
tags = var.apiary_tags
final_snapshot_identifier = "${local.instance_alias}-cluster-final-${random_id.snapshot_id[0].hex}"
iam_database_authentication_enabled = true
apply_immediately = var.db_apply_immediately
Expand All @@ -76,13 +76,13 @@ resource "aws_rds_cluster" "apiary_cluster" {
}

resource "aws_rds_cluster_instance" "apiary_cluster_instance" {
count = "${var.external_database_host == "" ? var.db_instance_count : 0}"
count = var.external_database_host == "" ? var.db_instance_count : 0
identifier = "${local.instance_alias}-instance-${count.index}"
cluster_identifier = "${aws_rds_cluster.apiary_cluster[0].id}"
instance_class = "${var.db_instance_class}"
db_subnet_group_name = "${aws_db_subnet_group.apiarydbsg[0].name}"
cluster_identifier = aws_rds_cluster.apiary_cluster[0].id
instance_class = var.db_instance_class
db_subnet_group_name = aws_db_subnet_group.apiarydbsg[0].name
publicly_accessible = false
tags = "${var.apiary_tags}"
tags = var.apiary_tags

lifecycle {
create_before_destroy = true
Expand Down
20 changes: 10 additions & 10 deletions ecs-service-discovery.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*/

resource "aws_service_discovery_private_dns_namespace" "apiary" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
name = "${local.instance_alias}-${var.aws_region}.${var.ecs_domain_extension}"
vpc = "${var.vpc_id}"
vpc = var.vpc_id
}

resource "aws_service_discovery_service" "hms_readwrite" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
name = "hms-readwrite"

dns_config {
namespace_id = "${aws_service_discovery_private_dns_namespace.apiary[0].id}"
namespace_id = aws_service_discovery_private_dns_namespace.apiary[0].id

dns_records {
ttl = 10
Expand All @@ -31,11 +31,11 @@ resource "aws_service_discovery_service" "hms_readwrite" {
}

resource "aws_service_discovery_service" "hms_readonly" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
name = "hms-readonly"

dns_config {
namespace_id = "${aws_service_discovery_private_dns_namespace.apiary[0].id}"
namespace_id = aws_service_discovery_private_dns_namespace.apiary[0].id

dns_records {
ttl = 10
Expand All @@ -51,8 +51,8 @@ resource "aws_service_discovery_service" "hms_readonly" {
}

resource "aws_route53_zone_association" "secondary" {
count = "${var.hms_instance_type == "ecs" ? length(var.secondary_vpcs) : 0}"
zone_id = "${aws_service_discovery_private_dns_namespace.apiary[0].hosted_zone}"
vpc_id = "${element(var.secondary_vpcs, count.index)}"
vpc_region = "${var.aws_region}"
count = var.hms_instance_type == "ecs" ? length(var.secondary_vpcs) : 0
zone_id = aws_service_discovery_private_dns_namespace.apiary[0].hosted_zone
vpc_id = element(var.secondary_vpcs, count.index)
vpc_region = var.aws_region
}
62 changes: 31 additions & 31 deletions ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,54 @@
*/

resource "aws_ecs_cluster" "apiary" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
name = "${local.instance_alias}"
tags = "${var.apiary_tags}"
count = var.hms_instance_type == "ecs" ? 1 : 0
name = local.instance_alias
tags = var.apiary_tags
}

resource "aws_cloudwatch_log_group" "apiary_ecs" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
name = "${local.instance_alias}-ecs"
tags = "${var.apiary_tags}"
tags = var.apiary_tags
}

resource "aws_ecs_task_definition" "apiary_hms_readwrite" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
family = "${local.instance_alias}-hms-readwrite"
task_role_arn = "${aws_iam_role.apiary_hms_readwrite.arn}"
execution_role_arn = "${aws_iam_role.apiary_task_exec[0].arn}"
task_role_arn = aws_iam_role.apiary_hms_readwrite.arn
execution_role_arn = aws_iam_role.apiary_task_exec[0].arn
network_mode = "awsvpc"
memory = "${var.hms_rw_heapsize}"
cpu = "${var.hms_rw_cpu}"
memory = var.hms_rw_heapsize
cpu = var.hms_rw_cpu
requires_compatibilities = ["EC2", "FARGATE"]
container_definitions = "${data.template_file.hms_readwrite.rendered}"
tags = "${var.apiary_tags}"
container_definitions = data.template_file.hms_readwrite.rendered
tags = var.apiary_tags
}

resource "aws_ecs_task_definition" "apiary_hms_readonly" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
family = "${local.instance_alias}-hms-readonly"
task_role_arn = "${aws_iam_role.apiary_hms_readonly.arn}"
execution_role_arn = "${aws_iam_role.apiary_task_exec[0].arn}"
task_role_arn = aws_iam_role.apiary_hms_readonly.arn
execution_role_arn = aws_iam_role.apiary_task_exec[0].arn
network_mode = "awsvpc"
memory = "${var.hms_ro_heapsize}"
cpu = "${var.hms_ro_cpu}"
memory = var.hms_ro_heapsize
cpu = var.hms_ro_cpu
requires_compatibilities = ["EC2", "FARGATE"]
container_definitions = "${data.template_file.hms_readonly.rendered}"
tags = "${var.apiary_tags}"
container_definitions = data.template_file.hms_readonly.rendered
tags = var.apiary_tags
}

resource "aws_ecs_service" "apiary_hms_readwrite_service" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
depends_on = [aws_lb_target_group.apiary_hms_rw_tg]
name = "${local.instance_alias}-hms-readwrite-service"
launch_type = "FARGATE"
cluster = "${aws_ecs_cluster.apiary[0].id}"
task_definition = "${aws_ecs_task_definition.apiary_hms_readwrite[0].arn}"
desired_count = "${var.hms_rw_ecs_task_count}"
cluster = aws_ecs_cluster.apiary[0].id
task_definition = aws_ecs_task_definition.apiary_hms_readwrite[0].arn
desired_count = var.hms_rw_ecs_task_count

load_balancer {
target_group_arn = "${aws_lb_target_group.apiary_hms_rw_tg[0].arn}"
target_group_arn = aws_lb_target_group.apiary_hms_rw_tg[0].arn
container_name = "apiary-hms-readwrite"
container_port = 9083
}
Expand All @@ -63,21 +63,21 @@ resource "aws_ecs_service" "apiary_hms_readwrite_service" {
}

service_registries {
registry_arn = "${aws_service_discovery_service.hms_readwrite[0].arn}"
registry_arn = aws_service_discovery_service.hms_readwrite[0].arn
}
}

resource "aws_ecs_service" "apiary_hms_readonly_service" {
count = "${var.hms_instance_type == "ecs" ? 1 : 0}"
count = var.hms_instance_type == "ecs" ? 1 : 0
depends_on = [aws_lb_target_group.apiary_hms_ro_tg]
name = "${local.instance_alias}-hms-readonly-service"
launch_type = "FARGATE"
cluster = "${aws_ecs_cluster.apiary[0].id}"
task_definition = "${aws_ecs_task_definition.apiary_hms_readonly[0].arn}"
desired_count = "${var.hms_ro_ecs_task_count}"
cluster = aws_ecs_cluster.apiary[0].id
task_definition = aws_ecs_task_definition.apiary_hms_readonly[0].arn
desired_count = var.hms_ro_ecs_task_count

load_balancer {
target_group_arn = "${aws_lb_target_group.apiary_hms_ro_tg[0].arn}"
target_group_arn = aws_lb_target_group.apiary_hms_ro_tg[0].arn
container_name = "apiary-hms-readonly"
container_port = 9083
}
Expand All @@ -88,6 +88,6 @@ resource "aws_ecs_service" "apiary_hms_readonly_service" {
}

service_registries {
registry_arn = "${aws_service_discovery_service.hms_readonly[0].arn}"
registry_arn = aws_service_discovery_service.hms_readonly[0].arn
}
}
4 changes: 2 additions & 2 deletions iam-cross-account-client-roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ resource "aws_iam_role" "apiary_assume_role" {
]
}
EOF
tags = "${var.apiary_tags}"
tags = var.apiary_tags
}

resource "aws_iam_role_policy" "apiary_assume_role_s3" {
count = length(var.apiary_assume_roles)
name = "s3_access"
role = "${aws_iam_role.apiary_assume_role[count.index].id}"
role = aws_iam_role.apiary_assume_role[count.index].id

policy = <<EOF
{
Expand Down
Loading

0 comments on commit e18570a

Please sign in to comment.