Agent Wranglers

INF-6Recommended

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. Raise the pins in small steps as Update dependencies in small automatic steps says.

Examples

Terraform 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."
  }
}

Shell example

# 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.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/versioned-modules">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.