mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
242 stars 168 forks source link

Seemingly unable to set provider source to mongodb/mongodbatlas for terraform v0.14? #396

Closed sonic1981 closed 3 years ago

sonic1981 commented 3 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v0.14.5
+ provider registry.terraform.io/hashicorp/azurerm v2.44.0
+ provider registry.terraform.io/hashicorp/random v3.0.1
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/mongodb/mongodbatlas v0.8.0
+ provider registry.terraform.io/terraform-providers/mongodbatlas v0.8.0

Terraform Configuration File

terraform {
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "= 0.8.0"
    }
  }
}

provider "mongodbatlas" {
    public_key = var.mongoPublicKey
    private_key  = var.mongoPrivateKey
}

Steps to Reproduce

I recently upgraded terraform from 0.13 to 0.14. Upon doing this I got an error message:

Warning: Additional provider information from registry

The remote registry returned warnings for
registry.terraform.io/terraform-providers/mongodbatlas:
- For users on Terraform 0.13 or greater, this provider has moved to
mongodb/mongodbatlas. Please update your sourc

My configuation file was at the time:

terraform {
  required_providers {
    mongodbatlas = {
      source = "terraform-providers/mongodbatlas"
      version = "= 0.8.0"
    }
  }
}
provider "mongodbatlas" {

    public_key = var.mongoPublicKey
    private_key  = var.mongoPrivateKey
}

I updated the source as requested to:

terraform {
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "= 0.8.0"
    }
  }
}

provider "mongodbatlas" {
    public_key = var.mongoPublicKey
    private_key  = var.mongoPrivateKey
}

Expected Behavior

Provider should be using the mongodb/mongodbatlas provider and not the registry.terraform.io/terraform-providers/mongodbatlas.

Actual Behavior

I still get the error message despite changing the source.

Debug Output

terraform providers output:

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/azurerm] 2.44.0
├── provider[registry.terraform.io/hashicorp/random]
├── module.takeapi
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.compare
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.mongo
│   └── provider[registry.terraform.io/mongodb/mongodbatlas] 0.8.0
├── module.process
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.dashboards
│   ├── provider[registry.terraform.io/hashicorp/azurerm]
│   └── provider[registry.terraform.io/hashicorp/template]
├── module.dl
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.sche
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.take
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.kv
│   └── provider[registry.terraform.io/hashicorp/azurerm]
└── module.list
    └── provider[registry.terraform.io/hashicorp/azurerm]

Providers required by state:

    provider[registry.terraform.io/hashicorp/azurerm]

    provider[registry.terraform.io/hashicorp/random]

    provider[registry.terraform.io/hashicorp/template]

    provider[registry.terraform.io/terraform-providers/mongodbatlas]

Terraform lock file:

# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/azurerm" {
  version     = "2.44.0"
  constraints = "2.44.0"
  hashes = [
    "h1:utblkIG5TUDkbxUJ/xJ6gwJxv+gBlBhOOqM14Bmk+/0=",
    "zh:0dfdcada6312a1b7216a8aef59a13604ed6d6ac364fb7e51e9c1c49289c47d2f",
    "zh:15067fcd6273cf5b0d8582ebd0b2d5c68d2f6c64b0bd7b6b57474f1076489508",
    "zh:2567a1c5c76b878b6de29170c70b49557388026129512ee5506dec3ad935d731",
    "zh:287f1025574b767c73367398e7a4cbd6d7c1abc2f74694f73e885ae43c5688d8",
    "zh:4fee5b2a2644725bcb56ac3b23e40b27b019ae95f783573a6d48bda2191fa8b8",
    "zh:a8105c96086f0e5696eeccee19b28268a4b22246d68d5a0a8b219491ec6fee81",
    "zh:c0bd239d8463c950b1a339693ca23fe5b85c6761124f56e13242c0f5baaeba7a",
    "zh:c31f0fecfa59b5c343939c4d842e4b843b251c7aadb6c63820c6fb6ef09d10e6",
    "zh:c3a1318a220270c0a3c655bd633d1204c752599953451e5c66a139bb9dc47f4f",
    "zh:e24506af1e6f51b1dcc6109ac5ccea7b136db4a51658fe8e309adccd34997fba",
  ]
}

provider "registry.terraform.io/hashicorp/random" {
  version = "3.0.1"
  hashes = [
    "h1:xN99GF2LlUhqjwbLVX2YPGpZ5NMG1ZuTFE6X66g5snM=",
    "zh:0d4f683868324af056a9eb2b06306feef7c202c88dbbe6a4ad7517146a22fb50",
    "zh:4824b3c7914b77d41dfe90f6f333c7ac9860afb83e2a344d91fbe46e5dfbec26",
    "zh:4b82e43712f3cf0d0cbc95b2cbcd409ba8f0dc7848fdfb7c13633c27468ed04a",
    "zh:78b3a2b860c3ebc973a794000015f5946eb59b82705d701d487475406b2612f1",
    "zh:88bc65197bd74ff408d147b32f0045372ae3a3f2a2fdd7f734f315d988c0e4a2",
    "zh:91bd3c9f625f177f3a5d641a64e54d4b4540cb071070ecda060a8261fb6eb2ef",
    "zh:a6818842b28d800f784e0c93284ff602b0c4022f407e4750da03f50b853a9a2c",
    "zh:c4a1a2b52abd05687e6cfded4a789dcd7b43e7a746e4d02dd1055370cf9a994d",
    "zh:cf65041bf12fc3bde709c1d267dbe94142bc05adcabc4feb17da3b12249132ac",
    "zh:e385e00e7425dda9d30b74ab4ffa4636f4b8eb23918c0b763f0ffab84ece0c5c",
  ]
}

provider "registry.terraform.io/hashicorp/template" {
  version = "2.2.0"
  hashes = [
    "h1:LN84cu+BZpVRvYlCzrbPfCRDaIelSyEx/W9Iwwgbnn4=",
    "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386",
    "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53",
    "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603",
    "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16",
    "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776",
    "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451",
    "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae",
    "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde",
    "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d",
    "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2",
  ]
}

provider "registry.terraform.io/mongodb/mongodbatlas" {
  version     = "0.8.0"
  constraints = "0.8.0"
  hashes = [
    "h1:3rf2nShWKpBdYNshycvsPbI++un5qjtNX6qSSnluNRE=",
    "zh:27c5a5bc7222a8fa7755f247bee1c1a38414836f1a29db0e2e8664ca6b266bed",
    "zh:2abd3366f9f6e0e78e88c1d0dcc7552857cc77d04672ae53453b6d9d7b7614eb",
    "zh:42f33844228c19226e51522959edf29862db41be95f08b83cb686b35d1d8a4c0",
    "zh:6ae3557d2af816895f04ae3b90b2575b8d510af95d1b08d502990bc25534b561",
    "zh:75f066f76028221154373b55e57b074137ec9e58aef9b6c1e153cea5970656ed",
    "zh:76079ec61a15ac1a65ae1d4b2b9c386ab2f24e4a8e6e9c35392f537dcc9c2d57",
    "zh:b7705f7ecf64ec52c90c2b7c08125c1da3af087e6d06eaddfcb31497f33ed400",
    "zh:bd4a5e1cb666b13b68b5a3fb7c93b8e93c75844a3e4ce9abea2c2cc52c68e82b",
    "zh:c043cb38797be4a1fe38fd17f18e266eb0a090a4b745dfffc1282751ec0eb000",
    "zh:d23c6760ea3b7626af093f6bf4cf6377736ee58273f1c6d8f2db43403c0629ad",
    "zh:d837e21914f599245de25109f55a09073b9a79c236c7b27f43d6d832da0fc137",
  ]
}

provider "registry.terraform.io/terraform-providers/mongodbatlas" {
  version = "0.8.0"
  hashes = [
    "h1:3rf2nShWKpBdYNshycvsPbI++un5qjtNX6qSSnluNRE=",
    "zh:27c5a5bc7222a8fa7755f247bee1c1a38414836f1a29db0e2e8664ca6b266bed",
    "zh:2abd3366f9f6e0e78e88c1d0dcc7552857cc77d04672ae53453b6d9d7b7614eb",
    "zh:42f33844228c19226e51522959edf29862db41be95f08b83cb686b35d1d8a4c0",
    "zh:6ae3557d2af816895f04ae3b90b2575b8d510af95d1b08d502990bc25534b561",
    "zh:75f066f76028221154373b55e57b074137ec9e58aef9b6c1e153cea5970656ed",
    "zh:76079ec61a15ac1a65ae1d4b2b9c386ab2f24e4a8e6e9c35392f537dcc9c2d57",
    "zh:b7705f7ecf64ec52c90c2b7c08125c1da3af087e6d06eaddfcb31497f33ed400",
    "zh:bd4a5e1cb666b13b68b5a3fb7c93b8e93c75844a3e4ce9abea2c2cc52c68e82b",
    "zh:c043cb38797be4a1fe38fd17f18e266eb0a090a4b745dfffc1282751ec0eb000",
    "zh:d23c6760ea3b7626af093f6bf4cf6377736ee58273f1c6d8f2db43403c0629ad",
    "zh:d837e21914f599245de25109f55a09073b9a79c236c7b27f43d6d832da0fc137",
  ]
}

Crash Output

Additional Context

References

themantissa commented 3 years ago

@sonic1981 we are using the new path and were an earlier mover when the registry change came out. This move meant all verified providers had to move from Hashicorp's repository (terraform-providers/mongodbatlas) to the providers own repository (mongodb/terraform-provider-mongodbatlas - where this issue is). It looks like you may have both perhaps cached locally? @nikhil-mongo can you try to repo this and see and assist?

sonic1981 commented 3 years ago

Hey @themantissa

If I delete the .terraform folder and the lock file and run init I can still see it using the terraform-providers/mongodbatlas. If it is cached, I'm not sure where from or how to remove that?

Here's the output from the init call on a clean directory:

Initializing the backend...

Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Finding latest version of hashicorp/template...
- Finding latest version of terraform-providers/mongodbatlas...
- Finding hashicorp/azurerm versions matching "2.44.0"...
- Finding mongodb/mongodbatlas versions matching "0.8.0"...
- Installing hashicorp/random v3.0.1...
- Installed hashicorp/random v3.0.1 (signed by HashiCorp)
- Installing hashicorp/template v2.2.0...
- Installed hashicorp/template v2.2.0 (signed by HashiCorp)
- Installing terraform-providers/mongodbatlas v0.8.1...
- Installed terraform-providers/mongodbatlas v0.8.1 (signed by HashiCorp)
- Installing hashicorp/azurerm v2.44.0...
- Installed hashicorp/azurerm v2.44.0 (signed by HashiCorp)
- Installing mongodb/mongodbatlas v0.8.0...
- Installed mongodb/mongodbatlas v0.8.0 (signed by a HashiCorp partner, key ID 2A32ED1F3AD25ABF)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Warning: Additional provider information from registry

The remote registry returned warnings for
registry.terraform.io/terraform-providers/mongodbatlas:
- For users on Terraform 0.13 or greater, this provider has moved to
mongodb/mongodbatlas. Please update your source in required_providers.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
nikhil-mongo commented 3 years ago

@sonic1981 I am currently working on this and will update you on our findings.

sonic1981 commented 3 years ago

I'm going to try tearing down everything and deleting the state to see what happens if I configure that provider from the off

sonic1981 commented 3 years ago

so if I completely delete the .tfstate and run init my providers looks like:

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/random]
├── provider[registry.terraform.io/hashicorp/azurerm] 2.44.0
├── provider[registry.terraform.io/mongodb/mongodbatlas] 0.8.0
├── module.takeapi
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.kv
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.list
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.compare
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.dashboards
│   ├── provider[registry.terraform.io/hashicorp/azurerm]
│   └── provider[registry.terraform.io/hashicorp/template]
├── module.take
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.process
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.sche
│   └── provider[registry.terraform.io/hashicorp/azurerm]
├── module.dl
│   └── provider[registry.terraform.io/hashicorp/azurerm]
└── module.mongo
    └── provider[registry.terraform.io/mongodb/mongodbatlas] 0.8.0

so it seems it's the state file that isn't changing the provider from terraform-providers/mongodbatlas to mongodb/mongodbatlas. Not sure if this is a provider issue or a terraform (core) issue?

sonic1981 commented 3 years ago

@nikhil-mongo looking at the docs for terraform, I think this is a terraform issue, not a provider issue. according to this doc I'd expect the resources for the old provider to be torn down and recreated with the new provider:

This is seamless when changing a resource's attributes, but Terraform will lose track of a resource if you change its name, move it to a different module, or change its provider.

Usually that's fine: Terraform will destroy the old resource, replace it with a new one (using the new resource address), and update any resources that rely on its attributes.

I'll raise an issue on the main terraform github

sonic1981 commented 3 years ago

Closing as it seems this is core terraform functionality and not the provider