Skip to content

feat(compute_instance): add standalone VM support without instance template#588

Open
AryamanParida wants to merge 3 commits into
terraform-google-modules:mainfrom
AryamanParida:feat/compute-instance-standalone
Open

feat(compute_instance): add standalone VM support without instance template#588
AryamanParida wants to merge 3 commits into
terraform-google-modules:mainfrom
AryamanParida:feat/compute-instance-standalone

Conversation

@AryamanParida

Copy link
Copy Markdown

Problem

The modules/compute_instance module only supports
google_compute_instance_from_template, which requires a mandatory
instance_template. This means the module cannot manage standalone
VMs
that were created directly (without a template) — there is no
way to import such instances into this module's state because
google_compute_instance_from_template and google_compute_instance
are completely different Terraform resource types.

Solution

Make instance_template optional (default = null). When null:

  • A google_compute_instance resource is created/managed instead.
  • New variables cover the required standalone configuration:
    machine_type, boot_disk, service_account, metadata,
    tags, and scheduling.

When instance_template is provided (the existing default), the
module behaves exactly as before — fully backward-compatible.

Changes

file what changed
variables.tf instance_template default set to null; 7 new optional variables added with null/empty defaults
main.tf google_compute_instance_from_template gated on instance_template != null; new google_compute_instance resource added for standalone path
outputs.tf All outputs coalesced via ternary on var.instance_template != null

New variables (all optional, backward-compatible defaults)

variable type description
machine_type string Machine type for standalone VMs
boot_disk object Boot disk config (source_image, disk_size_gb, disk_type, disk_labels, kms_key_self_link, auto_delete, device_name)
service_account object Service account (email + scopes)
metadata map(string) Instance metadata
tags list(string) Network tags
scheduling object on_host_maintenance, automatic_restart, preemptible

Usage (new standalone path)

module "vm" {
  source  = "terraform-google-modules/vm/google//modules/compute_instance"

  project_id   = "my-project"
  region       = "us-central1"
  zone         = "us-central1-a"
  hostname     = "my-vm"
  network      = "projects/my-project/global/networks/default"
  subnetwork   = "projects/my-project/regions/us-central1/subnetworks/default"

  machine_type = "n2-standard-4"
  boot_disk = {
    source_image = "debian-cloud/debian-12"
    disk_size_gb = 50
    disk_type    = "pd-balanced"
  }

  service_account = {
    scopes = ["cloud-platform"]
  }
}
@google-cla

google-cla Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@AryamanParida AryamanParida force-pushed the feat/compute-instance-standalone branch from 0c525fb to 344f09b Compare June 17, 2026 13:33
…mplate

Currently the module only supports google_compute_instance_from_template,
which requires a mandatory instance_template. This makes it impossible to
manage standalone VMs that were not created from a template.

Make instance_template optional (default null). When null, a
google_compute_instance resource is created using the new machine_type,
boot_disk, service_account, metadata, tags, and scheduling variables.
All new variables default to null/empty so existing callers are unaffected.

- variables.tf: instance_template default = null; add machine_type,
  boot_disk, service_account, metadata, tags, scheduling variables
- main.tf: gate google_compute_instance_from_template on
  instance_template != null; add google_compute_instance for the
  standalone path with boot_disk (initialize_params + optional CMEK),
  network_interface (reusing existing vars), service_account, and
  scheduling dynamic blocks
- outputs.tf: instances_self_links, instances_details, service_account_email,
  and instance_name coalesced via ternary on var.instance_template != null
@AryamanParida AryamanParida force-pushed the feat/compute-instance-standalone branch from 344f09b to 26c18c0 Compare June 17, 2026 13:37
…er >= 6.x

The disk_encryption_key nested block inside boot_disk of google_compute_instance
is not supported in hashicorp/google provider 7.x. Remove it to fix validation
errors when running tofu validate against provider >= 6.38. KMS key support can
be added via initialize_params.kms_key_self_link in a future additive change.
Four fixes found during drift-check against google provider 7.x:

- params block: made conditional (dynamic) so instances without
  resource_manager_tags don't force replacement
- nic_type: add variable and wire into network_interface so GVNIC
  instances can be managed without forced replacement
- lifecycle ignore_changes: suppress provider-injected noise fields
  (key_revocation_action_type, effective_labels, terraform_labels,
  attached_disk, metadata ssh-keys/startup-script, scratch_disk,
  scheduling local_ssd_recovery_timeout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant