0
0
GCPcloud~5 mins

Terraform vs Deployment Manager decision in GCP - CLI Comparison

Choose your learning style9 modes available
Introduction
When managing cloud resources on Google Cloud Platform, you need a tool to create and update your infrastructure safely and repeatedly. Terraform and Deployment Manager are two tools that help you do this, but they work differently and suit different needs.
When you want to manage infrastructure across multiple cloud providers with one tool, use Terraform.
When you prefer a Google-native tool tightly integrated with GCP services, use Deployment Manager.
When you want to use a simple YAML or Python template to define GCP resources, Deployment Manager is a good choice.
When you want a large community, many modules, and support for many providers, Terraform is better.
When you want to keep your infrastructure as code in a single language and use advanced features like state locking, Terraform is preferred.
Commands
This command initializes a Terraform working directory, downloading necessary provider plugins and preparing the environment.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/google... - Installing hashicorp/google v4.0.0... - Installed hashicorp/google v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized!
This command applies the Terraform configuration to create or update resources without asking for confirmation.
Terminal
terraform apply -auto-approve
Expected OutputExpected
google_compute_instance.my-instance: Creating... google_compute_instance.my-instance: Creation complete after 30s [id=projects/my-project/zones/us-central1-a/instances/my-instance] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Skip interactive approval before applying changes
This command creates a deployment in GCP using Deployment Manager with the specified YAML configuration file.
Terminal
gcloud deployment-manager deployments create my-deployment --config deployment.yaml
Expected OutputExpected
Create operation operation-1234567890abcdef started... Waiting for operation to complete... Create operation operation-1234567890abcdef completed successfully.
--config - Specifies the configuration file for the deployment
This command shows details about the deployment to verify that resources were created as expected.
Terminal
gcloud deployment-manager deployments describe my-deployment
Expected OutputExpected
name: my-deployment id: 1234567890123456789 operation: operationType: insert status: DONE targetLink: https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/my-instance ...
Key Concept

If you remember nothing else from this pattern, remember: Terraform is multi-cloud and community-driven, while Deployment Manager is Google-native and simpler for GCP-only setups.

Common Mistakes
Trying to use Deployment Manager templates for non-GCP resources
Deployment Manager only supports Google Cloud resources, so it cannot manage resources outside GCP.
Use Terraform if you need to manage resources across multiple cloud providers.
Not initializing Terraform before applying configurations
Terraform needs to download providers and set up the environment; skipping init causes errors.
Always run 'terraform init' before 'terraform apply' in a new working directory.
Not specifying the correct config file with Deployment Manager
Deployment Manager requires a valid YAML or Jinja template file; missing or wrong file causes deployment failure.
Use the --config flag with the correct file path when creating or updating deployments.
Summary
Terraform works across many clouds and has a large community with reusable modules.
Deployment Manager is a Google Cloud native tool using YAML or Python templates for GCP resources.
Use 'terraform init' and 'terraform apply' to manage infrastructure with Terraform.
Use 'gcloud deployment-manager deployments create' with a config file to deploy with Deployment Manager.
Choose the tool based on your cloud environment and management needs.