Skip to content

Add cross-variable preconditions for autoscale sizing constraints#43

Open
dmchaledev wants to merge 1 commit into
mainfrom
claude/blissful-pascal-gvlkyo
Open

Add cross-variable preconditions for autoscale sizing constraints#43
dmchaledev wants to merge 1 commit into
mainfrom
claude/blissful-pascal-gvlkyo

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

Summary

The autoscale tier variables document sizing invariants in their descriptions ("Must be between asg_min_size and asg_max_size") but didn't enforce them. A caller who sets asg_desired_capacity = 25 with asg_max_size = 20 gets a cryptic AWS provider error at apply time rather than a clear plan-time failure.

Terraform variable validation blocks can only reference the one variable being declared, so cross-variable constraints require a different mechanism. This PR uses terraform_data lifecycle precondition blocks (idiomatic Terraform ≥ 1.4, within our ≥ 1.5 floor) to add hard plan-time errors for three cross-variable invariants:

modules/unlimited-scale/aws/main.tf

  • asg_min_size ≤ asg_desired_capacity ≤ asg_max_size — AWS rejects an ASG where desired is outside [min, max]
  • db_max_allocated_storage_gb ≥ db_allocated_storage_gb — RDS autoscaling cap must be at least the initial allocation

modules/unlimited-scale/azure/main.tf

  • vmss_min_count ≤ vmss_default_count ≤ vmss_max_count — Azure VMSS rejects a default count outside [min, max]

Error messages include the actual values so the caller can fix them without digging into provider logs:

Error: Resource precondition failed
  asg_desired_capacity (25) must be between asg_min_size (3) and asg_max_size (20).

Changes

  • modules/unlimited-scale/aws/main.tf — adds terraform_data.validate_asg_sizing with two preconditions
  • modules/unlimited-scale/azure/main.tf — adds terraform_data.validate_vmss_sizing with one precondition

No variables, outputs, or resources added. No behaviour change for valid inputs. The terraform validate and tflint CI gates will exercise the new HCL.

Test plan

  • terraform validate passes in modules/unlimited-scale/aws and modules/unlimited-scale/azure
  • tflint passes with no new findings
  • Manually verify a plan with asg_desired_capacity outside [asg_min_size, asg_max_size] surfaces the precondition error at plan time
  • Manually verify a plan with db_max_allocated_storage_gb < db_allocated_storage_gb surfaces the precondition error at plan time
  • Default variable values (min=3, desired=3, max=20) pass all preconditions cleanly

Generated by Claude Code

Variable-level validation blocks can only reference the single variable being
declared, so the documented invariants — asg_desired_capacity must be between
asg_min_size and asg_max_size, and db_max_allocated_storage_gb must be at least
db_allocated_storage_gb — were enforced only by comments. A misconfigured
caller would get a cryptic provider error at apply time rather than a clear
plan-time failure.

Uses terraform_data lifecycle.precondition (Terraform >=1.4, within our >=1.5
requirement) to add two cross-variable checks to unlimited-scale/aws and one to
unlimited-scale/azure:

  - asg_min_size <= asg_desired_capacity <= asg_max_size (AWS)
  - db_max_allocated_storage_gb >= db_allocated_storage_gb (AWS)
  - vmss_min_count <= vmss_default_count <= vmss_max_count (Azure)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011wmAZG2UwZJYvunsUoDHKB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants