Skip to content

Run multiple provider versions

Abner Garcia edited this page Oct 5, 2021 · 7 revisions

In order to run multiple versions of the same provider (in this case, mongodbatlas) we will need to download the provider(s) for local use. For this example, we want to migrate to the new mongodbatlas v1.0.1 provider gradually from mongodbatlas v0.7.0

We need to create a folder where to put our providers, for example purposes we create a folder struct like this

project
│   main.tf  <- contains terraform definition for resources, datasources, etc.  
│   config.tfrc  <- configuration to use in terraform
└───providers    <- here we are going to add the local provider
│   └──registry.terraform.io
│      └──mongodb
|         └──mongodbatlas-old.  <- we added the sufix `old` to indicate that this contains the previous version
|            └──0.7.0
|               └──darwin_amd64
|                  └──terraform-provider-mongodbatlas-old_v0.7.0  <- we added the sufix `old` to indicate that this contains the previous version

main.tf

The header of the file contains 2 providers, one of them is the original provider provided by terraform registry (mongodbatlas) and the other one is the one that we want to use locally, we need to change the name according of how we named the downloaded provider, in this case, we use the old sufix to be sure that we are using an old version of the provider (we don't need to specify the version of this provider, due we only downloaded the v0.7.0

terraform {
  required_providers {
    mongodbatlas = {
      source = "mongodb/mongodbatlas"
      version = ">=1.0.1"
    }
    mongodbatlas-old = {
      source = "mongodb/mongodbatlas-old"
    }
  }
}

Inside the resource definition that are only contained in the old provider, we need to add the property provider = <Name of the provider, in this case, for the resource mongodbatlas_private_endpoint (that are only available in version 0.7.0) we set the property provider = mongodbatlas-old to specify that this resource is going to be run from the old version

variable "project_id" {
  type    = string
  default = "<default value for project id>"
}

resource "mongodbatlas_private_endpoint" "test" {
  provider = mongodbatlas-old
  project_id    = var.project_id
  provider_name = "AWS"
  region        = "us-east-1"
}

resource "mongodbatlas_privatelink_endpoint" "test" {
  project_id    = var.project_id
  provider_name = "AWS"
  region        = "us-east-1"
}

config.tfrc

In this file we are going to specify where is located our folder with the downloaded providers, in the example, we downloaded the provider inside providers folder

provider_installation {

  filesystem_mirror {
    path    = "./providers"
  }
  direct {}
}

In order to terraform use this file as configuration, we need to set the env var TF_CLI_CONFIG_FILE before use terraform, like this:

export TF_CLI_CONFIG_FILE=<PATH TO FILE>/config.tfrc
Clone this wiki locally