From 9d89b149dad98ec319f21f316cdf8f1e88d1014b Mon Sep 17 00:00:00 2001 From: "coord.e" Date: Mon, 15 Jul 2019 06:54:19 +0000 Subject: [PATCH 1/4] Fix: Fix some changes around blocks --- cert.tf | 2 +- compute.tf | 2 +- db.tf | 2 +- ecs.tf | 2 +- iam.tf | 2 +- security_group.tf | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cert.tf b/cert.tf index d957601..5d25d5a 100644 --- a/cert.tf +++ b/cert.tf @@ -19,7 +19,7 @@ resource "acme_certificate" "certificate" { dns_challenge { provider = "route53" - config { + config = { AWS_ACCESS_KEY_ID = "${var.aws_access_key}" AWS_SECRET_ACCESS_KEY = "${var.aws_secret_key}" AWS_DEFAULT_REGION = "${var.aws_region}" diff --git a/compute.tf b/compute.tf index f61a588..865afc8 100644 --- a/compute.tf +++ b/compute.tf @@ -10,7 +10,7 @@ resource "aws_autoscaling_group" "app" { data "template_file" "cloud_config" { template = "${file("${path.module}/cloud-config.yml")}" - vars { + vars = { aws_region = "${var.aws_region}" ecs_cluster_name = "${aws_ecs_cluster.main.name}" ecs_log_level = "info" diff --git a/db.tf b/db.tf index 40baea7..388e2b4 100644 --- a/db.tf +++ b/db.tf @@ -1,7 +1,7 @@ resource "aws_db_subnet_group" "main" { name = "db_subnet" subnet_ids = ["${aws_subnet.main.*.id}"] - tags { + tags = { Name = "db_subnet" } } diff --git a/ecs.tf b/ecs.tf index b15c0da..44d34cf 100644 --- a/ecs.tf +++ b/ecs.tf @@ -5,7 +5,7 @@ resource "aws_ecs_cluster" "main" { data "template_file" "task_definition" { template = "${file("${path.module}/task-definition.json")}" - vars { + vars = { image_url = "${var.ecs_image_url}" container_name = "sakuten_backend" log_group_region = "${var.aws_region}" diff --git a/iam.tf b/iam.tf index 15d6060..dc168e7 100644 --- a/iam.tf +++ b/iam.tf @@ -71,7 +71,7 @@ EOF data "template_file" "instance_profile" { template = "${file("${path.module}/instance-profile-policy.json")}" - vars { + vars = { app_log_group_arn = "${aws_cloudwatch_log_group.app.arn}" ecs_log_group_arn = "${aws_cloudwatch_log_group.ecs.arn}" } diff --git a/security_group.tf b/security_group.tf index 11ecd3a..32e34dc 100644 --- a/security_group.tf +++ b/security_group.tf @@ -59,7 +59,7 @@ resource "aws_security_group" "db" { name = "db_server" description = "a security group on db of sakuten main vpc" vpc_id = "${aws_vpc.main.id}" - tags { + tags = { Name = "db" } From e7fdf8e0edd7f955a25261aa97fd3e738c997aff Mon Sep 17 00:00:00 2001 From: "coord.e" Date: Mon, 15 Jul 2019 06:56:28 +0000 Subject: [PATCH 2/4] Fix: Replace md5(file( call with filemd5 to avoid non-UTF8 string --- s3.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s3.tf b/s3.tf index ef92986..dd8fce1 100644 --- a/s3.tf +++ b/s3.tf @@ -2,6 +2,6 @@ resource "aws_s3_bucket_object" "dbgen_archive" { bucket = "${aws_s3_bucket.bucket.id}" key = "dbgen_archive" source = "${var.dbgen_archive_path}" - etag = "${md5(file("${var.dbgen_archive_path}"))}" + etag = "${filemd5("${var.dbgen_archive_path}")}" } From fdcab84abf7077c851f0be7bb27bda4d0981c5ba Mon Sep 17 00:00:00 2001 From: "coord.e" Date: Mon, 15 Jul 2019 07:00:16 +0000 Subject: [PATCH 3/4] Change: Many changes by `terraform 0.12upgrade` --- alb.tf | 20 ++++++++++---------- cert.tf | 20 ++++++++++---------- compute.tf | 32 ++++++++++++++++---------------- db.tf | 26 +++++++++++++------------- ecs.tf | 42 +++++++++++++++++++++--------------------- iam.tf | 37 +++++++++++++++++++++---------------- lambda_data_gen.tf | 26 +++++++++++++++----------- lambda_drawer.tf | 23 ++++++++++++----------- main.tf | 5 +++-- outputs.tf | 9 +++++---- provider.tf | 7 ++++--- route53.tf | 39 ++++++++++++++++++++------------------- s3.tf | 6 +++--- security_group.tf | 15 ++++++++------- variables.tf | 42 ++++++++++++++++++++++++++++++------------ vpc.tf | 20 ++++++++++---------- 16 files changed, 201 insertions(+), 168 deletions(-) diff --git a/alb.tf b/alb.tf index 7153bbc..172b0af 100644 --- a/alb.tf +++ b/alb.tf @@ -1,32 +1,32 @@ resource "aws_alb_target_group" "main" { name = "tf-${var.base_name}-ecs" - port = "${var.alb_container_port}" + port = var.alb_container_port protocol = "HTTP" - vpc_id = "${aws_vpc.main.id}" + vpc_id = aws_vpc.main.id health_check { - path = "${var.health_check_path}" + path = var.health_check_path } } resource "aws_alb" "main" { name = "tf-${var.base_name}-alb-ecs" - subnets = ["${aws_subnet.main.*.id}"] - security_groups = ["${aws_security_group.lb_sg.id}"] + subnets = aws_subnet.main.*.id + security_groups = [aws_security_group.lb_sg.id] - depends_on = ["aws_internet_gateway.gw"] + depends_on = [aws_internet_gateway.gw] } resource "aws_alb_listener" "front_end" { - load_balancer_arn = "${aws_alb.main.id}" + load_balancer_arn = aws_alb.main.id port = "443" protocol = "HTTPS" - ssl_policy = "ELBSecurityPolicy-2015-05" - certificate_arn = "${aws_iam_server_certificate.elb_cert.arn}" + ssl_policy = "ELBSecurityPolicy-2015-05" + certificate_arn = aws_iam_server_certificate.elb_cert.arn default_action { - target_group_arn = "${aws_alb_target_group.main.id}" + target_group_arn = aws_alb_target_group.main.id type = "forward" } } diff --git a/cert.tf b/cert.tf index 5d25d5a..9924201 100644 --- a/cert.tf +++ b/cert.tf @@ -1,5 +1,5 @@ provider "acme" { - server_url = "${var.acme_server_url}" + server_url = var.acme_server_url } resource "tls_private_key" "private_key" { @@ -7,12 +7,12 @@ resource "tls_private_key" "private_key" { } resource "acme_registration" "reg" { - account_key_pem = "${tls_private_key.private_key.private_key_pem}" - email_address = "${var.acme_email}" + account_key_pem = tls_private_key.private_key.private_key_pem + email_address = var.acme_email } resource "acme_certificate" "certificate" { - account_key_pem = "${acme_registration.reg.account_key_pem}" + account_key_pem = acme_registration.reg.account_key_pem common_name = "api.${var.domain}" subject_alternative_names = [] @@ -20,17 +20,17 @@ resource "acme_certificate" "certificate" { provider = "route53" config = { - AWS_ACCESS_KEY_ID = "${var.aws_access_key}" - AWS_SECRET_ACCESS_KEY = "${var.aws_secret_key}" - AWS_DEFAULT_REGION = "${var.aws_region}" + AWS_ACCESS_KEY_ID = var.aws_access_key + AWS_SECRET_ACCESS_KEY = var.aws_secret_key + AWS_DEFAULT_REGION = var.aws_region } } } resource "aws_iam_server_certificate" "elb_cert" { - name_prefix = "tf-${var.base_name}-cert-" - certificate_body = "${acme_certificate.certificate.certificate_pem}" - private_key = "${acme_certificate.certificate.private_key_pem}" + name_prefix = "tf-${var.base_name}-cert-" + certificate_body = acme_certificate.certificate.certificate_pem + private_key = acme_certificate.certificate.private_key_pem lifecycle { create_before_destroy = true diff --git a/compute.tf b/compute.tf index 865afc8..a46e521 100644 --- a/compute.tf +++ b/compute.tf @@ -1,21 +1,21 @@ resource "aws_autoscaling_group" "app" { name = "tf-${var.base_name}-asg" - vpc_zone_identifier = ["${aws_subnet.main.*.id}"] - min_size = "${var.asg_min}" - max_size = "${var.asg_max}" - desired_capacity = "${var.asg_desired}" - launch_configuration = "${aws_launch_configuration.app.name}" + vpc_zone_identifier = aws_subnet.main.*.id + min_size = var.asg_min + max_size = var.asg_max + desired_capacity = var.asg_desired + launch_configuration = aws_launch_configuration.app.name } data "template_file" "cloud_config" { - template = "${file("${path.module}/cloud-config.yml")}" + template = file("${path.module}/cloud-config.yml") vars = { - aws_region = "${var.aws_region}" - ecs_cluster_name = "${aws_ecs_cluster.main.name}" + aws_region = var.aws_region + ecs_cluster_name = aws_ecs_cluster.main.name ecs_log_level = "info" ecs_agent_version = "latest" - ecs_log_group_name = "${aws_cloudwatch_log_group.ecs.name}" + ecs_log_group_name = aws_cloudwatch_log_group.ecs.name } } @@ -41,19 +41,19 @@ data "aws_ami" "stable_coreos" { } resource "aws_key_pair" "instance" { - public_key = "${var.ssh_public_key}" + public_key = var.ssh_public_key } resource "aws_launch_configuration" "app" { security_groups = [ - "${aws_security_group.instance_sg.id}", + aws_security_group.instance_sg.id, ] - key_name = "${aws_key_pair.instance.key_name}" - image_id = "${data.aws_ami.stable_coreos.id}" - instance_type = "${var.instance_type}" - iam_instance_profile = "${aws_iam_instance_profile.app.name}" - user_data = "${data.template_file.cloud_config.rendered}" + key_name = aws_key_pair.instance.key_name + image_id = data.aws_ami.stable_coreos.id + instance_type = var.instance_type + iam_instance_profile = aws_iam_instance_profile.app.name + user_data = data.template_file.cloud_config.rendered associate_public_ip_address = true lifecycle { diff --git a/db.tf b/db.tf index 388e2b4..9d7a81f 100644 --- a/db.tf +++ b/db.tf @@ -1,18 +1,18 @@ resource "aws_db_subnet_group" "main" { - name = "db_subnet" - subnet_ids = ["${aws_subnet.main.*.id}"] + name = "db_subnet" + subnet_ids = aws_subnet.main.*.id tags = { - Name = "db_subnet" + Name = "db_subnet" } } resource "aws_db_parameter_group" "db_pg" { - name = "rds-pg" - family = "postgres10" + name = "rds-pg" + family = "postgres10" description = "Managed by Terraform" parameter { - name = "timezone" + name = "timezone" value = "Asia/Tokyo" } } @@ -22,15 +22,15 @@ resource "aws_db_instance" "db" { allocated_storage = 5 engine = "postgres" engine_version = "10.4" - instance_class = "${var.db_instance_type}" + instance_class = var.db_instance_type storage_type = "gp2" - username = "${var.db_username}" - password = "${var.db_password}" + username = var.db_username + password = var.db_password backup_retention_period = 7 multi_az = true - vpc_security_group_ids = ["${aws_security_group.db.id}"] - db_subnet_group_name = "${aws_db_subnet_group.main.name}" - parameter_group_name = "${aws_db_parameter_group.db_pg.name}" - skip_final_snapshot = true + vpc_security_group_ids = [aws_security_group.db.id] + db_subnet_group_name = aws_db_subnet_group.main.name + parameter_group_name = aws_db_parameter_group.db_pg.name + skip_final_snapshot = true } diff --git a/ecs.tf b/ecs.tf index 44d34cf..d7263c8 100644 --- a/ecs.tf +++ b/ecs.tf @@ -3,45 +3,45 @@ resource "aws_ecs_cluster" "main" { } data "template_file" "task_definition" { - template = "${file("${path.module}/task-definition.json")}" + template = file("${path.module}/task-definition.json") vars = { - image_url = "${var.ecs_image_url}" - container_name = "sakuten_backend" - log_group_region = "${var.aws_region}" - log_group_name = "${aws_cloudwatch_log_group.app.name}" - secret_key = "${var.secret_key}" - container_port = "${var.container_port}" - host_port = "${var.alb_container_port}" - recaptcha_secret_key = "${var.recaptcha_secret_key}" - database_url = "postgresql://${var.db_username}:${var.db_password}@${aws_db_instance.db.endpoint}/postgres" - /* timepoints = "${var.timepoints}" */ - /* start_datetime = "${var.start_datetime}" */ - /* end_datetime = "${var.end_datetime}" */ + image_url = var.ecs_image_url + container_name = "sakuten_backend" + log_group_region = var.aws_region + log_group_name = aws_cloudwatch_log_group.app.name + secret_key = var.secret_key + container_port = var.container_port + host_port = var.alb_container_port + recaptcha_secret_key = var.recaptcha_secret_key + database_url = "postgresql://${var.db_username}:${var.db_password}@${aws_db_instance.db.endpoint}/postgres" } + /* timepoints = "${var.timepoints}" */ + /* start_datetime = "${var.start_datetime}" */ + /* end_datetime = "${var.end_datetime}" */ } resource "aws_ecs_task_definition" "backend" { family = "tf_backend_td" - container_definitions = "${data.template_file.task_definition.rendered}" + container_definitions = data.template_file.task_definition.rendered } resource "aws_ecs_service" "main" { name = "tf-${var.base_name}-ecs" - cluster = "${aws_ecs_cluster.main.id}" - task_definition = "${aws_ecs_task_definition.backend.arn}" + cluster = aws_ecs_cluster.main.id + task_definition = aws_ecs_task_definition.backend.arn desired_count = 1 - iam_role = "${aws_iam_role.ecs_service.name}" + iam_role = aws_iam_role.ecs_service.name load_balancer { - target_group_arn = "${aws_alb_target_group.main.id}" + target_group_arn = aws_alb_target_group.main.id container_name = "sakuten_backend" - container_port = "${var.container_port}" + container_port = var.container_port } depends_on = [ - "aws_iam_role_policy.ecs_service", - "aws_alb_listener.front_end", + aws_iam_role_policy.ecs_service, + aws_alb_listener.front_end, ] } diff --git a/iam.tf b/iam.tf index dc168e7..06eb6e1 100644 --- a/iam.tf +++ b/iam.tf @@ -16,11 +16,12 @@ resource "aws_iam_role" "ecs_service" { ] } EOF + } resource "aws_iam_role_policy" "ecs_service" { name = "tf_ecs_policy" - role = "${aws_iam_role.ecs_service.name}" + role = aws_iam_role.ecs_service.name policy = < Date: Mon, 15 Jul 2019 07:00:39 +0000 Subject: [PATCH 4/4] Add: Use 0.12 or later --- versions.tf | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 versions.tf diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}