1

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

Julio
  • 471
  • 5
  • 20

1 Answers1

1

Your module module.vcn does not declare any provider. From docs:

each module must declare its own provider requirements,

So you have to add to your module something like:

terraform {
  required_providers {
    oci = {
      source  = "source_for-oci"
      version = ">= your_version"
    }
  }
}
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Thanks @Marcin, I modify my question setting the parameter that i forgot, the point is that, on the second region nothing is created. What could be wrong? Regards – Julio Nov 24 '21 at 10:56
  • 1
    @Julio This would be a new issue. Its good practice to create new question for it, not to edit existing one. The issue that you originally reported about the provider has been fixed. – Marcin Nov 24 '21 at 11:03
  • 1
    your are rigth , thanks man this is the new question: https://stackoverflow.com/questions/70094984/terraform-oci-create-multiple-vcn-in-multiple-regions – Julio Nov 24 '21 at 11:07