Skip to content

Instantly share code, notes, and snippets.

@sabrehagen
Created November 22, 2018 10:22
Show Gist options
  • Save sabrehagen/74a964e17834c5c87a27125a4069be33 to your computer and use it in GitHub Desktop.
Save sabrehagen/74a964e17834c5c87a27125a4069be33 to your computer and use it in GitHub Desktop.
> terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ google_compute_firewall.ci-host
id: <computed>
allow.#: "3"
allow.1367131964.ports.#: "0"
allow.1367131964.protocol: "icmp"
allow.3184342675.ports.#: "1"
allow.3184342675.ports.0: "2375"
allow.3184342675.protocol: "tcp"
allow.803338340.ports.#: "1"
allow.803338340.ports.0: "22"
allow.803338340.protocol: "tcp"
creation_timestamp: <computed>
destination_ranges.#: <computed>
direction: <computed>
name: "${local.environment_name}"
network: "${local.environment_name}"
priority: "1000"
project: <computed>
self_link: <computed>
source_ranges.#: <computed>
target_tags.#: "1"
target_tags.4065722285: "docker"
+ google_compute_instance.ci-host
id: <computed>
allow_stopping_for_update: "true"
boot_disk.#: "1"
boot_disk.0.auto_delete: "true"
boot_disk.0.device_name: <computed>
boot_disk.0.disk_encryption_key_sha256: <computed>
boot_disk.0.initialize_params.#: "1"
boot_disk.0.initialize_params.0.image: "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
boot_disk.0.initialize_params.0.size: <computed>
boot_disk.0.initialize_params.0.type: <computed>
can_ip_forward: "false"
cpu_platform: <computed>
create_timeout: "4"
deletion_protection: "false"
guest_accelerator.#: <computed>
instance_id: <computed>
label_fingerprint: <computed>
machine_type: "n1-highcpu-32"
metadata.%: "1"
metadata.ssh-keys: "root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5w7uoucQmkhf5Qq33KNLhRDkIp0lLw9308koFXMRs+pIndUB+Ayarc/5nlrFQNhDk49AG+9G6D3qbi3qA1LPQS4Gyl30Y52+p7NwEokbkFGnc71c8Wg5cx+KJsgBZbN3iJKXa2Q3tPeUq2SdS0tCF3nKBSgSC8EdhZL/NEut0K7y5doyyPlLK21fGTrjf+mbH8dQwn/J1P4189snQSsL/OFzOv5g1AoYG5OW1dzqNh9DFJIU7x+DhSiXXMefqQZ/TlQ4Q5rNfSr56oZSiCLcVVRNFwS7YTIvN+PqeWs9u+BYjiFtpavJiryg2CPTWxO1WdOx0LC/l6voyQ2hg3OdH root@f87b43d3ecbd\n"
metadata_fingerprint: <computed>
name: "${local.environment_name}"
network_interface.#: "1"
network_interface.0.access_config.#: "1"
network_interface.0.access_config.0.assigned_nat_ip: <computed>
network_interface.0.access_config.0.nat_ip: <computed>
network_interface.0.access_config.0.network_tier: <computed>
network_interface.0.address: <computed>
network_interface.0.name: <computed>
network_interface.0.network: "${local.environment_name}"
network_interface.0.network_ip: <computed>
network_interface.0.subnetwork_project: <computed>
project: "stemnapp"
scheduling.#: <computed>
self_link: <computed>
service_account.#: "1"
service_account.0.email: <computed>
service_account.0.scopes.#: "1"
service_account.0.scopes.1632638332: "https://www.googleapis.com/auth/devstorage.read_only"
tags.#: "1"
tags.4065722285: "docker"
tags_fingerprint: <computed>
zone: "us-west2-c"
+ google_compute_network.ci-host
id: <computed>
auto_create_subnetworks: "true"
gateway_ipv4: <computed>
name: "${local.environment_name}"
project: <computed>
routing_mode: <computed>
self_link: <computed>
+ random_id.instance_id
id: <computed>
b64: <computed>
b64_std: <computed>
b64_url: <computed>
byte_length: "8"
dec: <computed>
hex: <computed>
Plan: 4 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
random_id.instance_id: Creating...
b64: "" => "<computed>"
b64_std: "" => "<computed>"
b64_url: "" => "<computed>"
byte_length: "" => "8"
dec: "" => "<computed>"
hex: "" => "<computed>"
random_id.instance_id: Creation complete after 0s (ID: URq-HvQPgRE)
google_compute_network.ci-host: Creating...
auto_create_subnetworks: "" => "true"
gateway_ipv4: "" => "<computed>"
name: "" => "stemn-ci-511abe1ef40f8111"
project: "" => "<computed>"
routing_mode: "" => "<computed>"
self_link: "" => "<computed>"
google_compute_firewall.ci-host: Creating...
allow.#: "" => "3"
allow.1367131964.ports.#: "" => "0"
allow.1367131964.protocol: "" => "icmp"
allow.3184342675.ports.#: "" => "1"
allow.3184342675.ports.0: "" => "2375"
allow.3184342675.protocol: "" => "tcp"
allow.803338340.ports.#: "" => "1"
allow.803338340.ports.0: "" => "22"
allow.803338340.protocol: "" => "tcp"
creation_timestamp: "" => "<computed>"
destination_ranges.#: "" => "<computed>"
direction: "" => "<computed>"
name: "" => "stemn-ci-511abe1ef40f8111"
network: "" => "stemn-ci-511abe1ef40f8111"
priority: "" => "1000"
project: "" => "<computed>"
self_link: "" => "<computed>"
source_ranges.#: "" => "<computed>"
target_tags.#: "" => "1"
target_tags.4065722285: "" => "docker"
google_compute_instance.ci-host: Creating...
allow_stopping_for_update: "" => "true"
boot_disk.#: "" => "1"
boot_disk.0.auto_delete: "" => "true"
boot_disk.0.device_name: "" => "<computed>"
boot_disk.0.disk_encryption_key_sha256: "" => "<computed>"
boot_disk.0.initialize_params.#: "" => "1"
boot_disk.0.initialize_params.0.image: "" => "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
boot_disk.0.initialize_params.0.size: "" => "<computed>"
boot_disk.0.initialize_params.0.type: "" => "<computed>"
can_ip_forward: "" => "false"
cpu_platform: "" => "<computed>"
create_timeout: "" => "4"
deletion_protection: "" => "false"
guest_accelerator.#: "" => "<computed>"
instance_id: "" => "<computed>"
label_fingerprint: "" => "<computed>"
machine_type: "" => "n1-highcpu-32"
metadata.%: "" => "1"
metadata.ssh-keys: "" => "root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5w7uoucQmkhf5Qq33KNLhRDkIp0lLw9308koFXMRs+pIndUB+Ayarc/5nlrFQNhDk49AG+9G6D3qbi3qA1LPQS4Gyl30Y52+p7NwEokbkFGnc71c8Wg5cx+KJsgBZbN3iJKXa2Q3tPeUq2SdS0tCF3nKBSgSC8EdhZL/NEut0K7y5doyyPlLK21fGTrjf+mbH8dQwn/J1P4189snQSsL/OFzOv5g1AoYG5OW1dzqNh9DFJIU7x+DhSiXXMefqQZ/TlQ4Q5rNfSr56oZSiCLcVVRNFwS7YTIvN+PqeWs9u+BYjiFtpavJiryg2CPTWxO1WdOx0LC/l6voyQ2hg3OdH root@f87b43d3ecbd\n"
metadata_fingerprint: "" => "<computed>"
name: "" => "stemn-ci-511abe1ef40f8111"
network_interface.#: "" => "1"
network_interface.0.access_config.#: "" => "1"
network_interface.0.access_config.0.assigned_nat_ip: "" => "<computed>"
network_interface.0.access_config.0.nat_ip: "" => "<computed>"
network_interface.0.access_config.0.network_tier: "" => "<computed>"
network_interface.0.address: "" => "<computed>"
network_interface.0.name: "" => "<computed>"
network_interface.0.network: "" => "stemn-ci-511abe1ef40f8111"
network_interface.0.network_ip: "" => "<computed>"
network_interface.0.subnetwork_project: "" => "<computed>"
project: "" => "stemnapp"
scheduling.#: "" => "<computed>"
self_link: "" => "<computed>"
service_account.#: "" => "1"
service_account.0.email: "" => "<computed>"
service_account.0.scopes.#: "" => "1"
service_account.0.scopes.1632638332: "" => "https://www.googleapis.com/auth/devstorage.read_only"
tags.#: "" => "1"
tags.4065722285: "" => "docker"
tags_fingerprint: "" => "<computed>"
zone: "" => "us-west2-c"
google_compute_network.ci-host: Still creating... (10s elapsed)
google_compute_network.ci-host: Still creating... (20s elapsed)
google_compute_network.ci-host: Still creating... (30s elapsed)
google_compute_network.ci-host: Creation complete after 40s (ID: stemn-ci-511abe1ef40f8111)
Error: Error applying plan:
2 error(s) occurred:
* google_compute_firewall.ci-host: 1 error(s) occurred:
* google_compute_firewall.ci-host: Error creating Firewall: googleapi: Error 404: The resource 'projects/stemnapp/global/networks/stemn-ci-511abe1ef40f8111' was not found, notFound
* google_compute_instance.ci-host: 1 error(s) occurred:
* google_compute_instance.ci-host: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0]': ''. No default subnetwork was found in the region of the instance., invalid
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
➜ ci-host git:(sync-route-typing) ✗ terraform apply
random_id.instance_id: Refreshing state... (ID: URq-HvQPgRE)
google_compute_network.ci-host: Refreshing state... (ID: stemn-ci-511abe1ef40f8111)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ google_compute_firewall.ci-host
id: <computed>
allow.#: "3"
allow.1367131964.ports.#: "0"
allow.1367131964.protocol: "icmp"
allow.3184342675.ports.#: "1"
allow.3184342675.ports.0: "2375"
allow.3184342675.protocol: "tcp"
allow.803338340.ports.#: "1"
allow.803338340.ports.0: "22"
allow.803338340.protocol: "tcp"
creation_timestamp: <computed>
destination_ranges.#: <computed>
direction: <computed>
name: "stemn-ci-511abe1ef40f8111"
network: "stemn-ci-511abe1ef40f8111"
priority: "1000"
project: <computed>
self_link: <computed>
source_ranges.#: <computed>
target_tags.#: "1"
target_tags.4065722285: "docker"
+ google_compute_instance.ci-host
id: <computed>
allow_stopping_for_update: "true"
boot_disk.#: "1"
boot_disk.0.auto_delete: "true"
boot_disk.0.device_name: <computed>
boot_disk.0.disk_encryption_key_sha256: <computed>
boot_disk.0.initialize_params.#: "1"
boot_disk.0.initialize_params.0.image: "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
boot_disk.0.initialize_params.0.size: <computed>
boot_disk.0.initialize_params.0.type: <computed>
can_ip_forward: "false"
cpu_platform: <computed>
create_timeout: "4"
deletion_protection: "false"
guest_accelerator.#: <computed>
instance_id: <computed>
label_fingerprint: <computed>
machine_type: "n1-highcpu-32"
metadata.%: "1"
metadata.ssh-keys: "root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5w7uoucQmkhf5Qq33KNLhRDkIp0lLw9308koFXMRs+pIndUB+Ayarc/5nlrFQNhDk49AG+9G6D3qbi3qA1LPQS4Gyl30Y52+p7NwEokbkFGnc71c8Wg5cx+KJsgBZbN3iJKXa2Q3tPeUq2SdS0tCF3nKBSgSC8EdhZL/NEut0K7y5doyyPlLK21fGTrjf+mbH8dQwn/J1P4189snQSsL/OFzOv5g1AoYG5OW1dzqNh9DFJIU7x+DhSiXXMefqQZ/TlQ4Q5rNfSr56oZSiCLcVVRNFwS7YTIvN+PqeWs9u+BYjiFtpavJiryg2CPTWxO1WdOx0LC/l6voyQ2hg3OdH root@f87b43d3ecbd\n"
metadata_fingerprint: <computed>
name: "stemn-ci-511abe1ef40f8111"
network_interface.#: "1"
network_interface.0.access_config.#: "1"
network_interface.0.access_config.0.assigned_nat_ip: <computed>
network_interface.0.access_config.0.nat_ip: <computed>
network_interface.0.access_config.0.network_tier: <computed>
network_interface.0.address: <computed>
network_interface.0.name: <computed>
network_interface.0.network: "stemn-ci-511abe1ef40f8111"
network_interface.0.network_ip: <computed>
network_interface.0.subnetwork_project: <computed>
project: "stemnapp"
scheduling.#: <computed>
self_link: <computed>
service_account.#: "1"
service_account.0.email: <computed>
service_account.0.scopes.#: "1"
service_account.0.scopes.1632638332: "https://www.googleapis.com/auth/devstorage.read_only"
tags.#: "1"
tags.4065722285: "docker"
tags_fingerprint: <computed>
zone: "us-west2-c"
Plan: 2 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
google_compute_firewall.ci-host: Creating...
allow.#: "" => "3"
allow.1367131964.ports.#: "" => "0"
allow.1367131964.protocol: "" => "icmp"
allow.3184342675.ports.#: "" => "1"
allow.3184342675.ports.0: "" => "2375"
allow.3184342675.protocol: "" => "tcp"
allow.803338340.ports.#: "" => "1"
allow.803338340.ports.0: "" => "22"
allow.803338340.protocol: "" => "tcp"
creation_timestamp: "" => "<computed>"
destination_ranges.#: "" => "<computed>"
direction: "" => "<computed>"
name: "" => "stemn-ci-511abe1ef40f8111"
network: "" => "stemn-ci-511abe1ef40f8111"
priority: "" => "1000"
project: "" => "<computed>"
self_link: "" => "<computed>"
source_ranges.#: "" => "<computed>"
target_tags.#: "" => "1"
target_tags.4065722285: "" => "docker"
google_compute_instance.ci-host: Creating...
allow_stopping_for_update: "" => "true"
boot_disk.#: "" => "1"
boot_disk.0.auto_delete: "" => "true"
boot_disk.0.device_name: "" => "<computed>"
boot_disk.0.disk_encryption_key_sha256: "" => "<computed>"
boot_disk.0.initialize_params.#: "" => "1"
boot_disk.0.initialize_params.0.image: "" => "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
boot_disk.0.initialize_params.0.size: "" => "<computed>"
boot_disk.0.initialize_params.0.type: "" => "<computed>"
can_ip_forward: "" => "false"
cpu_platform: "" => "<computed>"
create_timeout: "" => "4"
deletion_protection: "" => "false"
guest_accelerator.#: "" => "<computed>"
instance_id: "" => "<computed>"
label_fingerprint: "" => "<computed>"
machine_type: "" => "n1-highcpu-32"
metadata.%: "" => "1"
metadata.ssh-keys: "" => "root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5w7uoucQmkhf5Qq33KNLhRDkIp0lLw9308koFXMRs+pIndUB+Ayarc/5nlrFQNhDk49AG+9G6D3qbi3qA1LPQS4Gyl30Y52+p7NwEokbkFGnc71c8Wg5cx+KJsgBZbN3iJKXa2Q3tPeUq2SdS0tCF3nKBSgSC8EdhZL/NEut0K7y5doyyPlLK21fGTrjf+mbH8dQwn/J1P4189snQSsL/OFzOv5g1AoYG5OW1dzqNh9DFJIU7x+DhSiXXMefqQZ/TlQ4Q5rNfSr56oZSiCLcVVRNFwS7YTIvN+PqeWs9u+BYjiFtpavJiryg2CPTWxO1WdOx0LC/l6voyQ2hg3OdH root@f87b43d3ecbd\n"
metadata_fingerprint: "" => "<computed>"
name: "" => "stemn-ci-511abe1ef40f8111"
network_interface.#: "" => "1"
network_interface.0.access_config.#: "" => "1"
network_interface.0.access_config.0.assigned_nat_ip: "" => "<computed>"
network_interface.0.access_config.0.nat_ip: "" => "<computed>"
network_interface.0.access_config.0.network_tier: "" => "<computed>"
network_interface.0.address: "" => "<computed>"
network_interface.0.name: "" => "<computed>"
network_interface.0.network: "" => "stemn-ci-511abe1ef40f8111"
network_interface.0.network_ip: "" => "<computed>"
network_interface.0.subnetwork_project: "" => "<computed>"
project: "" => "stemnapp"
scheduling.#: "" => "<computed>"
self_link: "" => "<computed>"
service_account.#: "" => "1"
service_account.0.email: "" => "<computed>"
service_account.0.scopes.#: "" => "1"
service_account.0.scopes.1632638332: "" => "https://www.googleapis.com/auth/devstorage.read_only"
tags.#: "" => "1"
tags.4065722285: "" => "docker"
tags_fingerprint: "" => "<computed>"
zone: "" => "us-west2-c"
google_compute_firewall.ci-host: Still creating... (10s elapsed)
google_compute_instance.ci-host: Still creating... (10s elapsed)
google_compute_firewall.ci-host: Creation complete after 13s (ID: stemn-ci-511abe1ef40f8111)
google_compute_instance.ci-host: Provisioning with 'remote-exec'...
google_compute_instance.ci-host (remote-exec): Connecting to remote host via SSH...
google_compute_instance.ci-host (remote-exec): Host: 35.236.31.88
google_compute_instance.ci-host (remote-exec): User: root
google_compute_instance.ci-host (remote-exec): Password: false
google_compute_instance.ci-host (remote-exec): Private key: true
google_compute_instance.ci-host (remote-exec): SSH Agent: false
google_compute_instance.ci-host (remote-exec): Checking Host Key: false
google_compute_instance.ci-host: Still creating... (20s elapsed)
google_compute_instance.ci-host (remote-exec): Connecting to remote host via SSH...
google_compute_instance.ci-host (remote-exec): Host: 35.236.31.88
google_compute_instance.ci-host (remote-exec): User: root
google_compute_instance.ci-host (remote-exec): Password: false
google_compute_instance.ci-host (remote-exec): Private key: true
google_compute_instance.ci-host (remote-exec): SSH Agent: false
google_compute_instance.ci-host (remote-exec): Checking Host Key: false
google_compute_instance.ci-host (remote-exec): Connecting to remote host via SSH...
google_compute_instance.ci-host (remote-exec): Host: 35.236.31.88
google_compute_instance.ci-host (remote-exec): User: root
google_compute_instance.ci-host (remote-exec): Password: false
google_compute_instance.ci-host (remote-exec): Private key: true
google_compute_instance.ci-host (remote-exec): SSH Agent: false
google_compute_instance.ci-host (remote-exec): Checking Host Key: false
google_compute_instance.ci-host (remote-exec): Connecting to remote host via SSH...
google_compute_instance.ci-host (remote-exec): Host: 35.236.31.88
google_compute_instance.ci-host (remote-exec): User: root
google_compute_instance.ci-host (remote-exec): Password: false
google_compute_instance.ci-host (remote-exec): Private key: true
google_compute_instance.ci-host (remote-exec): SSH Agent: false
google_compute_instance.ci-host (remote-exec): Checking Host Key: false
google_compute_instance.ci-host: Still creating... (30s elapsed)
google_compute_instance.ci-host (remote-exec): Connecting to remote host via SSH...
google_compute_instance.ci-host (remote-exec): Host: 35.236.31.88
google_compute_instance.ci-host (remote-exec): User: root
google_compute_instance.ci-host (remote-exec): Password: false
google_compute_instance.ci-host (remote-exec): Private key: true
google_compute_instance.ci-host (remote-exec): SSH Agent: false
google_compute_instance.ci-host (remote-exec): Checking Host Key: false
google_compute_instance.ci-host (remote-exec): Connected!
google_compute_instance.ci-host: Still creating... (40s elapsed)
google_compute_instance.ci-host (remote-exec): /tmp/terraform_1659587624.sh: 2: /tmp/terraform_1659587624.sh: cannot create /etc/docker/daemon.json: Directory nonexistent
google_compute_instance.ci-host (remote-exec): # Executing docker install script, commit: 46dc063
google_compute_instance.ci-host (remote-exec): + sh -c apt-get update -qq >/dev/null
google_compute_instance.ci-host: Still creating... (50s elapsed)
google_compute_instance.ci-host (remote-exec): + sh -c apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
google_compute_instance.ci-host: Still creating... (1m0s elapsed)
google_compute_instance.ci-host (remote-exec): + sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
google_compute_instance.ci-host (remote-exec): + sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty edge" > /etc/apt/sources.list.d/docker.list
google_compute_instance.ci-host (remote-exec): + [ ubuntu = debian ]
google_compute_instance.ci-host (remote-exec): + sh -c apt-get update -qq >/dev/null
google_compute_instance.ci-host (remote-exec): + sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
google_compute_instance.ci-host: Still creating... (1m10s elapsed)
google_compute_instance.ci-host (remote-exec): + sh -c docker version
google_compute_instance.ci-host (remote-exec): Client:
google_compute_instance.ci-host (remote-exec): Version: 18.06.1-ce
google_compute_instance.ci-host (remote-exec): API version: 1.38
google_compute_instance.ci-host (remote-exec): Go version: go1.10.3
google_compute_instance.ci-host (remote-exec): Git commit: e68fc7a
google_compute_instance.ci-host (remote-exec): Built: Tue Aug 21 17:24:58 2018
google_compute_instance.ci-host (remote-exec): OS/Arch: linux/amd64
google_compute_instance.ci-host (remote-exec): Experimental: false
google_compute_instance.ci-host (remote-exec): Server:
google_compute_instance.ci-host (remote-exec): Engine:
google_compute_instance.ci-host (remote-exec): Version: 18.06.1-ce
google_compute_instance.ci-host (remote-exec): API version: 1.38 (minimum version 1.12)
google_compute_instance.ci-host (remote-exec): Go version: go1.10.3
google_compute_instance.ci-host (remote-exec): Git commit: e68fc7a
google_compute_instance.ci-host (remote-exec): Built: Tue Aug 21 17:23:24 2018
google_compute_instance.ci-host (remote-exec): OS/Arch: linux/amd64
google_compute_instance.ci-host (remote-exec): Experimental: false
google_compute_instance.ci-host (remote-exec): If you would like to use Docker as a non-root user, you should now consider
google_compute_instance.ci-host (remote-exec): adding your user to the "docker" group with something like:
google_compute_instance.ci-host (remote-exec): sudo usermod -aG docker your-user
google_compute_instance.ci-host (remote-exec): Remember that you will have to log out and back in for this to take effect!
google_compute_instance.ci-host (remote-exec): WARNING: Adding a user to the "docker" group will grant the ability to run
google_compute_instance.ci-host (remote-exec): containers which can be used to obtain root privileges on the
google_compute_instance.ci-host (remote-exec): docker host.
google_compute_instance.ci-host (remote-exec): Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
google_compute_instance.ci-host (remote-exec): for more information.
google_compute_instance.ci-host (remote-exec): docker stop/waiting
google_compute_instance.ci-host (remote-exec): docker start/running, process 10136
google_compute_instance.ci-host: Creation complete after 1m18s (ID: stemn-ci-511abe1ef40f8111)
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
machine_endpoint = 35.236.31.88
@sabrehagen
Copy link
Author

