devans10 / terraform-provider-flash

Terraform provider plugin for Pure Storage FlashArray
Apache License 2.0
5 stars 10 forks source link

Unable to install in 0.12 due to registry lookup #16

Open dstamen opened 4 years ago

dstamen commented 4 years ago

I followed all the instructions for .12 on mac and linux but every time the provider tries to go out and pull it from the registry. can this be pushed to the terraform registry for ease of install?

devans10 commented 4 years ago

I will take a look at it, but there could be a naming issue that would result in some changes. Terraform's convention would be for this to be called terraform-provider-purestorage, since that is the provider name used in the code. However, due to trademarks, I can't use "purestorage" in the name.

Changing the name in the code to be "flash", would make the code less readable, i.e

provider flash {}

resource flash_volume {}

I will take a look to see if there is a work around.

Thank you for opening the issue and using/looking at the provider.

dstamen commented 4 years ago

Thanks it looks like the .terraformrc file was deprecated. so i downloaded the provider to ~/.terraform.d/plugins and its named terraform-provider-flash

when running terraform init

❯ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/purestorage...
- Finding latest version of hashicorp/terraform-provider-flash...

Error: Failed to install provider

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

Error: Failed to install provider

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

this is my main.tf

provider "terraform-provider-flash" {
username = var.purestorage_username
password = var.purestorage_password
target = var.purestorage_target
}

resource "purestorage_volume" "testvol_tf" {
name = "testvol_tf"
size = "1048000000"
}

On Wed, Aug 5, 2020 at 7:49 AM Dave Evans notifications@github.com wrote:

I will take a look at it, but there could be a naming issue that would result in some changes. Terraform's convention would be for this to be called terraform-provider-purestorage, since that is the provider name used in the code. However, due to trademarks, I can't use "purestorage" in the name.

Changing the name in the code to be "flash", would make the code less readable, i.e

provider flash {}

resource flash_volume {}

I will take a look to see if there is a work around.

Thank you for opening the issue and using/looking at the provider.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/devans10/terraform-provider-flash/issues/16#issuecomment-669147874, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2JMEWWASYS5TICUYRHSDDR7FBMRANCNFSM4PVMFP4Q .

dstamen commented 4 years ago

I ended up getting this to work, but still would be nice if it could be added to the registry. :)

mattivoxy commented 4 years ago

@dstamen Care to share how you got it to work? Running into the same exact problem.

dstamen commented 4 years ago

Take a look at https://davidstamen.com/2020/08/06/using-terraform-to-provision-your-pure-storage-infrastructure/

mattivoxy commented 4 years ago

