Skip to content

Commit

Permalink
update examples from 0.11 syntax to 0.12 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 authored Nov 5, 2019
2 parents 90eb8ea + dcd4080 commit 1d88ac6
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 215 deletions.
40 changes: 20 additions & 20 deletions examples/cloud-armor/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,8 +26,8 @@ resource "google_compute_instance" "cluster1" {
}

network_interface {
network = "default"
access_config = {
network = "default"
access_config {
# Ephemeral IP
}
}
Expand All @@ -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 {
Expand All @@ -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,
]
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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"]
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion examples/cloud-armor/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
39 changes: 20 additions & 19 deletions examples/content-based-load-balancing/main.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -88,34 +88,35 @@ 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" {
name = "tf-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" {
name = "tf-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 = ["*"]
Expand All @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion examples/content-based-load-balancing/output.tf
Original file line number Diff line number Diff line change
@@ -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
}
49 changes: 27 additions & 22 deletions examples/endpoints-on-compute-engine/main.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = <<EOF
swagger: "2.0"
Expand Down Expand Up @@ -72,21 +73,22 @@ definitions:
type: "string"
EOF

depends_on = ["google_project_service.endpoints_project_sm"]

depends_on = [google_project_service.endpoints_project_sm]
}

resource "google_compute_network" "network" {
name = "ep-network"
auto_create_subnetworks = "true"
project = "${google_project.endpoints_project.project_id}"
depends_on = ["google_project_service.endpoints_project"]
project = google_project.endpoints_project.project_id
depends_on = [google_project_service.endpoints_project]
}

# Allow the hosted network to be hit over ICMP, SSH, and HTTP.
resource "google_compute_firewall" "network" {
name = "allow-ssh-and-icmp"
network = "${google_compute_network.network.self_link}"
project = "${google_compute_network.network.project}"
network = google_compute_network.network.self_link
project = google_compute_network.network.project

allow {
protocol = "icmp"
Expand All @@ -100,24 +102,24 @@ resource "google_compute_firewall" "network" {

resource "google_compute_instance" "project_1_vm" {
name = "tf-ep-vm"
project = "${google_project.endpoints_project.project_id}"
project = google_project.endpoints_project.project_id
machine_type = "f1-micro"
zone = "${var.region_zone}"
zone = var.region_zone

boot_disk {
initialize_params {
image = "projects/debian-cloud/global/images/family/debian-8"
}
}

metadata {
endpoints-service-name = "${google_endpoints_service.endpoints_service.service_name}"
endpoints-service-config-id = "${google_endpoints_service.endpoints_service.config_id}"
startup-script = "${file("scripts/install-vm.sh")}"
metadata = {
endpoints-service-name = google_endpoints_service.endpoints_service.service_name
endpoints-service-config-id = google_endpoints_service.endpoints_service.config_id
startup-script = file("scripts/install-vm.sh")
}

network_interface {
network = "${google_compute_firewall.network.network}"
network = google_compute_firewall.network.network

access_config {
// Ephemeral IP
Expand All @@ -128,9 +130,12 @@ resource "google_compute_instance" "project_1_vm" {
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
}

depends_on = ["google_project_service.endpoints_project_sm", "google_project_service.endpoints_project"]
depends_on = [
google_project_service.endpoints_project_sm,
google_project_service.endpoints_project,
]
}

output "ip" {
value = "${google_compute_instance.project_1_vm.network_interface.0.access_config.0.nat_ip}"
value = google_compute_instance.project_1_vm.network_interface[0].access_config[0].nat_ip
}
Loading

0 comments on commit 1d88ac6

Please sign in to comment.