-
provider
helps you to Use Multiple Providers in Terraform -
You can use multiple providers within the same configuration to manage resources in different cloud regions or service providers.
-
Each provider definition specifies a different set of configuration parameters, enabling you to interact with multiple environments.
-
Scenario: Suppose a you want to create 2 VPC in 2 different regions, or may be you want to launch EC2 instance in 2 different regions.
-
Example:
terraform { required_version = "~> 1.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } # Define First AWS Provider (us-east-1) provider "aws" { region = "us-east-1" alias = "us-east-nv" default_tags { tags = { Terraform = "yes" Region = "N.Virginia" } } } # Defining Second AWS Provider (ap-south-1) provider "aws" { region = "ap-south-1" alias = "ap-south-mumbai" default_tags { tags = { Terraform = "yes" Region = "Mumbai" } } }
# Create VPC in different regions using different providers # Create VPC in North-Virginia Region resource "aws_vpc" "nv-vpc" { # meta argument provider is used to specify which provider to be used provider = aws.us-east-nv cidr_block = "10.1.0.0/16" tags = { Name = "North-Virginia-VPC" } } # Create VPC in Mumbai Region resource "aws_vpc" "mum-vpc" { # meta argument provider is used to specify which provider to be used provider = aws.ap-south-mumbai cidr_block = "10.2.0.0/16" tags = { Name = "Mumbai-VPC" } }
-
Lets Execute Terraform commands to understand resource behavior
terraform init
: Initialize terraformterraform validate
: Validate terraform codeterraform fmt
: format terraform codeterraform plan
: Review the terraform planterraform apply
: Create Resources by terraform
terraform destroy
: destroy or delete Resources, Cleanup the resources we created-
After you type yes to
terraform destroy
prompt, terraform will start destroying resources -
Once terraform completes the execution you should be able to check on your AWS Console
-
08-04-provider
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||