terraform get -updateDownload and update remote module sources.
Commands and snippets for modules, providers, version constraints, registry access, and dependency management.
Install, update, and author reusable modules.
terraform get -updateDownload and update remote module sources.
Copy a module into an empty working directory and initialize it.
terraform init -from-module=git::https://github.com/acme/networking.gitCopy a module into an empty working directory and initialize it.
Use a Terraform Registry module with a version constraint.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
}Use a Terraform Registry module with a version constraint.
Use a module source from Git with a specific ref.
module "networking" {
source = "git::https://github.com/acme/networking.git?ref=v1.2.3"
}Use a module source from Git with a specific ref.
Work with provider requirements and mirrors.
Update the dependency lock file with checksums for target platforms.
terraform providers lock -platform=darwin_amd64 -platform=linux_amd64Update the dependency lock file with checksums for target platforms.
Download required providers into a local mirror directory.
terraform providers mirror ./terraform-providersDownload required providers into a local mirror directory.
Pin Terraform version and provider source/version constraints.
terraform {
required_version = ">= 1.6.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Pin Terraform version and provider source/version constraints.
Configure provider installation behavior in CLI config file.
provider_installation {
filesystem_mirror {
path = "/usr/share/terraform/providers"
include = ["registry.terraform.io/hashicorp/*"]
}
direct {}
}Configure provider installation behavior in CLI config file.
Common registry-oriented tasks and patterns.
Example of documenting reusable module outputs clearly.
output "vpc_id" {
description = "Created VPC ID"
value = aws_vpc.this.id
}Example of documenting reusable module outputs clearly.
Example of typed input variables for reusable modules.
variable "name" {
type = string
description = "Resource name prefix"
}Example of typed input variables for reusable modules.
Patterns for cleaner module and provider management.
Use moved blocks to preserve state during resource renames in configuration.
moved {
from = aws_instance.old
to = aws_instance.web
}Use moved blocks to preserve state during resource renames in configuration.
Document intentional removal of resource addresses when refactoring.
removed {
from = aws_instance.legacy
}Document intentional removal of resource addresses when refactoring.