From 0bd27f068d02ccb839bdeeb0d858c243979a7371 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Wed, 21 Dec 2016 15:10:01 -0800 Subject: [PATCH] ILB example instances no longer have external IPs --- .../google-internal-load-balancing/main.tf | 56 +++++++------------ .../google-internal-load-balancing/startup.sh | 10 ++++ 2 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 examples/google-internal-load-balancing/startup.sh diff --git a/examples/google-internal-load-balancing/main.tf b/examples/google-internal-load-balancing/main.tf index 0cdc32da7..f19d5d97b 100644 --- a/examples/google-internal-load-balancing/main.tf +++ b/examples/google-internal-load-balancing/main.tf @@ -65,15 +65,11 @@ resource "google_compute_instance" "ilb-instance-1" { } } - metadata_startup_script = <

ilb-instance-1

' | tee /var/www/html/index.html -EOF + service_account { + scopes = ["compute-rw"] + } + + metadata_startup_script = "${file("startup.sh")}" } resource "google_compute_instance" "ilb-instance-2" { @@ -94,15 +90,11 @@ resource "google_compute_instance" "ilb-instance-2" { } } - metadata_startup_script = <

ilb-instance-2

' | tee /var/www/html/index.html -EOF + service_account { + scopes = ["compute-rw"] + } + + metadata_startup_script = "${file("startup.sh")}" } resource "google_compute_instance" "ilb-instance-3" { @@ -123,15 +115,11 @@ resource "google_compute_instance" "ilb-instance-3" { } } - metadata_startup_script = <

ilb-instance-3

' | tee /var/www/html/index.html -EOF + service_account { + scopes = ["compute-rw"] + } + + metadata_startup_script = "${file("startup.sh")}" } resource "google_compute_instance" "ilb-instance-4" { @@ -152,15 +140,11 @@ resource "google_compute_instance" "ilb-instance-4" { } } - metadata_startup_script = <

ilb-instance-4

' | tee /var/www/html/index.html -EOF + service_account { + scopes = ["compute-rw"] + } + + metadata_startup_script = "${file("startup.sh")}" } resource "google_compute_instance_group" "us-ig1" { diff --git a/examples/google-internal-load-balancing/startup.sh b/examples/google-internal-load-balancing/startup.sh new file mode 100644 index 000000000..d2b099f55 --- /dev/null +++ b/examples/google-internal-load-balancing/startup.sh @@ -0,0 +1,10 @@ +#! /bin/bash +apt-get update +apt-get install apache2 -y +a2ensite default-ssl +a2enmod ssl +service apache2 restart +INSTANCE_NAME=`curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/hostname | awk -F "." '{print $1}'` +ZONE=`curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/zone | awk -F "/" '{print $NF}'` +echo '

'$INSTANCE_NAME'

' | tee /var/www/html/index.html +gcloud compute instances delete-access-config $INSTANCE_NAME --zone $ZONE