Terraform Override Files
Step-01: Introduction
- c1-versions.tf
- c2-variables.tf
- c3-resource-group.tf
- c4-virtual-network.tf
- terraform.tfvars
- Define the same Resource Group resource with different
location
# Resource-1: Azure Resource Group
resource "azurerm_resource_group" "myrg" {
#name = var.resource_group_name
name = "${var.business_unit}-${var.environment}-${var.resoure_group_name}"
location = "westus"
}
# Change Directory
cd terraform-manifests-v1/
# Terraform Initialize
terraform init
# Terraform Validate
terraform validate
# Terraform Plan
terraform plan
# Observation
1. Review the location for all resources.
2. Location of all resources should be "westus" because it has picked the information from "override.tf"
# Clean-Up
rm -rf .terraform*
# Resource-1: Azure Resource Group
resource "azurerm_resource_group" "myrg" {
#name = var.resource_group_name
name = "${var.business_unit}-${var.environment}-${var.resoure_group_name}"
location = "westus"
}
# Change Directory
cd terraform-manifests-v2/
# Terraform Initialize
terraform init
# Terraform Validate
terraform validate
# Terraform Plan
terraform plan
# Observation
1. Review the location for all resources.
2. Location of all resources should be "westus" because it has picked the information from "c3-resource-group_override.tf"
# Clean-Up
rm -rf .terraform*
- By default if we use
.gitignore
of Terraform from github it will have override files
ignored.
- Based on need, you need to comment them in
.gitignore
if those are required and our .tf
files are checked-in to github.
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
#override.tf
#override.tf.json
#*_override.tf
#*_override.tf.json