Bird
Raised Fist0
GCPcloud~7 mins

Deployment Manager as native IaC in GCP - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you want to create and manage Google Cloud resources automatically, Deployment Manager helps you write a file that describes what you want. It then builds and updates those resources for you, so you don't have to click around manually.
When you want to create a virtual machine and a network together in Google Cloud without clicking in the console.
When you need to update your cloud resources safely and keep track of changes over time.
When you want to share your cloud setup with teammates as a simple file.
When you want to recreate the same cloud environment multiple times easily.
When you want to avoid mistakes from manual setup by automating resource creation.
Config File - vm-deployment.yaml
vm-deployment.yaml
resources:
- name: example-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-11
    networkInterfaces:
    - network: global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

This file tells Deployment Manager to create one virtual machine named example-vm.

The type specifies a Compute Engine instance.

The properties section sets the zone, machine type, disk image, and network settings.

This file is complete and can be used to deploy a VM in Google Cloud.

Commands
This command creates a deployment named 'example-deployment' using the configuration file. It tells Google Cloud to build the VM as described.
Terminal
gcloud deployment-manager deployments create example-deployment --config vm-deployment.yaml
Expected OutputExpected
Create operation operation-1234567890abcdef started... Waiting for operation to complete... Create operation operation-1234567890abcdef completed successfully.
→
--config - Specifies the YAML file that describes the resources to create.
This command shows details about the deployment, including the resources created and their status.
Terminal
gcloud deployment-manager deployments describe example-deployment
Expected OutputExpected
name: example-deployment id: 1234567890123456789 operation: status: DONE operationType: insert targetLink: https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-vm resources: - name: example-vm type: compute.v1.instance state: COMPLETED
This command lists the VM instances filtered by the name 'example-vm' to verify the VM is running.
Terminal
gcloud compute instances list --filter="name=example-vm"
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-vm us-central1-a n1-standard-1 10.128.0.2 34.68.123.45 RUNNING
→
--filter - Filters the list to show only the VM with the specified name.
This command deletes the deployment and all resources it created, cleaning up the VM and related resources.
Terminal
gcloud deployment-manager deployments delete example-deployment
Expected OutputExpected
Delete operation operation-abcdef1234567890 started... Waiting for operation to complete... Delete operation operation-abcdef1234567890 completed successfully.
Key Concept

If you remember nothing else from this pattern, remember: Deployment Manager lets you describe your cloud resources in a file and then creates or updates them automatically.

Common Mistakes
Using incorrect indentation or syntax in the YAML file.
YAML is sensitive to spaces and structure; wrong indentation causes deployment errors.
Always use two spaces per indentation level and validate YAML syntax before deploying.
Not specifying the full machine type path in the properties.
Deployment Manager requires the full path like 'zones/us-central1-a/machineTypes/n1-standard-1' to find the machine type.
Always include the zone and full machine type path exactly as required.
Trying to deploy without enabling the Deployment Manager API in the Google Cloud project.
The API must be enabled to use Deployment Manager; otherwise, commands fail.
Enable the Deployment Manager API in the Google Cloud Console before deploying.
Summary
Write a YAML file describing the cloud resources you want to create.
Use 'gcloud deployment-manager deployments create' with the config file to deploy resources.
Check deployment status and resource details with 'gcloud deployment-manager deployments describe'.
Verify resources like VMs with specific gcloud commands such as 'gcloud compute instances list'.
Clean up resources by deleting the deployment with 'gcloud deployment-manager deployments delete'.

Practice

(1/5)
1. What is the main purpose of Google Cloud Deployment Manager?
easy
A. To define and manage cloud resources using code
B. To manually create resources through the console
C. To monitor cloud resource usage in real-time
D. To provide a graphical interface for cloud billing

