Terraform OCI - 在多个区域创建多个 VCN

我想在两个或更多区域内创建 2 个 VCN 和其他资源.

我在这个

您必须使用 provider = oci.region1 创建 2 个 oci_core_vcn 资源块,然后使用 provider = oci.root

I would like to create 2 VCN and other resources inside two or more regions.

I upload my code inside this github account

When i execute the code (you have to set the tenancy, user, fingerprint, etc) i don't have errors, but:

  1. When I go to the root region, all is created (compartment and VCN)
  2. when I go to the second region, the VCN is not created

terraform version: v1.0.2

my VCN module has:

terraform {
  required_providers {
    oci = {
      source = "hashicorp/oci"
      version = ">= 1.0.2"
      configuration_aliases = [
        oci.root,
        oci.region1
      ]
    }
  }
}

And when i call the VCN module I pass:

module "vcn" {
  source            = "./modules/vcn"
  
  providers = {
    oci.root = oci.home
    oci.region1 = oci.region1
  }
...
...

And my providers are:

provider "oci" {
  alias             = "home"
  tenancy_ocid      = local.json_data.TERRAFORM_work.tenancy_ocid
  user_ocid         = local.json_data.TERRAFORM_work.user_ocid
  private_key_path  = local.json_data.TERRAFORM_work.private_key_path
  fingerprint       = local.json_data.TERRAFORM_work.fingerprint
  region            = local.json_data.TERRAFORM_work.region
}

provider "oci" {
  alias             = "region1"
  region            = var.region1
  tenancy_ocid      = local.json_data.TERRAFORM_work.tenancy_ocid
  user_ocid         = local.json_data.TERRAFORM_work.user_ocid
  private_key_path  = local.json_data.TERRAFORM_work.private_key_path
  fingerprint       = local.json_data.TERRAFORM_work.fingerprint
}

What should i change, to create this VCN inside the two regions or more, at the same time?

using the terraform plan and apply

Thanks so much

解决方案

In the docs

You will have to create 2 oci_core_vcn resource blocks once with provider = oci.region1 to and once with provider = oci.root

相关文章