Terraform Override
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed terraform provisioner.
https://cloudaffaire.com/terraform-provisioner/
In this blog post, we will discuss terraform override.
What is Terraform Override?
Terraform loads all configuration files within a directory and appends them together. Terraform also has a concept of overrides, a way to create files that are loaded last and merged into your configuration, rather than appended. Overrides names must be override or end in _override, excluding the extension. Examples of valid override files are override.tf, override.tf.json, temp_override.tf.
Terraform Override demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
##------------------------- ## Terraform: Override ## ##------------------------- ## Create a directory and get inside it mkdir terraform && cd terraform ## Create main.tf vi main.tf --------------- #Create a VPC provider "aws" { access_key = " secret_key = " region = "ap-south-1" } resource "aws_vpc" "myvpc" { cidr_block = "10.0.0.0/16" tags { Name = "myvpc" } } --------------- :wq ## Format code terraform fmt ## Initialize terraform terraform init ## Create the resource terraform apply ## View state file terraform show ## Create an override file vi override.tf --------------- #Overrides the VPC configuration resource "aws_vpc" "myvpc" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true tags { Name = "mynewvpc" } } --------------- :wq ## Format code terraform fmt ## Plan the changes terraform plan ## Apply the changes terraform apply ## View state file terraform show ## Destroy the resources terraform destroy ## Cleanup cd .. && rm -rf terraform |
Hope you have enjoyed this article. In the next blog post, we will create a LAMP stack using terraform.
To get more details on terraform, please refer below terraform documentation
https://www.terraform.io/docs/index.html