Updated on 2023-08-11 GMT+08:00

provider

In Terraform, you can use provider blocks to create multiple configurations, among which, one block is the default configuration, and other blocks are labeled as non-default configurations using alias. You can use the meta-argument provider in a resource to select a non-default provider block. For example, to manage resources in different regions, you need to declare multiple provider blocks.

provider "huaweicloud" {
  region = "cn-north-1"
  ...
}

provider "huaweicloud" {
  alias  = "guangzhou"
  region = "cn-south-1"
  ...
}

In the example, Huawei Cloud providers in Beijing and Guangzhou are declared, and the provider in Guangzhou is labeled with an alias. You can use the meta-argument provider in a resource to select a non-default provider block in the format of <Provider name>.<Alias>.

resource "huaweicloud_networking_secgroup" "mysecgroup" {
# Use the name and alias of the non-default provider block.
  provider = huaweicloud.guangzhou
  ...
}

Huawei Cloud providers allow you to specify the region argument in a resource to create resources in different regions. Compared with labeling providers with aliases, this mode is more flexible and simple.

provider "huaweicloud" {
  region = "cn-north-1"
  ...
}

resource "huaweicloud_vpc" "example" {
  region = "cn-south-1"
  name   = "terraform_vpc"
  cidr   = "192.168.0.0/16"
}