Deployment Manager as native IaC in GCP - Time & Space Complexity
When using Deployment Manager to create cloud resources, it's important to know how the time to deploy grows as you add more resources.
We want to understand how the number of resources affects the deployment time and API calls.
Analyze the time complexity of deploying multiple resources using Deployment Manager.
resources:
- name: vm-instance-1
type: compute.v1.instance
properties:
zone: us-central1-a
machineType: zones/us-central1-a/machineTypes/n1-standard-1
- name: vm-instance-2
type: compute.v1.instance
properties:
zone: us-central1-a
machineType: zones/us-central1-a/machineTypes/n1-standard-1
# ... repeated for n instances
This configuration creates multiple virtual machine instances, each defined as a separate resource.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating each VM instance via the Compute Engine API.
- How many times: Once per resource, so n times for n instances.
Each additional resource adds one more API call to create it, so the total work grows directly with the number of resources.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls grows linearly as you add more resources.
Time Complexity: O(n)
This means the deployment time grows in direct proportion to the number of resources you define.
[X] Wrong: "Adding more resources won't affect deployment time much because Deployment Manager handles everything at once."
[OK] Correct: Each resource requires its own API call and provisioning, so more resources mean more work and longer deployment time.
Understanding how deployment time scales with resource count helps you design efficient infrastructure and explain trade-offs clearly in real projects.
"What if Deployment Manager supported batching multiple resource creations in a single API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand Deployment Manager's role
Deployment Manager lets you write code to define cloud resources instead of manual setup.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.Final Answer:
To define and manage cloud resources using code -> Option AQuick Check:
Deployment Manager = Infrastructure as Code [OK]
- Confusing Deployment Manager with monitoring tools
- Thinking it is a manual console tool
- Mixing it with billing or cost tools
Solution
Step 1: Recall YAML structure for Deployment Manager
The root key to list cloud resources isresources:.Step 2: Check other options
Options likedeployments:,instances:, andservices:are not valid root keys in Deployment Manager YAML.Final Answer:
resources: -> Option BQuick Check:
YAML starts with resources: [OK]
- Using wrong root keys like deployments or instances
- Confusing resource types with YAML structure
- Starting with service names instead of resources
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?
Solution
Step 1: Identify resource type
The typecompute.v1.instancemeans a virtual machine (VM) instance.Step 2: Check properties
The zone and machineType confirm it's a VM in zone us-central1-a with a standard machine type.Final Answer:
A virtual machine instance in zone us-central1-a -> Option DQuick Check:
compute.v1.instance = VM instance [OK]
- Confusing instance with storage or database
- Ignoring the type field
- Assuming default zone without checking properties
resources:
- name: my-vm
type: compute.v1.instance
properties:
zone: us-central1-a
machineType: n1-standard-1
Why does deployment fail?
Solution
Step 1: Check machineType format
machineType must include full path with zone prefix like zones/us-central1-a/machineTypes/n1-standard-1.Step 2: Validate other fields
zone is valid, name is allowed, and type is current. Only machineType format is wrong.Final Answer:
machineType property is missing zone prefix -> Option CQuick Check:
machineType needs full path [OK]
- Using short machineType without zone prefix
- Changing name to fix error
- Assuming type is deprecated
Solution
Step 1: Understand YAML resource listing
Deployment Manager YAML supports multiple resources by listing each with a unique name underresources:.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.Final Answer:
List two separate resource entries under resources with different names -> Option AQuick Check:
Multiple resources = multiple entries [OK]
- Trying to name one resource with multiple names
- Expecting loops inside YAML
- Splitting into multiple files unnecessarily
Ready to prove it?
Pass the test and this pattern moves unknown
