refactor(compute-engine): support multiple VMs via instances map#4
Merged
Conversation
The original component hardcoded a single google_compute_instance, so the module could only ever manage one VM. Rework it to fan out over an instances map (for_each), matching the github component's pattern: per-VM spec fields carry module defaults and are overridden per entry, IAM grants fan out over member x instance, and outputs become a per-instance map. project_id and access_members gain defaults (dev project + the two engineers) since they are stable across VMs
…empty A reusable module should know how to build a VM, not where or who. Drop the dev-project default on project_id (now required — a forgotten value fails loudly instead of silently provisioning into the wrong project) and default access_members to [] (no SSH) instead of two named engineers. Cost-safe "how" defaults (e2-micro, debian-12, 20 GB) unchanged. Refresh README + CHANGELOG for this and the prior multi-VM instances-map rework. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop the dropped `compute-engine` infix; name is `<env>-<key>` (matches main.tf and README). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
@Lexxick — review follow-ups to fix (rest LGTM, Docs (2 nits, output keying):
Optional — input validation (parity with validation {
condition = alltrue([for k in keys(var.instances) : can(regex("^[a-z][a-z0-9-]*$", k))])
error_message = "Each instances key must be lowercase alphanumeric/hyphen and start with a letter (RFC1035)."
}Non-blocking. Docs worth fixing before merge; validation is your call. |
…s keys Review follow-ups from #4: - CHANGELOG/README: outputs are keyed by the map key (short name), not the full <env>-<key> VM name. - Add RFC1035 validation on instances keys so a bad key fails at plan, not apply (parity with github.repositories).
Outputs are keyed by the map key (short name), not the <env>-<key> VM name — consistency with compute-engine README + CHANGELOG.
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.
Summary
Reworks
compute-engineto manage many VMs via aninstancesmap (for_each), and stops the module from hard-coding environment identity. Mirrors thegithubcomponent'srepositoriespattern.Changes
instancesmap fanned out withfor_each. VM name =<env>-<key>(e.g.postiz→dev-postiz). Per-VM spec (machine_type,boot_image,boot_disk_size_gb,zone,assign_public_ip,startup_script,network_tags) moved into each map entry, alloptional()with cost-safe defaults.setproducton stable keys — adding a VM or member never reindexes existing grants.project_idis now required (no dev-project default → forgotten value fails loudly);access_membersdefaults to[](no SSH) instead of named engineers.instancesmap keyed by VM key (name,instance_id,internal_ip,zone,ssh_command).compute-engine/README.md+ CHANGELOG[Unreleased]updated; fixed a stale VM-name string in theinstancesvar description.Type
google_compute_instance.this→this["<key>"](IAM members too) — consumers mustterragrunt state mvor recreate, and must now setproject_id+access_membersexplicitly.How to Verify
cd compute-engine/terraform && terraform fmt -check && terraform validate→ clean.infra-environments-dev, setinstances = { ... }+project_id, runterragrunt plan— one VM per map key, no external IP, OS Login + IAP grants per member × VM.gcloud compute ssh <env>-<key> --tunnel-through-iap(frominstances[<key>].ssh_command).