vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 33 forks source link

terraform init fails with "Error: Failed to install provider" #92

Closed andbut closed 3 years ago

andbut commented 3 years ago

I am using the following config

terraform {
    required_providers {
        xenorchestra = {
            source = "terra-farm/xenorchestra"
            version = "0.9.1"
        }
    }
}

# Configure the XenServer Provider
provider "xenorchestra" {
    # Must be ws or wss
    url      = "ws://hostname-of-server" # Or set XOA_URL environment variable
    username = "<username>"              # Or set XOA_USER environment variable
    password = "<password>"              # Or set XOA_PASSWORD environment variable
}

But encounter the following error when I run terraform init

Initializing provider plugins...
- Finding latest version of hashicorp/xenorchestra...
- Finding terra-farm/xenorchestra versions matching "0.9.1"...
- Installing terra-farm/xenorchestra v0.9.1...
- Installed terra-farm/xenorchestra v0.9.1 (self-signed, key ID DDBA1674AA3EA0EE)

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

Error: Failed to install provider

Error while installing hashicorp/xenorchestra: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/xenorchestra
$ terraform -v
Terraform v0.13.5
+ provider registry.terraform.io/terra-farm/xenorchestra v0.9.1
ddelnano commented 3 years ago

@andbut can you run TF_LOG=trace terraform init? Please search that output to make sure your XO credentials are not in it.

