feat(compute_instance): add standalone VM support without instance template#588
Open
AryamanParida wants to merge 3 commits into
Open
Conversation
|
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. |
0c525fb to
344f09b
Compare
…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
344f09b to
26c18c0
Compare
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
modules/compute_instancemodule only supportsgoogle_compute_instance_from_template, which requires a mandatoryinstance_template. This means the module cannot manage standaloneVMs 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_templateandgoogle_compute_instanceare completely different Terraform resource types.
Solution
Make
instance_templateoptional (default = null). Whennull:google_compute_instanceresource is created/managed instead.machine_type,boot_disk,service_account,metadata,tags, andscheduling.When
instance_templateis provided (the existing default), themodule behaves exactly as before — fully backward-compatible.
Changes
variables.tfinstance_templatedefault set tonull; 7 new optional variables added with null/empty defaultsmain.tfgoogle_compute_instance_from_templategated oninstance_template != null; newgoogle_compute_instanceresource added for standalone pathoutputs.tfvar.instance_template != nullNew variables (all optional, backward-compatible defaults)
machine_typestringboot_diskobjectsource_image,disk_size_gb,disk_type,disk_labels,kms_key_self_link,auto_delete,device_name)service_accountobjectemail+scopes)metadatamap(string)tagslist(string)schedulingobjecton_host_maintenance,automatic_restart,preemptibleUsage (new standalone path)