Agent Wranglers

Infrastructure as code Recommended

Reuse versioned modules

Put each repeated pattern in a module with checked inputs, and pin every use of it to a version. Never copy the same resources between environments.

How to do it

A module is a folder of resources with named inputs and outputs. Check inputs with validation blocks. Publish shared modules with version tags, and refer to them as ?ref=v1.4.0 or with a registry version. Upgrade one environment at a time.

Example

module "web" {
  source        = "git::https://git.example.com/infra/modules.git//web?ref=v1.4.0"
  environment   = "production"
  instance_size = "m7g.large"
}

variable "environment" {
  type = string
  validation {
    condition     = contains(["staging", "production"], var.environment)
    error_message = "environment must be staging or production."
  }
}
# Fails when a remote module is used without a version tag
! grep -rnE 'source *= *"git::' infra --include=*.tf | grep -v '?ref=v[0-9]'

How to check

Every git source line holds ?ref= with a version tag, as the grep below confirms. Every registry module block has a version argument.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers infrastructure playbook: https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/versioned-modules.