Provision a Compute Engine Instance in GCP

In the "Code Editor" tab, edit the following files:

  • variables.tf: Define input variables project_id (string, no default), region (string, default: us-central1), vm_name (string, default: my-vm), and machine_type (string, default: e2-micro), each with appropriate descriptions.
  • outputs.tf: Define outputs vm_instance_name (VM name) and vm_external_ip (VM external IP).
  • main.tf: Configure a Compute Engine VM using the defined variables, with the debian-cloud/debian-11 image, connected to the default VPC network.
  • terraform.tfvars: Set project_id = "my-gcp-project".

The provider.tf file is pre-configured and read-only.

GitOps Repository

  • 📁 /root/learn-terraform-gcp-compute-engine
    • 📄 provider.tf
    • 📄 main.tf
    • 📄 variables.tf
    • 📄 outputs.tf
    • 📄 terraform.tfvars

Code Editor

Terminal