From b243662e7aaae0be70d65cf7defd081b16e12dbb Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Mon, 12 Aug 2019 15:17:11 -0700 Subject: [PATCH] Update syntax to TF >= 0.12 --- main.tf | 274 ++++++++++++++++++++++++++------------------------- outputs.tf | 6 +- variables.tf | 11 ++- versions.tf | 4 + 4 files changed, 157 insertions(+), 138 deletions(-) create mode 100644 versions.tf diff --git a/main.tf b/main.tf index 61275df..640e5f9 100644 --- a/main.tf +++ b/main.tf @@ -24,134 +24,134 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ provider "aws" { - region = "${var.region}" + region = var.region } locals { - k8s_cluster_tags = "${map( - "Name", "kubeadm-milpa-${var.cluster-name}", - "kubernetes.io/cluster/${var.cluster-name}", "owned" - )}" + k8s_cluster_tags = { + "Name" = "kubeadm-milpa-${var.cluster-name}" + "kubernetes.io/cluster/${var.cluster-name}" = "owned" + } } data "aws_availability_zones" "available-azs" { - state = "available" + state = "available" blacklisted_zone_ids = var.blacklisted-azs } resource "random_shuffle" "azs" { - input = "${data.aws_availability_zones.available-azs.names}" - result_count = "${var.number-of-subnets}" + input = data.aws_availability_zones.available-azs.names + result_count = var.number-of-subnets } resource "aws_vpc" "main" { - cidr_block = "${var.vpc-cidr}" + cidr_block = var.vpc-cidr enable_dns_hostnames = true - tags = "${local.k8s_cluster_tags}" + tags = local.k8s_cluster_tags provisioner "local-exec" { # Remove any leftover instance, security group etc Milpa created. They # would prevent terraform from destroying the VPC. - when = "destroy" - command = "./cleanup-vpc.sh ${self.id}" + when = destroy + command = "./cleanup-vpc.sh ${self.id}" interpreter = ["/bin/bash", "-c"] environment = { - "AWS_REGION" = "${var.region}" - "AWS_DEFAULT_REGION" = "${var.region}" + "AWS_REGION" = var.region + "AWS_DEFAULT_REGION" = var.region } } } resource "aws_internet_gateway" "gw" { - vpc_id = "${aws_vpc.main.id}" + vpc_id = aws_vpc.main.id - tags = "${local.k8s_cluster_tags}" + tags = local.k8s_cluster_tags provisioner "local-exec" { # Remove any leftover instance, security group etc Milpa created. They # would prevent terraform from destroying the VPC. - when = "destroy" - command = "./cleanup-vpc.sh ${self.vpc_id}" + when = destroy + command = "./cleanup-vpc.sh ${self.vpc_id}" interpreter = ["/bin/bash", "-c"] environment = { - "AWS_REGION" = "${var.region}" - "AWS_DEFAULT_REGION" = "${var.region}" + "AWS_REGION" = var.region + "AWS_DEFAULT_REGION" = var.region } } } resource "aws_subnet" "subnets" { - count = "${var.number-of-subnets}" - vpc_id = "${aws_vpc.main.id}" - cidr_block = "${cidrsubnet("${var.vpc-cidr}", 4, "${count.index+1}")}" - availability_zone = "${element("${random_shuffle.azs.result}", count.index)}" + count = var.number-of-subnets + vpc_id = aws_vpc.main.id + cidr_block = cidrsubnet(var.vpc-cidr, 4, count.index + 1) + availability_zone = element(random_shuffle.azs.result, count.index) map_public_ip_on_launch = true - tags = "${local.k8s_cluster_tags}" + tags = local.k8s_cluster_tags } resource "aws_route_table" "route-table" { - vpc_id = "${aws_vpc.main.id}" + vpc_id = aws_vpc.main.id route { cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.gw.id}" + gateway_id = aws_internet_gateway.gw.id } - depends_on = ["aws_internet_gateway.gw"] + depends_on = [aws_internet_gateway.gw] - tags = "${local.k8s_cluster_tags}" + tags = local.k8s_cluster_tags lifecycle { - ignore_changes = ["route"] + ignore_changes = [route] } } resource "aws_route_table_association" "route-table-to-subnets" { - count = "${var.number-of-subnets}" - subnet_id = "${aws_subnet.subnets.*.id[count.index]}" - route_table_id = "${aws_route_table.route-table.id}" + count = var.number-of-subnets + subnet_id = aws_subnet.subnets[count.index].id + route_table_id = aws_route_table.route-table.id } resource "aws_security_group" "kubernetes" { - name = "kubernetes" + name = "kubernetes" description = "Allow inbound ssh traffic" - vpc_id = "${aws_vpc.main.id}" + vpc_id = aws_vpc.main.id ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" + from_port = 22 + to_port = 22 + protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["${var.vpc-cidr}"] + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = [var.vpc-cidr] } ingress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["${var.pod-cidr}"] + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = [var.pod-cidr] } egress { - from_port = 0 - to_port = 0 - protocol = "-1" + from_port = 0 + to_port = 0 + protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } - tags = "${local.k8s_cluster_tags}" + tags = local.k8s_cluster_tags } resource "aws_iam_role" "k8s-master" { - name = "k8s-master-${var.cluster-name}" + name = "k8s-master-${var.cluster-name}" assume_role_policy = <