Solution

  1. Step 1: Understand Deployment Manager's role

    Deployment Manager lets you write code to define cloud resources instead of manual setup.
  2. Step 2: Compare options

    Only To define and manage cloud resources using code describes defining and managing resources using code, which matches Deployment Manager's purpose.
  3. Final Answer:

    To define and manage cloud resources using code -> Option A
  4. Quick Check:

    Deployment Manager = Infrastructure as Code [OK]
Hint: Deployment Manager = write code for cloud setup [OK]
Common Mistakes:
  • Confusing Deployment Manager with monitoring tools
  • Thinking it is a manual console tool
  • Mixing it with billing or cost tools
2. Which of the following is the correct way to start a Deployment Manager YAML configuration file?
easy
A. services:
B. resources:
C. instances:
D. deployments:

Solution

  1. Step 1: Recall YAML structure for Deployment Manager

    The root key to list cloud resources is resources:.
  2. Step 2: Check other options

    Options like deployments:, instances:, and services: are not valid root keys in Deployment Manager YAML.
  3. Final Answer:

    resources: -> Option B
  4. Quick Check:

    YAML starts with resources: [OK]
Hint: Deployment Manager YAML always starts with resources: [OK]
Common Mistakes:
  • Using wrong root keys like deployments or instances
  • Confusing resource types with YAML structure
  • Starting with service names instead of resources
3. Given this Deployment Manager snippet:
resources:
- name: my-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1

What resource is being created?
medium
A. A network firewall rule
B. A storage bucket in us-central1-a
C. A SQL database instance
D. A virtual machine instance in zone us-central1-a

Solution

  1. Step 1: Identify resource type

    The type compute.v1.instance means a virtual machine (VM) instance.
  2. Step 2: Check properties

    The zone and machineType confirm it's a VM in zone us-central1-a with a standard machine type.
  3. Final Answer:

    A virtual machine instance in zone us-central1-a -> Option D
  4. Quick Check:

    compute.v1.instance = VM instance [OK]
Hint: compute.v1.instance means VM instance [OK]
Common Mistakes:
  • Confusing instance with storage or database
  • Ignoring the type field
  • Assuming default zone without checking properties
4. You wrote this Deployment Manager YAML:
resources:
- name: my-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: n1-standard-1

Why does deployment fail?
medium
A. name property cannot be my-vm
B. zone property is invalid
C. machineType property is missing zone prefix
D. type compute.v1.instance is deprecated

Solution

  1. Step 1: Check machineType format

    machineType must include full path with zone prefix like zones/us-central1-a/machineTypes/n1-standard-1.
  2. Step 2: Validate other fields

    zone is valid, name is allowed, and type is current. Only machineType format is wrong.
  3. Final Answer:

    machineType property is missing zone prefix -> Option C
  4. Quick Check:

    machineType needs full path [OK]
Hint: machineType needs full zone path like zones/zone/machineTypes/type [OK]
Common Mistakes:
  • Using short machineType without zone prefix
  • Changing name to fix error
  • Assuming type is deprecated
5. You want to create two VM instances in Deployment Manager using one YAML file. Which approach is best?
hard
A. List two separate resource entries under resources with different names
B. Create one resource with two names separated by commas
C. Use a loop inside YAML to repeat the resource
D. Write two separate YAML files and deploy them separately

Solution

  1. Step 1: Understand YAML resource listing

    Deployment Manager YAML supports multiple resources by listing each with a unique name under resources:.
  2. Step 2: Evaluate options

    List two separate resource entries under resources with different names correctly lists two resources separately. Create one resource with two names separated by commas is invalid syntax. Use a loop inside YAML to repeat the resource is not supported natively in YAML. Write two separate YAML files and deploy them separately works but is less efficient and not best practice.
  3. Final Answer:

    List two separate resource entries under resources with different names -> Option A
  4. Quick Check:

    Multiple resources = multiple entries [OK]
Hint: Multiple resources = multiple entries under resources: [OK]
Common Mistakes:
  • Trying to name one resource with multiple names
  • Expecting loops inside YAML
  • Splitting into multiple files unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard