...

/

More Than One Instance of the Same Provider

More Than One Instance of the Same Provider

We will learn to create multiple instances of the same provider and to add provider property.

Creating multiple instances of the same provider

Since region is a required parameter in the AWS provider, you may be wondering how to create resources in different regions. Is that possible in a single Terraform project? Well, yes, it is. To do this, you simply create multiple instances of the same provider.

Project example

Consider the following project:



provider "aws" {
    region = "us-east-1"
}

provider "aws" {
    region = "us-east-2"
    alias = "ohio"
}

resource "aws_vpc" "n_virginia_vpc" {
    cidr_block = "10.0.0.0/16"
}

resource "aws_vpc" "ohio_vpc" {
    cidr_block = "10.1.0.0/16"
    provider = aws.ohio
}

AWS provider instances

As you can see, we are defining two instances of the AWS provider. One points at the region us-east-1 while the other points at the region us-east-2. For the one that is pointing at us-east-2, ...