📖 Scenario: You are working as a cloud engineer for a company moving their infrastructure to Google Cloud Platform (GCP). Your team needs to decide whether to use Terraform or Google Cloud Deployment Manager to manage infrastructure as code.Both tools help automate resource creation, but they have differences in flexibility, community support, and integration.
🎯 Goal: Build a simple comparison dictionary in Python that lists key features of Terraform and Deployment Manager. Then, add a configuration variable to select the preferred tool. Finally, write logic to print the chosen tool's features.
📋 What You'll Learn
Create a dictionary named tools with keys 'Terraform' and 'Deployment Manager' and their feature descriptions as values.
Add a variable named preferred_tool set to either 'Terraform' or 'Deployment Manager'.
Write a for loop that iterates over tools.items() and prints the features of the preferred_tool.
Add a final print statement confirming the selected tool.
💡 Why This Matters
🌍 Real World
Cloud engineers often compare infrastructure as code tools to choose the best fit for their projects. Automating this comparison helps in decision making.
💼 Career
Understanding how to manage and compare cloud infrastructure tools is essential for roles like Cloud Engineer, DevOps Engineer, and Site Reliability Engineer.
Progress0 / 4 steps
1
Create the tools dictionary
Create a dictionary called tools with these exact entries: 'Terraform' mapped to 'Open-source, multi-cloud, large community' and 'Deployment Manager' mapped to 'GCP native, YAML/JSON configs, integrates with GCP services'.
GCP
Hint
Use curly braces {} to create a dictionary with the exact keys and values.
2
Add preferred tool variable
Add a variable called preferred_tool and set it to the string 'Terraform'.
GCP
Hint
Assign the string 'Terraform' to the variable preferred_tool.
3
Write loop to print preferred tool features
Write a for loop using variables tool and features to iterate over tools.items(). Inside the loop, use an if statement to check if tool equals preferred_tool. If yes, print the string f"Features of {tool}: {features}".
GCP
Hint
Use for tool, features in tools.items(): and inside it check if tool == preferred_tool:.
4
Add final confirmation print
Add a print statement that outputs f"Selected tool: {preferred_tool}" to confirm the choice.
GCP
Hint
Use a print statement with an f-string to show the selected tool.
Practice
(1/5)
1. Which tool is best described as Google Cloud's native infrastructure management service?
easy
A. Deployment Manager
B. Terraform
C. Ansible
D. Chef
Solution
Step 1: Understand native tools in GCP
Deployment Manager is built by Google specifically for managing GCP resources.
Step 2: Compare with other tools
Terraform is multi-cloud and not native to GCP, while Ansible and Chef are configuration management tools, not native GCP infrastructure managers.
Final Answer:
Deployment Manager -> Option A
Quick Check:
Native GCP tool = Deployment Manager [OK]
Hint: Native GCP tool means Deployment Manager [OK]
Common Mistakes:
Confusing Terraform as native to GCP
Mixing configuration tools with infrastructure tools
Assuming multi-cloud tools are native
2. Which syntax snippet correctly initializes a Terraform configuration for Google Cloud?
easy
A. resource "gcp_project" { name = "my-project" }
B. provider "google" { project = "my-project" region = "us-central1" }
C. deployment "my-deployment" { config: "config.yaml" }
D. service "google" { project = "my-project" }
Solution
Step 1: Identify Terraform provider syntax
Terraform uses the keyword 'provider' with the provider name and configuration inside curly braces.
Step 2: Check other options
resource "gcp_project" { name = "my-project" } uses incorrect resource type, C is Deployment Manager style, D uses invalid keyword 'service'.
Final Answer:
provider "google" { project = "my-project" region = "us-central1" } -> Option B
4. You wrote a Deployment Manager config but get an error: Invalid resource type. What is the most likely cause?
medium
A. Missing project ID in the config file
B. Not enabling the Compute Engine API
C. Incorrect indentation in YAML file
D. Using a Terraform resource type in Deployment Manager config
Solution
Step 1: Understand resource types in Deployment Manager
Deployment Manager requires resource types specific to GCP and its own syntax, not Terraform resource types.
Step 2: Identify error cause
Using Terraform resource types in Deployment Manager config causes 'Invalid resource type' error.
Final Answer:
Using a Terraform resource type in Deployment Manager config -> Option D
Quick Check:
Resource types must match tool syntax [OK]
Hint: Use correct resource types per tool [OK]
Common Mistakes:
Confusing Terraform and Deployment Manager resource types
Ignoring API enablement errors
Assuming YAML indentation causes resource type errors
5. Your team needs to manage infrastructure across multiple clouds with a single tool and prefers simple, readable syntax. Which tool should you choose?
hard
A. Deployment Manager because it is native to GCP
B. Use Deployment Manager with custom scripts for multi-cloud
C. Terraform because it supports multiple clouds and has simple syntax
D. Manual scripting with gcloud CLI for flexibility
Solution
Step 1: Analyze multi-cloud support
Deployment Manager only supports GCP, so it cannot manage multiple clouds.
Step 2: Consider syntax and team preference
Terraform supports multiple clouds and uses simple, readable syntax, fitting team needs.
Step 3: Evaluate other options
Manual scripting is error-prone and less maintainable; Deployment Manager with scripts is complex and limited to GCP.
Final Answer:
Terraform because it supports multiple clouds and has simple syntax -> Option C
Quick Check:
Multi-cloud + simple syntax = Terraform [OK]
Hint: Multi-cloud needs point to Terraform [OK]
Common Mistakes:
Choosing Deployment Manager for multi-cloud
Thinking manual scripts are simpler
Assuming Deployment Manager can be extended easily for other clouds
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.