From looking at your code it seems correct and I'm surprised that it's trying to install the hashicorp version of the provider (which wouldn't exist)

andbut commented 3 years ago

Here you go

TF_LOG=trace terraform init
2020/11/24 08:21:59 [INFO] Terraform version: 0.13.5  
2020/11/24 08:21:59 [INFO] Go runtime version: go1.15.3
2020/11/24 08:21:59 [INFO] CLI args: []string{"/usr/bin/terraform", "init"}
2020/11/24 08:21:59 [DEBUG] Attempting to open CLI config file: /home/andyb/.terraformrc
2020/11/24 08:21:59 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /home/andyb/.terraform.d/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /home/andyb/.local/share/terraform/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /home/andyb/.local/share/flatpak/exports/share/terraform/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /var/lib/flatpak/exports/share/terraform/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2020/11/24 08:21:59 [DEBUG] ignoring non-existing provider search directory /var/lib/snapd/desktop/terraform/plugins
2020/11/24 08:21:59 [INFO] CLI command args: []string{"init"}
2020/11/24 08:21:59 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
Initializing modules...
2020/11/24 08:21:59 [DEBUG] Module installer: begin cloud-init
2020/11/24 08:21:59 [TRACE] ModuleInstaller: Module installer: cloud-init <nil> already installed in ../../modules/cloud-init
2020/11/24 08:21:59 [TRACE] modsdir: writing modules manifest to .terraform/modules/modules.json

2020/11/24 08:21:59 [TRACE] Meta.Backend: built configuration for "gcs" backend with hash value 2977648403
Initializing the backend...
2020/11/24 08:21:59 [TRACE] Preserving existing state lineage "b1e747fe-9bb3-8593-1dd3-ba2ee7b46be0"
2020/11/24 08:21:59 [TRACE] Preserving existing state lineage "b1e747fe-9bb3-8593-1dd3-ba2ee7b46be0"
2020/11/24 08:21:59 [TRACE] Meta.Backend: working directory was previously initialized for "gcs" backend
2020/11/24 08:21:59 [TRACE] Meta.Backend: using already-initialized, unchanged "gcs" backend configuration
2020/11/24 08:22:00 [TRACE] Meta.Backend: instantiated backend of type *gcs.Backend
2020/11/24 08:22:00 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins
2020/11/24 08:22:00 [TRACE] getproviders.SearchLocalDirectory: .terraform/plugins is a symlink to .terraform/plugins
2020/11/24 08:22:00 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/terra-farm/xenorchestra v0.9.1 for linux_amd64 at .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64
2020/11/24 08:22:00 [TRACE] providercache.fillMetaCache: including .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64 as a candidate package for registry.terraform.io/terra-farm/xenorchestra 0.9.1
2020/11/24 08:22:00 [DEBUG] checking for provisioner in "."
2020/11/24 08:22:00 [DEBUG] checking for provisioner in "/usr/bin"
2020/11/24 08:22:00 [INFO] Failed to read plugin lock file .terraform/plugins/linux_amd64/lock.json: open .terraform/plugins/linux_amd64/lock.json: no such file or directory
2020/11/24 08:22:00 [TRACE] Meta.Backend: backend *gcs.Backend does not support operations, so wrapping it in a local backend
2020/11/24 08:22:00 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins
2020/11/24 08:22:00 [TRACE] getproviders.SearchLocalDirectory: .terraform/plugins is a symlink to .terraform/plugins

Initializing provider plugins...
2020/11/24 08:22:00 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/terra-farm/xenorchestra v0.9.1 for linux_amd64 at .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64
2020/11/24 08:22:00 [TRACE] providercache.fillMetaCache: including .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64 as a candidate package for registry.terraform.io/terra-farm/xenorchestra 0.9.1
2020/11/24 08:22:00 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
2020/11/24 08:22:00 [TRACE] HTTP client GET request to https://registry.terraform.io/.well-known/terraform.json
- Using previously-installed terra-farm/xenorchestra v0.9.1
- Finding latest version of hashicorp/xenorchestra...
2020/11/24 08:22:01 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/xenorchestra/versions
2020/11/24 08:22:01 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/xenorchestra/versions
2020/11/24 08:22:01 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/plugins
2020/11/24 08:22:01 [DEBUG] GET https://registry.terraform.io/v1/providers/-/xenorchestra/versions
2020/11/24 08:22:01 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/-/xenorchestra/versions

Error: Failed to install provider

Error while installing hashicorp/xenorchestra: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/xenorchestra
ddelnano commented 3 years ago

@andbut I see the issue now. You have two parts of your code declaring the provider.

The first is the modern terraform syntax

terraform {
    required_providers {
        xenorchestra = {
            source = "terra-farm/xenorchestra"
            version = "0.9.1"
        }
    }
}

The second is legacy and should only be used if you are on a terraform version < 0.12

# Configure the XenServer Provider
provider "xenorchestra" {
    # Must be ws or wss
    url      = "ws://hostname-of-server" # Or set XOA_URL environment variable
    username = "<username>"              # Or set XOA_USER environment variable
    password = "<password>"              # Or set XOA_PASSWORD environment variable
}

Remove the second code block and your terraform init will run properly. Sorry for not catching that sooner as I was on mobile the first time and didn't see the duplicated block.

Closing this issue since this is not an issue with the provider.

andbut commented 3 years ago

Thanks for that - but please consider updating your Getting Started instructions accordingly, as I literally just copied it from there.

andbut commented 3 years ago

Sadly that still does not work - my config is now

terraform {
    backend "gcs" {
        bucket  = "<bucket_name>"
        prefix  = "<bucket_prefix>"
    }
    required_providers {
        xenorchestra = {
            source = "terra-farm/xenorchestra"
            version = "0.9.1"
            # I assume the below is still needed - else how do I configure the provider??
            url      = "ws://hostname-of-server" # Or set XOA_URL environment variable
            username = "<username>"              # Or set XOA_USER environment variable
            password = "<password>"              # Or set XOA_PASSWORD environment variable
        }
    }
}

But the issue still occurs

$ rm -rf .terraform          
$ TF_LOG=trace terraform init
2020/11/25 08:47:15 [INFO] Terraform version: 0.13.5  
2020/11/25 08:47:15 [INFO] Go runtime version: go1.15.3
2020/11/25 08:47:15 [INFO] CLI args: []string{"/usr/bin/terraform", "init"}
2020/11/25 08:47:15 [DEBUG] Attempting to open CLI config file: /home/andyb/.terraformrc
2020/11/25 08:47:15 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /home/andyb/.terraform.d/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /home/andyb/.local/share/terraform/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /home/andyb/.local/share/flatpak/exports/share/terraform/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /var/lib/flatpak/exports/share/terraform/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2020/11/25 08:47:15 [DEBUG] ignoring non-existing provider search directory /var/lib/snapd/desktop/terraform/plugins
2020/11/25 08:47:15 [INFO] CLI command args: []string{"init"}
Initializing modules...
2020/11/25 08:47:15 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
2020/11/25 08:47:15 [DEBUG] Module installer: begin cloud-init
2020/11/25 08:47:15 [TRACE] ModuleInstaller: cloud-init is not yet installed
2020/11/25 08:47:15 [TRACE] ModuleInstaller: cleaning directory .terraform/modules/cloud-init prior to install of cloud-init
2020/11/25 08:47:15 [TRACE] ModuleInstaller: cloud-init has local path "../../modules/cloud-init"
2020/11/25 08:47:15 [TRACE] ModuleInstaller: cloud-init uses directory from parent: ../../modules/cloud-init
2020/11/25 08:47:15 [DEBUG] Module installer: cloud-init installed at ../../modules/cloud-init
2020/11/25 08:47:15 [TRACE] modsdir: writing modules manifest to .terraform/modules/modules.json
- cloud-init in ../../modules/cloud-init

Initializing the backend...
2020/11/25 08:47:15 [TRACE] Meta.Backend: built configuration for "gcs" backend with hash value 2977648403
2020/11/25 08:47:15 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2020/11/25 08:47:15 [DEBUG] New state was assigned lineage "bf08fb33-53ee-341b-7f57-dcec0acf937b"
2020/11/25 08:47:15 [TRACE] Meta.Backend: moving from default local state only to "gcs" backend
2020/11/25 08:47:15 [DEBUG] checking for provisioner in "."
2020/11/25 08:47:15 [DEBUG] checking for provisioner in "/usr/bin"
2020/11/25 08:47:15 [INFO] Failed to read plugin lock file .terraform/plugins/linux_amd64/lock.json: open .terraform/plugins/linux_amd64/lock.json: no such file or directory
2020/11/25 08:47:15 [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2020/11/25 08:47:15 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2020/11/25 08:47:15 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2020/11/25 08:47:15 [TRACE] statemgr.Filesystem: read nil snapshot
2020/11/25 08:47:15 [TRACE] Meta.Backend: ignoring local "default" workspace because its state is empty
2020/11/25 08:47:15 [DEBUG] New state was assigned lineage "66a1ee50-b877-1fd8-bb63-f2e3df661d8d"
2020/11/25 08:47:15 [TRACE] Preserving existing state lineage "66a1ee50-b877-1fd8-bb63-f2e3df661d8d"

Successfully configured the backend "gcs"! Terraform will automatically
use this backend unless the backend configuration changes.
2020/11/25 08:47:16 [TRACE] Meta.Backend: instantiated backend of type *gcs.Backend
2020/11/25 08:47:16 [DEBUG] checking for provisioner in "."
2020/11/25 08:47:16 [DEBUG] checking for provisioner in "/usr/bin"
2020/11/25 08:47:16 [INFO] Failed to read plugin lock file .terraform/plugins/linux_amd64/lock.json: open .terraform/plugins/linux_amd64/lock.json: no such file or directory
2020/11/25 08:47:16 [TRACE] Meta.Backend: backend *gcs.Backend does not support operations, so wrapping it in a local backend
2020/11/25 08:47:17 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins
2020/11/25 08:47:17 [TRACE] getproviders.SearchLocalDirectory: failed to resolve symlinks for .terraform/plugins: lstat .terraform/plugins: no such file or directory

2020/11/25 08:47:17 [TRACE] providercache.fillMetaCache: error while scanning directory .terraform/plugins: cannot search .terraform/plugins: lstat .terraform/plugins: no such file or directory
2020/11/25 08:47:17 [WARN] Failed to scan provider cache directory .terraform/plugins: cannot search .terraform/plugins: lstat .terraform/plugins: no such file or directory
2020/11/25 08:47:17 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
2020/11/25 08:47:17 [TRACE] HTTP client GET request to https://registry.terraform.io/.well-known/terraform.json
Initializing provider plugins...
- Finding latest version of hashicorp/xenorchestra...
2020/11/25 08:47:17 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/xenorchestra/versions
2020/11/25 08:47:17 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/xenorchestra/versions
2020/11/25 08:47:17 [DEBUG] GET https://registry.terraform.io/v1/providers/terra-farm/xenorchestra/versions
- Finding terra-farm/xenorchestra versions matching "0.9.1"...
2020/11/25 08:47:17 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/terra-farm/xenorchestra/versions
2020/11/25 08:47:18 [DEBUG] GET https://registry.terraform.io/v1/providers/terra-farm/xenorchestra/0.9.1/download/linux/amd64
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/terra-farm/xenorchestra/0.9.1/download/linux/amd64
2020/11/25 08:47:18 [DEBUG] GET https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_SHA256SUMS
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_SHA256SUMS
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://github-production-release-asset-2e65be.s3.amazonaws.com/175864600/b013b400-2917-11eb-958e-586925694118?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201125%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201125T084528Z&X-Amz-Expires=300&X-Amz-Signature=501191f5d9faf1952f833a31a20ef49172b94fb6c0fae67f4a696cf57c89b309&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=175864600&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-xenorchestra_0.9.1_SHA256SUMS&response-content-type=application%2Foctet-stream
2020/11/25 08:47:18 [DEBUG] GET https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_SHA256SUMS.sig
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_SHA256SUMS.sig
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://github-production-release-asset-2e65be.s3.amazonaws.com/175864600/a0946b00-2917-11eb-8643-983286645812?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201125%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201125T084529Z&X-Amz-Expires=300&X-Amz-Signature=832341e1f27f0427efcd69d96c1ba31a7a964cb87b39fdb3f4f6c92688a0b023&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=175864600&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-xenorchestra_0.9.1_SHA256SUMS.sig&response-content-type=application%2Foctet-stream
2020/11/25 08:47:18 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/terra-farm/xenorchestra v0.9.1 from https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_linux_amd64.zip
2020/11/25 08:47:18 [TRACE] HTTP client GET request to https://github.com/terra-farm/terraform-provider-xenorchestra/releases/download/v0.9.1/terraform-provider-xenorchestra_0.9.1_linux_amd64.zip
- Installing terra-farm/xenorchestra v0.9.1...
2020/11/25 08:47:19 [TRACE] HTTP client GET request to https://github-production-release-asset-2e65be.s3.amazonaws.com/175864600/a8eca600-2917-11eb-9709-924b9588e0ae?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201125%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201125T084529Z&X-Amz-Expires=300&X-Amz-Signature=1da93dba3ee72c83291fc786743491bdad85006a7330a54dd37a16a07d177471&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=175864600&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-xenorchestra_0.9.1_linux_amd64.zip&response-content-type=application%2Foctet-stream
2020/11/25 08:47:28 [DEBUG] Provider signed by DDBA1674AA3EA0EE Dom Del Nano <ddelnano@gmail.com>
2020/11/25 08:47:29 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins
2020/11/25 08:47:29 [TRACE] getproviders.SearchLocalDirectory: .terraform/plugins is a symlink to .terraform/plugins
2020/11/25 08:47:29 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/terra-farm/xenorchestra v0.9.1 for linux_amd64 at .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64
2020/11/25 08:47:29 [TRACE] providercache.fillMetaCache: including .terraform/plugins/registry.terraform.io/terra-farm/xenorchestra/0.9.1/linux_amd64 as a candidate package for registry.terraform.io/terra-farm/xenorchestra 0.9.1
2020/11/25 08:47:29 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/plugins
- Installed terra-farm/xenorchestra v0.9.1 (self-signed, key ID DDBA1674AA3EA0EE)

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
2020/11/25 08:47:29 [DEBUG] GET https://registry.terraform.io/v1/providers/-/xenorchestra/versions
2020/11/25 08:47:29 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/-/xenorchestra/versions

Error: Failed to install provider

Error while installing hashicorp/xenorchestra: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/xenorchestra
andbut commented 3 years ago

Ok - I think I found the issue.

The problem is caused by me using modules - if I place the config block

terraform {
    required_providers {
        xenorchestra = {
            source = "terra-farm/xenorchestra"
            version = "0.9.1"
        }
    }
}

In both the terraform module - and the state file that uses the modules then init runs successfully

$ terraform init
Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Using previously-installed terra-farm/xenorchestra v0.9.1

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.
ddelnano commented 3 years ago

Thanks for highlighting that the instructions are wrong. I've opened #93 to fix the documentation issue.

And yea for any module that references the provider you will need to add that block. Glad you got it working and thanks for improving the documentation of the project!