📖 Scenario: You are setting up a simple Google Cloud Platform (GCP) project. You need to define resources like a Compute Engine instance and a Cloud Storage bucket using configuration files.
🎯 Goal: Build a basic GCP resource definition using configuration files that create a virtual machine and a storage bucket.
📋 What You'll Learn
Create a resource definition for a Compute Engine instance named vm-instance-1 in zone us-central1-a.
Create a resource definition for a Cloud Storage bucket named my-storage-bucket-123 in location US.
Add a configuration variable for the machine type of the Compute Engine instance.
Use the machine type variable in the Compute Engine instance resource definition.
💡 Why This Matters
🌍 Real World
Defining resources in GCP using configuration files is a common task for automating cloud infrastructure setup.
💼 Career
Cloud engineers and DevOps professionals use resource definitions to manage infrastructure as code, enabling repeatable and consistent deployments.
Progress0 / 4 steps
1
Create initial resource definitions
Create a YAML resource definition for a Compute Engine instance named vm-instance-1 in zone us-central1-a. Use the resource type compute.v1.instance, name it vm-instance-1, and set the zone property exactly as specified.
GCP
Hint
Remember to use the exact resource type compute.v1.instance, name the resource vm-instance-1, and set the zone property inside properties.
2
Add a Cloud Storage bucket resource
Add a resource definition for a Cloud Storage bucket named my-storage-bucket-123 in location US. Use the resource type storage.v1.bucket and set the name and location properties exactly as specified.
GCP
Hint
Use the resource type storage.v1.bucket and set the name and location properties inside properties.
3
Add a machine type configuration variable
Create a configuration variable called machineType and set its value to zones/us-central1-a/machineTypes/n1-standard-1. This variable will be used to specify the machine type of the Compute Engine instance.
GCP
Hint
Define a variables section at the top level and add machineType: zones/us-central1-a/machineTypes/n1-standard-1 inside it.
4
Use the machine type variable in the Compute Engine instance
Update the Compute Engine instance resource to use the machineType variable for its machineType property. Use the syntax $(machineType) to reference the variable.
GCP
Hint
Add the machineType property inside the Compute Engine instance's properties and set it to $(machineType).
Practice
(1/5)
1. What is the main purpose of a resource definition in Google Cloud Platform (GCP)?
easy
A. To manually start and stop virtual machines
B. To write application code that runs on GCP
C. To monitor the usage of cloud resources
D. To tell GCP what cloud parts to create and how to configure them
Solution
Step 1: Understand the role of resource definitions
Resource definitions specify what cloud resources to create and their settings.
Step 2: Compare options to the definition role
Only To tell GCP what cloud parts to create and how to configure them describes creating and configuring cloud parts, which matches resource definitions.
Final Answer:
To tell GCP what cloud parts to create and how to configure them -> Option D
Quick Check:
Resource definitions = create and configure cloud parts [OK]
Hint: Resource definitions describe cloud parts to create [OK]
Common Mistakes:
Confusing resource definitions with application code
Thinking resource definitions monitor usage
Believing resource definitions manually control VMs
2. Which of the following is the correct minimal structure for a GCP resource definition in YAML?
easy
A. resources:\n - name: my-vm\n type: compute.instance\n properties:\n location: us-central1-a
B. resources:\n - id: my-vm\n kind: compute.v1.instance\n settings:\n zone: us-central1-a
C. resources:\n - name: my-vm\n type: compute.v1.instance\n properties:\n zone: us-central1-a
D. resource_list:\n - name: my-vm\n type: compute.v1.instance\n properties:\n zone: us-central1-a
Solution
Step 1: Check the required keys in GCP resource definitions
GCP expects 'resources' list with each item having 'name', 'type', and 'properties'.
Step 2: Validate each option
resources:\n - name: my-vm\n type: compute.v1.instance\n properties:\n zone: us-central1-a uses correct keys and valid type 'compute.v1.instance'. Others use wrong keys like 'id', 'kind', or wrong root key 'resource_list'. resources:\n - name: my-vm\n type: compute.instance\n properties:\n location: us-central1-a uses incorrect type 'compute.instance'.
Hint: Resource names must be unique in definitions [OK]
Common Mistakes:
Ignoring duplicate names
Thinking storageClass values are invalid
Believing location is disallowed
5. You want to define a GCP resource that creates a Compute Engine VM with a specific network interface and a startup script. Which of the following resource definitions correctly includes both properties?