Courseiva
Google Cloud products, services, and solutionseasyMultiple ChoiceObjective-mapped

Cloud Digital Leader Practice Question: Google Cloud products, services, and solutions

Exhibit

Refer to the exhibit.
```
resource "google_compute_network" "vpc" {
  name                    = "my-vpc"
  auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnet" {
  name          = "my-subnet"
  network       = google_compute_network.vpc.name
  region        = "us-central1"
  ip_cidr_range = "10.0.1.0/24"
}
```

A team uses Terraform to create a VPC as shown. They now need to add a Compute Engine instance in the subnet. Which of the following correctly references the subnet?

⚠ Common exam trap

Google Cloud often tests the distinction between `network` and `subnetwork` arguments, and the trap here is that candidates confuse the subnet's `name` attribute with its `self_link`, or mistakenly think the `network` argument can accept a subnet reference.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Set `subnetwork = google_compute_subnetwork.subnet.self_link`

When adding a Compute Engine instance to a subnet in Terraform, you must use the `subnetwork` argument (not `network`) and reference the subnet's `self_link` attribute. The `google_compute_subnetwork` resource's `self_link` provides the full URI required by the instance resource to attach to the correct subnet within the VPC.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Set `network = google_compute_subnetwork.subnet.self_link`

    Why it's wrong here

    The `network` attribute of a compute instance expects a reference to a VPC network (a `google_compute_network` resource), not a subnetwork. Supplying `google_compute_subnetwork.subnet.self_link` assigns a subnet URL to the network field, causing the API to reject the request because it cannot interpret a subnetwork as a network resource. Additionally, when a subnetwork is specified, the network is implicitly derived, making this assignment both invalid and redundant. The instance would fail to create with an invalid field value error.

  • Set `subnetwork = google_compute_subnetwork.subnet.self_link`

    Why this is correct

    The `subnetwork` attribute on a `google_compute_instance` accepts the self-link of a subnet, which uniquely identifies it across projects and regions. Using the full URL returned by `self_link` (e.g., `https://www.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/subnetworks/SUBNET`) ensures Terraform and the GCP API resolve the exact subnetwork, even in shared VPC or multi-region deployments. This is the recommended and most explicit configuration; the self-link is the resource's canonical identifier.

  • Set `subnetwork = google_compute_subnetwork.subnet.name`

    Why it's wrong here

    Using only the subnet name for the `subnetwork` attribute is unreliable because subnet names are scoped to a region and not globally unique. Terraform may attempt to resolve the name, but the GCP API expects a fully-qualified self-link for resources outside the default project or when multiple regions are involved. A bare name can lead to ambiguous matches or failure with a 'resource not found' error. Therefore, you must use the self-link to guarantee the correct subnetwork is selected.

  • Set `network = google_compute_network.vpc.name` and `subnetwork = google_compute_network.vpc.self_link`

    Why it's wrong here

    This option misuses both fields: `network` should reference the VPC's self-link, not the network name alone (though a name may work if unique), and `subnetwork` must reference the subnetwork's self-link, not the VPC's self-link. By setting `subnetwork` to `google_compute_network.vpc.self_link`, you are passing a network URL into an attribute that expects a subnet URL, causing an API error. Additionally, there is no need to set `network` explicitly when `subnetwork` is correctly specified, because the subnet determines its parent VPC. This reflects confusion between the VPC and its subnets.

Visual reference

192.168.1.0 /24 256 addresses (254 usable) 192.168.1.0 /25 Subnet A 128 addr (126 usable) 192.168.1.128 /25 Subnet B 128 addr (126 usable) Borrowing 1 bit from host portion creates 2 subnets (/25)

About these practice questions

Courseiva writes every GCDL question from scratch — 829 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This GCDL practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the GCDL exam.