From c45f2b7cd3f216f43e71224e45e2ec356ce5b0ac Mon Sep 17 00:00:00 2001 From: Megan Bang Date: Mon, 4 Nov 2019 13:03:20 -0600 Subject: [PATCH 1/3] update examples from 0.11 syntax to 0.12 syntax --- examples/cloud-armor/main.tf | 40 +++---- examples/cloud-armor/variables.tf | 2 +- examples/content-based-load-balancing/main.tf | 39 +++---- .../content-based-load-balancing/output.tf | 2 +- examples/endpoints-on-compute-engine/main.tf | 49 ++++---- examples/internal-load-balancing/main.tf | 72 ++++++------ examples/internal-load-balancing/output.tf | 2 +- examples/shared-vpc/main.tf | 105 +++++++++--------- examples/shared-vpc/output.tf | 2 +- examples/two-tier/main.tf | 56 +++++++--- examples/two-tier/output.tf | 7 +- examples/vpn/vpn.tf | 100 +++++++++-------- 12 files changed, 261 insertions(+), 215 deletions(-) diff --git a/examples/cloud-armor/main.tf b/examples/cloud-armor/main.tf index 28f47253df..762fde2ea2 100644 --- a/examples/cloud-armor/main.tf +++ b/examples/cloud-armor/main.tf @@ -7,10 +7,10 @@ resource "random_id" "instance_id" { # Configure the Google Cloud provider provider "google" { - credentials = "${file(var.credentials_file_path)}" - project = "${var.project_name}" - region = "${var.region}" - zone = "${var.region_zone}" + credentials = file(var.credentials_file_path) + project = var.project_name + region = var.region + zone = var.region_zone } # Set up a backend to be proxied to: @@ -26,8 +26,8 @@ resource "google_compute_instance" "cluster1" { } network_interface { - network = "default" - access_config = { + network = "default" + access_config { # Ephemeral IP } } @@ -50,7 +50,7 @@ resource "google_compute_instance_group" "webservers" { description = "An instance group for the single GCE instance" instances = [ - "${google_compute_instance.cluster1.self_link}", + google_compute_instance.cluster1.self_link, ] named_port { @@ -63,11 +63,11 @@ resource "google_compute_target_pool" "example" { name = "armor-pool" instances = [ - "${google_compute_instance.cluster1.self_link}", + google_compute_instance.cluster1.self_link, ] health_checks = [ - "${google_compute_http_health_check.health.name}", + google_compute_http_health_check.health.name, ] } @@ -87,12 +87,12 @@ resource "google_compute_backend_service" "website" { enable_cdn = false backend { - group = "${google_compute_instance_group.webservers.self_link}" + group = google_compute_instance_group.webservers.self_link } - security_policy = "${google_compute_security_policy.security-policy-1.self_link}" + security_policy = google_compute_security_policy.security-policy-1.self_link - health_checks = ["${google_compute_http_health_check.health.self_link}"] + health_checks = [google_compute_http_health_check.health.self_link] } # Cloud Armor Security policies @@ -125,7 +125,7 @@ resource "google_compute_security_policy" "security-policy-1" { versioned_expr = "SRC_IPS_V1" config { - src_ip_ranges = "${var.ip_white_list}" + src_ip_ranges = var.ip_white_list } } @@ -136,18 +136,18 @@ resource "google_compute_security_policy" "security-policy-1" { # Front end of the load balancer resource "google_compute_global_forwarding_rule" "default" { name = "armor-rule" - target = "${google_compute_target_http_proxy.default.self_link}" + target = google_compute_target_http_proxy.default.self_link port_range = "80" } resource "google_compute_target_http_proxy" "default" { - name = "armor-proxy" - url_map = "${google_compute_url_map.default.self_link}" + name = "armor-proxy" + url_map = google_compute_url_map.default.self_link } resource "google_compute_url_map" "default" { name = "armor-url-map" - default_service = "${google_compute_backend_service.website.self_link}" + default_service = google_compute_backend_service.website.self_link host_rule { hosts = ["mysite.com"] @@ -156,15 +156,15 @@ resource "google_compute_url_map" "default" { path_matcher { name = "allpaths" - default_service = "${google_compute_backend_service.website.self_link}" + default_service = google_compute_backend_service.website.self_link path_rule { paths = ["/*"] - service = "${google_compute_backend_service.website.self_link}" + service = google_compute_backend_service.website.self_link } } } output "ip" { - value = "${google_compute_global_forwarding_rule.default.ip_address}" + value = google_compute_global_forwarding_rule.default.ip_address } diff --git a/examples/cloud-armor/variables.tf b/examples/cloud-armor/variables.tf index d3967d5960..ad5cf47cc9 100644 --- a/examples/cloud-armor/variables.tf +++ b/examples/cloud-armor/variables.tf @@ -17,5 +17,5 @@ variable "credentials_file_path" { variable "ip_white_list" { description = "A list of ip addresses that can be white listed through security policies" - default = ["192.0.2.0/24"] + default = ["192.0.2.0/24"] } diff --git a/examples/content-based-load-balancing/main.tf b/examples/content-based-load-balancing/main.tf index 92122e7520..467d892a47 100644 --- a/examples/content-based-load-balancing/main.tf +++ b/examples/content-based-load-balancing/main.tf @@ -1,10 +1,10 @@ # https://cloud.google.com/compute/docs/load-balancing/http/content-based-example provider "google" { - region = "${var.region}" - project = "${var.project_name}" - credentials = "${file("${var.credentials_file_path}")}" - zone = "${var.region_zone}" + region = var.region + project = var.project_name + credentials = file(var.credentials_file_path) + zone = var.region_zone } resource "google_compute_instance" "www" { @@ -26,7 +26,7 @@ resource "google_compute_instance" "www" { } } - metadata_startup_script = "${file("scripts/install-www.sh")}" + metadata_startup_script = file("scripts/install-www.sh") service_account { scopes = ["https://www.googleapis.com/auth/compute.readonly"] @@ -52,7 +52,7 @@ resource "google_compute_instance" "www-video" { } } - metadata_startup_script = "${file("scripts/install-video.sh")}" + metadata_startup_script = file("scripts/install-video.sh") service_account { scopes = ["https://www.googleapis.com/auth/compute.readonly"] @@ -66,7 +66,7 @@ resource "google_compute_global_address" "external-address" { resource "google_compute_instance_group" "www-resources" { name = "tf-www-resources" - instances = ["${google_compute_instance.www.self_link}"] + instances = [google_compute_instance.www.self_link] named_port { name = "http" @@ -77,7 +77,7 @@ resource "google_compute_instance_group" "www-resources" { resource "google_compute_instance_group" "video-resources" { name = "tf-video-resources" - instances = ["${google_compute_instance.www-video.self_link}"] + instances = [google_compute_instance.www-video.self_link] named_port { name = "http" @@ -88,7 +88,8 @@ resource "google_compute_instance_group" "video-resources" { resource "google_compute_health_check" "health-check" { name = "tf-health-check" - http_health_check {} + http_health_check { + } } resource "google_compute_backend_service" "www-service" { @@ -96,10 +97,10 @@ resource "google_compute_backend_service" "www-service" { protocol = "HTTP" backend { - group = "${google_compute_instance_group.www-resources.self_link}" + group = google_compute_instance_group.www-resources.self_link } - health_checks = ["${google_compute_health_check.health-check.self_link}"] + health_checks = [google_compute_health_check.health-check.self_link] } resource "google_compute_backend_service" "video-service" { @@ -107,15 +108,15 @@ resource "google_compute_backend_service" "video-service" { protocol = "HTTP" backend { - group = "${google_compute_instance_group.video-resources.self_link}" + group = google_compute_instance_group.video-resources.self_link } - health_checks = ["${google_compute_health_check.health-check.self_link}"] + health_checks = [google_compute_health_check.health-check.self_link] } resource "google_compute_url_map" "web-map" { name = "tf-web-map" - default_service = "${google_compute_backend_service.www-service.self_link}" + default_service = google_compute_backend_service.www-service.self_link host_rule { hosts = ["*"] @@ -124,24 +125,24 @@ resource "google_compute_url_map" "web-map" { path_matcher { name = "tf-allpaths" - default_service = "${google_compute_backend_service.www-service.self_link}" + default_service = google_compute_backend_service.www-service.self_link path_rule { paths = ["/video", "/video/*"] - service = "${google_compute_backend_service.video-service.self_link}" + service = google_compute_backend_service.video-service.self_link } } } resource "google_compute_target_http_proxy" "http-lb-proxy" { name = "tf-http-lb-proxy" - url_map = "${google_compute_url_map.web-map.self_link}" + url_map = google_compute_url_map.web-map.self_link } resource "google_compute_global_forwarding_rule" "default" { name = "tf-http-content-gfr" - target = "${google_compute_target_http_proxy.http-lb-proxy.self_link}" - ip_address = "${google_compute_global_address.external-address.address}" + target = google_compute_target_http_proxy.http-lb-proxy.self_link + ip_address = google_compute_global_address.external-address.address port_range = "80" } diff --git a/examples/content-based-load-balancing/output.tf b/examples/content-based-load-balancing/output.tf index f9b443672f..5c958ad238 100644 --- a/examples/content-based-load-balancing/output.tf +++ b/examples/content-based-load-balancing/output.tf @@ -1,3 +1,3 @@ output "application_public_ip" { - value = "${google_compute_global_forwarding_rule.default.ip_address}" + value = google_compute_global_forwarding_rule.default.ip_address } diff --git a/examples/endpoints-on-compute-engine/main.tf b/examples/endpoints-on-compute-engine/main.tf index 4a27e2aa1b..d38b4618c4 100644 --- a/examples/endpoints-on-compute-engine/main.tf +++ b/examples/endpoints-on-compute-engine/main.tf @@ -1,9 +1,10 @@ provider "google" { - region = "${var.region}" - credentials = "${file("${var.credentials_file_path}")}" + region = var.region + credentials = file(var.credentials_file_path) } -provider "random" {} +provider "random" { +} resource "random_id" "project_name" { byte_length = 8 @@ -12,23 +13,23 @@ resource "random_id" "project_name" { resource "google_project" "endpoints_project" { name = "Endpoints Project" project_id = "tf-ep-${random_id.project_name.hex}" - org_id = "${var.org_id}" - billing_account = "${var.billing_account_id}" + org_id = var.org_id + billing_account = var.billing_account_id } resource "google_project_service" "endpoints_project" { - project = "${google_project.endpoints_project.project_id}" + project = google_project.endpoints_project.project_id service = "compute.googleapis.com" } resource "google_project_service" "endpoints_project_sm" { - project = "${google_project.endpoints_project.project_id}" + project = google_project.endpoints_project.project_id service = "servicemanagement.googleapis.com" } resource "google_endpoints_service" "endpoints_service" { service_name = "echo-api.endpoints.${google_project.endpoints_project.project_id}.cloud.goog" - project = "${google_project.endpoints_project.project_id}" + project = google_project.endpoints_project.project_id openapi_config = < Date: Mon, 4 Nov 2019 15:34:52 -0600 Subject: [PATCH 2/3] update host --- examples/two-tier/main.tf | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/examples/two-tier/main.tf b/examples/two-tier/main.tf index 4e15371e10..2f0262020f 100644 --- a/examples/two-tier/main.tf +++ b/examples/two-tier/main.tf @@ -58,21 +58,7 @@ resource "google_compute_instance" "www" { destination = var.install_script_dest_path connection { - host = coalesce( # Simplify this to reference a specific desired IP address, if possible. - concat( - # Prefer any available NAT IP address - flatten([ - for ni in self.network_interface : [ - for ac in ni.access_config : ac.nat_ip - ] - ]), - - # Otherwise, use the first available LAN IP address - [ - for ni in self.network_interface : ni.network_ip - ], - )... - ) + host = self.network_interface.0.access_config.0.nat_ip type = "ssh" user = "root" private_key = file(var.private_key_path) @@ -82,21 +68,7 @@ resource "google_compute_instance" "www" { provisioner "remote-exec" { connection { - host = coalesce( # Simplify this to reference a specific desired IP address, if possible. - concat( - # Prefer any available NAT IP address - flatten([ - for ni in self.network_interface : [ - for ac in ni.access_config : ac.nat_ip - ] - ]), - - # Otherwise, use the first available LAN IP address - [ - for ni in self.network_interface : ni.network_ip - ], - )... - ) + host = self.network_interface.0.access_config.0.nat_ip type = "ssh" user = "root" private_key = file(var.private_key_path) From dcd40807635a6c251b2b2515308e2183dd4a9215 Mon Sep 17 00:00:00 2001 From: Megan Bang Date: Mon, 4 Nov 2019 15:38:57 -0600 Subject: [PATCH 3/3] update spacing --- examples/two-tier/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/two-tier/main.tf b/examples/two-tier/main.tf index 2f0262020f..19a3097392 100644 --- a/examples/two-tier/main.tf +++ b/examples/two-tier/main.tf @@ -58,7 +58,7 @@ resource "google_compute_instance" "www" { destination = var.install_script_dest_path connection { - host = self.network_interface.0.access_config.0.nat_ip + host = self.network_interface.0.access_config.0.nat_ip type = "ssh" user = "root" private_key = file(var.private_key_path) @@ -68,7 +68,7 @@ resource "google_compute_instance" "www" { provisioner "remote-exec" { connection { - host = self.network_interface.0.access_config.0.nat_ip + host = self.network_interface.0.access_config.0.nat_ip type = "ssh" user = "root" private_key = file(var.private_key_path)