sabrehagen commented Nov 22, 2018

resource "random_id" "instance_id" {
  byte_length = 8
}

locals {
  environment_name = "stemn-ci-${random_id.instance_id.hex}"
}
resource "google_compute_instance" "ci-host" {
  allow_stopping_for_update = true
  machine_type = "${var.machine_type}"
  name = "${local.environment_name}"
  project = "${var.gcp_project}"
  tags = ["docker"]
  zone = "${var.machine_zone}"

  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
    }
  }

  network_interface {
    network = "${local.environment_name}"
    access_config { } # Creates ephemeral IP
  }

  metadata {
    ssh-keys = "root:${file("${var.public_key_path}")}"
  }

  provisioner "remote-exec" {
    connection {
      type = "ssh"
      user = "root"
      private_key = "${file("${var.private_key_path}")}"
      agent = false
    }

    inline = [
      "curl -sSL https://get.docker.com/ | sh",
      "usermod -aG docker `echo $USER`",
      "sed -i 's;dockerd -H fd://;dockerd -H tcp://0.0.0.0:2376;' /lib/systemd/system/docker.service",
      "service docker restart",
    ]
  }

  service_account {
    scopes = ["https://www.googleapis.com/auth/devstorage.read_only"]
  }
}

resource "google_compute_firewall" "ci-host" {
  name = "${local.environment_name}"
  network = "${local.environment_name}"

  allow {
    protocol = "icmp"
  }

  allow {
    protocol = "tcp"
    ports = ["22"]
  }

  allow {
    protocol = "tcp"
    ports = ["2375"]
  }

  target_tags = ["docker"]
}

resource "google_compute_network" "ci-host" {
  name = "${local.environment_name}"
}

@petervandenabeele
Copy link

petervandenabeele commented Nov 22, 2018

So, to test the presumption, you could change lines like:

  network = "${local.environment_name}"

in the firewall and the compute-instance blocks to

   network = "${true ? local.environment_name : google_compute_network.ci-host.self_link}"

and test a full destroy and a full apply. Now, it should be successful at the first run of the apply.

@sabrehagen
Copy link
Author

I tried your fix and can confirm it works. I believe the dependency tree was lost when referencing "${local.environment_name}" rather than "${google_compute_network.ci-host.self_link}". Thank you for your assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment