HewlettPackard / terraform-provider-oneview

Automates the provisioning of physical infrastructure from a private cloud using templates from HPE OneView with Terraform
Apache License 2.0
49 stars 30 forks source link

question - what is the proper way to upgrade providers? #378

Closed rismoney closed 3 years ago

rismoney commented 3 years ago

I am currently using terraform 12, 6.0 and want to go to terraform 13 6.2

So I previosuly only had this:

+provider "oneview" {
  ov_username  = var.username
  ov_password  = var.password
  ov_endpoint  = var.endpoint
  ov_sslverify = var.ssl_enabled
  ov_apiversion = "2000"
  ov_ifmatch = "*"

Now I added this (and left the above):

terraform {
  backend "local" {
    path = "\\\\my.com\\data\\Appinstalls\\terraform\\sp_eg06.tfstate"
  }
  required_providers {
    oneview = {
      source = "HewlettPackard/oneview"
      version = "6.2.0-13"

    }
  }
}

I then got the error message:

C:\gitrepos\terraform\sp_eg06 [master ≡ +0 ~2 -0 !]> C:\terraform13\terraform.exe init
Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Using previously-installed hashicorp/local v2.1.0
- terraform.io/builtin/terraform is built in to Terraform
- Using previously-installed hewlettpackard/oneview v6.2.0-13
- Using previously-installed -/local v2.1.0
- Finding latest version of hashicorp/oneview...

*** I snipped deprecation warnings ***
Error: Failed to install provider

Error while installing hashicorp/oneview: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/oneview

Error: Failed to install legacy providers required by state

Found unresolvable legacy provider references in state. It looks like these
refer to in-house providers. You can update the resources in state with the
following command:
terraform state replace-provider registry.terraform.io/-/oneview registry.terraform.io/hewlettpackard/oneview

Then I ran the above command terraform state replace-provider registry.terraform.io/-/oneview registry.terraform.io/hewlettpackard/oneview

Now I still get the error:

Error: Failed to install provider

Error while installing hashicorp/oneview: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/oneview

How do I properly configure/update state this?

rismoney commented 3 years ago

alright I figured it. For new readers of this- if you use modules with the provider you will need a provider.tf (or any tf file) :

terraform {
  required_providers {
    oneview = {
      source = "HewlettPackard/oneview"
      version = "6.2.0-13"
    }
  }
}

inside the module source directory.

Then you need to run terraform state replace-provider registry.terraform.io/-/oneview registry.terraform.io/hewlettpackard/oneview

Then you can run C:\terraform13\terraform.exe init -upgrade

rismoney commented 3 years ago

I spoke too soon. This yields a

To work with module.server1.data.local_file.mappings its original
provider configuration at provider["registry.terraform.io/-/local"] is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.server1.data.local_file.mappings, after which you can remove the
provider configuration again.

Going to try passing the module into the child... I shouldn't have to specify the required provider in the child module, it should inherit.

rismoney commented 3 years ago

wait that is a diff provider, local. standdown.

rismoney commented 3 years ago

made it passed that with C:\terraform13\terraform.exe state replace-provider registry.terraform.io/-/local registry.terraform.io/hashicorp/local

nabhajit-ray commented 3 years ago

Hi Rich , if your problem is resolved please close the issue. Something similar was raised earlier.

https://github.com/HewlettPackard/terraform-provider-oneview/issues/351