Interesting. Following same steps (that's how I found this!) and still running into the same error.

Error: Failed to install provider

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

main.tf: provider "purestorage" { username = var.pure_admin_username password = var.pure_admin_password target = var.pure_array }

~/.terraformrc: providers { purestorage = "/Users//.terraform.d/plugins/terraform-provider-flash" }

dstamen commented 4 years ago

make sure your ~/.terraformrc has the full path to where the provider is downloaded i couldnt use ~ in that short url

On Fri, Aug 28, 2020 at 11:44 AM Matt Yette notifications@github.com wrote:

Interesting. Following same steps (that's how I found this!) and still running into the same error.

Error: Failed to install provider

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

main.tf: provider "purestorage" { username = var.pure_admin_username password = var.pure_admin_password target = var.pure_array }

~/.terraformrc: providers { purestorage = "/Users//.terraform.d/plugins/terraform-provider-flash" }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/devans10/terraform-provider-flash/issues/16#issuecomment-682738124, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2JMESGBE3TORZKORMCVQ3SC7GETANCNFSM4PVMFP4Q .

mattivoxy commented 4 years ago

Yep, it's been my full path the entire time. TF insists on its "registry" as the only source it'll look at.

Error: Failed to install provider

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

Pretty maddening. How hard is it to point something at "THIS" local file?

mattivoxy commented 4 years ago

Maybe this just doesn't work with 0.13 yet...

dstamen commented 4 years ago

I will check what version I was using I know I had a .13rc but need to check it still works with GA.

On Fri, Aug 28, 2020 at 4:49 PM Matt Yette notifications@github.com wrote:

Maybe this just doesn't work with 0.13 yet...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/devans10/terraform-provider-flash/issues/16#issuecomment-683140441, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2JMERXYZM5I6BAAZBXQRDSDAJ6TANCNFSM4PVMFP4Q .

mattivoxy commented 4 years ago

Thanks @dstamen - I've got TF looking at the right folder, but still no joy on it picking it up. Here's what my env looks like:

[vro@terraform VS67]$ cat versions.tf 
terraform {
  required_providers {
    nsxt = {
      source = "terraform-providers/nsxt"
    }
    vsphere = {
      source = "hashicorp/vsphere"
    }
    purestorage = {
      source = "example.com/org/purestorage"
    }
  }
  required_version = ">= 0.13"
}
[vro@terraform VS67]$ cat ~/.terraformrc 
provider_installation {
  filesystem_mirror {
    path    = "/home/vro/.terraform.d/plugins/"
    include = ["example.com/*/*"]
  }
  direct {
    exclude = ["example.com/*/*"]
  }
}
[vro@terraform VS67]$ ls -la /home/vro/.terraform.d/plugins/example.com/org/purestorage/
total 54840
drwxrwxr-x. 2 vro vro      173 Aug 29 09:23 .
drwxrwxr-x. 3 vro vro       25 Aug 29 09:17 ..
-rw-rw-r--. 1 vro vro      113 Aug 29 09:23 1.1.1.json
-rw-r--r--. 1 vro vro       40 Aug 29 09:17 index.json
-rwxrwxr-x. 1 vro vro 28808708 May  4  2019 terraform-provider-flash
-rw-rw-r--. 1 vro vro 13665632 Aug 29 09:19 terraform-provider-flash_1.1.1_linux_amd64.zip
-rw-rw-r--. 1 vro vro 13665231 Feb  8  2020 terraform-provider-flash.linux.tar.gz

Both 1.1.1.json and index.json mimic other plugins files since this provider download doesn't have them included; I don't think it matters either way but have tried with and without. Same result. I also untar'd the tarball and recompressed as a zip, just again to mimic others.

Result:

[vro@terraform VS67]$ terraform init
Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Using previously-installed hashicorp/vsphere v1.23.0
- Using previously-installed terraform-providers/nsxt v3.0.0
- Finding latest version of example.com/org/purestorage...

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider
example.com/org/purestorage: provider example.com/org/purestorage was not
found in any of the search locations

- /home/vro/.terraform.d/plugins/

Thanks again for all your help on this.

dstamen commented 4 years ago

i was running terraform v0.12.29. Just upgraded to 0.13.1 and it is now failing....i wonder if the configuration changed with 13 somehow, ill try to do some digging too.

On Fri, Aug 28, 2020 at 4:02 PM Matt Yette notifications@github.com wrote:

Yep, it's been my full path the entire time. TF insists on its "registry" as the only source it'll look at.

Error: Failed to install provider

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

Pretty maddening. How hard is it to point something at "THIS" local file?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/devans10/terraform-provider-flash/issues/16#issuecomment-683122818, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2JMEQPOLXBKXQGH6K3GBLSDAELZANCNFSM4PVMFP4Q .

mattivoxy commented 4 years ago

Ok, at least I'm not crazy :)

So I got it working, but it's certainly a hack as I ended up renaming things back to terraform-provider-purestorage, which I know is a copyright thing, so publicly not distributable. Ultimately, I needed to roll up a .zip file with version/arch and all that"

terraform-provider-purestorage_1.1.1_linux_amd64.zip

and place that into my /home/vro/.terraform.d/plugins/example.com/org/purestorage/ directory.

export TF_LOG=TRACE

helped me a lot too.

devans10 commented 4 years ago

I have been looking at getting this in the registry, and I'm going to try to get it working with 0.13.x tonight. I have just recently started to use 0.13 and other modules have some config upgrade scripts that need to be run. So I'm assuming some changes are required.

Thanks Dave

devans10 commented 4 years ago

I just published v1.1.2 to the Terraform Registry. You will need to add the following to your Terraform configuration.

terraform {
  required_providers {
    purestorage = {
      source  = "devans10/flash"
      version = "~> 1.1.2"
    }
  }
}

This replaces the need to put anything in the .terraformrc. I'm still working on running this through my acceptance tests, but had to publish something to get it into the registry.

devans10 commented 4 years ago

It looks like in addition to the above setting, you will also need to specify a provider for each resource.

For example:

terraform {
  required_providers {
    purestorage = {
      source  = "devans10/flash"
      version = "~> 1.1.2"
    }
  }
}

provider "purestorage" {
  target    = "flasharray.example.com"
  api_token = "123456676"
}

resource "purestorage_volume" "vol1" {
  provider = purestorage
  name     = "volume_name"
  size     = 1073741824
}
mattivoxy commented 4 years ago

Thanks for all your work on this, Dave.

I'm still having problems, now having switched over to 1.1.2. I'm able to add it to the providers block, and it downloads/installs successfully with an init. However, when trying to include it in my code:

resource "purestorage_volume" "testvol_tf" { provider = purestorage name = "testvol_tf" size = "1048000000" }

Fails:

Failed to instantiate provider "registry.terraform.io/hashicorp/purestorage" to obtain schema: unknown provider "registry.terraform.io/hashicorp/purestorage"

devans10 commented 4 years ago

Can you post the terraform {} and provider{} blocks?

mattivoxy commented 4 years ago
terraform {
  required_providers {
    nsxt = {
      source = "terraform-providers/nsxt"
    }
    vsphere = {
      source = "hashicorp/vsphere"
    }
    purestorage = {
      source  = "devans10/flash"
      version = "~> 1.1.2"
    }
  }
  required_version = ">= 0.13"
}
provider "purestorage" {
  username          = var.admin_username
  password          = var.admin_password
  target            = "<hostname>"
}

The above works, and init's just fine. The errors come in when I include something like the following in main.tf:

resource "purestorage_volume" "testvol_tf" {
  provider      = purestorage
  name          = "testvol_tf"
  size          = "1048000000"
}
devans10 commented 4 years ago

Looks like the local rename may not be working. I will look into if that is a bug with Terraform.

Calling the provider "flash" after the expected name, then listing that as the provider for the resource worked for me. Once I was able to get to my array to run some actual tests, the config above seemed to not find the provider parameters appropriately.

terraform {
  required_providers {
    flash = {
      source  = "devans10/flash"
      version = "~> 1.1.2"
    }
  }
}

provider "flash" {
  target = "flasharray.example.com"
  api_token = var.api_token
}

resource "purestorage_volume" "vol1" {
  provider = flash
  name = "testvol"
  size = 1024000000
}

Needless to say, the name mismatch is really starting to make things difficult. Its now broken all my acceptance tests.

mattivoxy commented 4 years ago

Yeah, I can seem to get init working all the way up to actually declaring a resource. I can't seem to find a combination of alias or name/provider setting to get it to stop reaching out and searching for another provider against hashicorp at that point.

% terraform providers

├── provider[registry.terraform.io/devans10/flash] ~> 1.1.2
├── provider[registry.terraform.io/terraform-providers/nsxt] 3.0.0
├── provider[registry.terraform.io/hashicorp/vsphere] 1.23.0
├── module.compute
**│   ├── provider[registry.terraform.io/hashicorp/flash]**
│   └── provider[registry.terraform.io/hashicorp/vsphere]
└── module.network
    └── provider[registry.terraform.io/terraform-providers/nsxt]

I can't seem to reference your proper "flash" inside at all.

devans10 commented 4 years ago

Ok, you have a module there too. There is a GitHub Terraform issue referencing a similar problem here.

As a workaround they put a provider reference both in the root and within the module. Which should not be the case, you should only need to list the provider once, but seems like a bug in Terraform.

mattivoxy commented 4 years ago

Excellent - the workaround allows me to get past the provider inclusion block.

Now, however:

Error: [error] Must specify API token or both username and password

Even thought I'm specifying U/P in the provider block in my base (above the modules) main.tf. Does it only currently work with API? Or must I establish these values again per the current workaround?

EDIT: disregard. Had an alias in my provider and that seemed to be holding me back.

dstamen commented 4 years ago

im seeing the same error.

On Sun, Aug 30, 2020 at 1:27 PM Matt Yette notifications@github.com wrote:

Excellent - the workaround allows me to get past the provider inclusion block.

Now, however:

Error: [error] Must specify API token or both username and password

Even thought I'm specifying U/P in the provider block in my base (above the modules) main.tf. Does it only currently work with API?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/devans10/terraform-provider-flash/issues/16#issuecomment-683447278, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2JMERSYADD4LHHES7MAZ3SDKDWTANCNFSM4PVMFP4Q .