Using the self_link attribute
Note
The code for this section is under chap02/self-link
in the GitHub repo of this book.
In the for_each
example, we used the name
attribute of the subnetwork
resource to specify the subnet for our VM:
subnetwork = google_compute_subnetwork.this['iowa'].name
In Google Cloud, nearly every resource has a unique name, but it is better to use the self_link
attribute, which is a unique Google Cloud construct. To understand self_link
, let’s look at the details of the Iowa
subnet using the gcloud
command:
$ gcloud compute networks subnets describe iowa \ --region us-central1 .. gatewayAddress: 192.168.1.1 id: '4434945742234922953' ipCidrRange: 192.168.1.0/24 .. selfLink: https://www.googleapis.com/compute/v1/projects/tf-gcp-01/regions/us-central1/subnetworks/iowa stackType: IPV4_ONLY
Then look at the same resource using the terraform state
show
command:
$ terraform state show 'google_compute_subnetwork...