bpg / terraform-provider-proxmox

Terraform Provider for Proxmox
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
807 stars 134 forks source link

The plugin returned an unexpected error from plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc = got different PrepareProviderConfig #385

Closed JonTheNiceGuy closed 1 year ago

JonTheNiceGuy commented 1 year ago

Describe the bug When performing terraform plan or terraform apply I get this error:

╷
│ Error: Plugin error
│ 
│ The plugin returned an unexpected error from plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc = got different PrepareProviderConfig
│ PreparedConfig response from multiple servers, not sure which to use
╵

To Reproduce Steps to reproduce the behavior:

  1. Create main.tf
terraform {
  required_providers {
    proxmox = {
      source = "bpg/proxmox"
      version = "0.22.0"
    }
  }
}
provider "proxmox" {
  insecure = true
}
data "proxmox_virtual_environment_version" "current_version" {}
output "version" {
  value = data.proxmox_virtual_environment_version.current_version
}
  1. Set environment variables
export PROXMOX_VE_ENDPOINT=https://192.0.2.1:8006
export PROXMOX_VE_USERNAME=root@pam
export PROXMOX_VE_PASSWORD=abc123
  1. Run terraform apply

Expected behavior

data.proxmox_virtual_environment_version.current_version: Reading...
data.proxmox_virtual_environment_version.current_version: Read complete after 0s [id=version]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

version = {
  "id" = "version"
  "keyboard_layout" = ""
  "release" = "7.4"
  "repository_id" = "46c37d9c"
  "version" = "7.4-13"
}

This behaviour only is exhibited when replacing the provider "proxmox" block with the actual credentials in the HCL.

Additional context Add any other context about the problem here.

$ terraform --version
Terraform v1.5.0
on linux_amd64
+ provider registry.terraform.io/bpg/proxmox v0.22.0
$ TF_LOG=DEBUG terraform apply
2023-06-25T01:26:58.382+0100 [INFO]  Terraform version: 1.5.0
2023-06-25T01:26:58.383+0100 [DEBUG] using github.com/hashicorp/go-tfe v1.26.0
2023-06-25T01:26:58.383+0100 [DEBUG] using github.com/hashicorp/hcl/v2 v2.16.2
2023-06-25T01:26:58.383+0100 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.0
2023-06-25T01:26:58.383+0100 [DEBUG] using github.com/zclconf/go-cty v1.12.2
2023-06-25T01:26:58.383+0100 [INFO]  Go runtime version: go1.20
2023-06-25T01:26:58.383+0100 [INFO]  CLI args: []string{"terraform", "apply"}
2023-06-25T01:26:58.383+0100 [DEBUG] Attempting to open CLI config file: /home/jonspriggs/.terraformrc
2023-06-25T01:26:58.383+0100 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /home/jonspriggs/.terraform.d/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /home/jonspriggs/.local/share/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /usr/share/ubuntu/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /usr/share/gnome/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /home/jonspriggs/.local/share/flatpak/exports/share/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /var/lib/flatpak/exports/share/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2023-06-25T01:26:58.383+0100 [DEBUG] ignoring non-existing provider search directory /var/lib/snapd/desktop/terraform/plugins
2023-06-25T01:26:58.383+0100 [INFO]  CLI command args: []string{"apply"}
2023-06-25T01:26:58.383+0100 [DEBUG] New state was assigned lineage "acf0201a-1741-d699-1fa8-7db1352abc39"
2023-06-25T01:26:58.422+0100 [DEBUG] checking for provisioner in "."
2023-06-25T01:26:58.426+0100 [DEBUG] checking for provisioner in "/usr/bin"
2023-06-25T01:26:58.426+0100 [INFO]  backend/local: starting Apply operation
2023-06-25T01:26:58.427+0100 [DEBUG] created provider logger: level=debug
2023-06-25T01:26:58.427+0100 [INFO]  provider: configuring client automatic mTLS
2023-06-25T01:26:58.435+0100 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 args=[.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0]
2023-06-25T01:26:58.435+0100 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 pid=1351075
2023-06-25T01:26:58.435+0100 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0
2023-06-25T01:26:58.440+0100 [INFO]  provider.terraform-provider-proxmox_v0.22.0: configuring server automatic mTLS: timestamp=2023-06-25T01:26:58.440+0100
2023-06-25T01:26:58.449+0100 [DEBUG] provider: using plugin: version=6
2023-06-25T01:26:58.449+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: plugin address: address=/tmp/plugin3426463886 network=unix timestamp=2023-06-25T01:26:58.448+0100
2023-06-25T01:26:58.458+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-06-25T01:26:58.459+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 pid=1351075
2023-06-25T01:26:58.459+0100 [DEBUG] provider: plugin exited
2023-06-25T01:26:58.459+0100 [DEBUG] Building and walking validate graph
2023-06-25T01:26:58.459+0100 [DEBUG] ProviderTransformer: "data.proxmox_virtual_environment_version.current_version" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/bpg/proxmox"]
2023-06-25T01:26:58.459+0100 [DEBUG] ReferenceTransformer: "data.proxmox_virtual_environment_version.current_version" references: []
2023-06-25T01:26:58.459+0100 [DEBUG] ReferenceTransformer: "output.version (expand)" references: [data.proxmox_virtual_environment_version.current_version]
2023-06-25T01:26:58.459+0100 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/bpg/proxmox\"]" references: []
2023-06-25T01:26:58.460+0100 [DEBUG] Starting graph walk: walkValidate
2023-06-25T01:26:58.460+0100 [DEBUG] created provider logger: level=debug
2023-06-25T01:26:58.460+0100 [INFO]  provider: configuring client automatic mTLS
2023-06-25T01:26:58.466+0100 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 args=[.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0]
2023-06-25T01:26:58.466+0100 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 pid=1351087
2023-06-25T01:26:58.466+0100 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0
2023-06-25T01:26:58.471+0100 [INFO]  provider.terraform-provider-proxmox_v0.22.0: configuring server automatic mTLS: timestamp=2023-06-25T01:26:58.471+0100
2023-06-25T01:26:58.480+0100 [DEBUG] provider: using plugin: version=6
2023-06-25T01:26:58.480+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: plugin address: network=unix address=/tmp/plugin3499398780 timestamp=2023-06-25T01:26:58.480+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Calling provider defined validator.String: description="must be a valid API token, e.g. 'USER@REALM!TOKENID=UUID'" tf_provider_addr=registry.terraform.io/bpg/proxmox tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/attribute_validation.go:707 @module=sdk.framework tf_attribute_path=api_token tf_mux_provider=*proto6server.Server tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Called provider defined validator.String: description="must be a valid API token, e.g. 'USER@REALM!TOKENID=UUID'" tf_attribute_path=api_token tf_mux_provider=*proto6server.Server tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/attribute_validation.go:717 @module=sdk.framework tf_rpc=ValidateProviderConfig timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Calling provider defined validator.String: tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/attribute_validation.go:707 tf_attribute_path=endpoint description="string length must be at least 1" tf_mux_provider=*proto6server.Server tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 @module=sdk.framework timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Called provider defined validator.String: tf_mux_provider=*proto6server.Server tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 @module=sdk.framework tf_attribute_path=endpoint description="string length must be at least 1" tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/attribute_validation.go:717 timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Calling provider defined Type Validate: tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwschemadata/data_value.go:81 @module=sdk.framework tf_mux_provider=*proto6server.Server timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Called provider defined Type Validate: tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwschemadata/data_value.go:83 @module=sdk.framework tf_mux_provider=*proto6server.Server tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Calling provider defined validator.List: tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 @module=sdk.framework description="list must contain at most 1 elements" tf_mux_provider=*proto6server.Server tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/block_validation.go:217 timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [DEBUG] provider.terraform-provider-proxmox_v0.22.0: Called provider defined validator.List: description="list must contain at most 1 elements" tf_mux_provider=*proto6server.Server tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 tf_rpc=ValidateProviderConfig @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.0/internal/fwserver/block_validation.go:227 @module=sdk.framework tf_provider_addr=registry.terraform.io/bpg/proxmox timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [ERROR] provider.terraform-provider-proxmox_v0.22.0: Error from downstream: tf_proto_version=6.3 tf_provider_addr=registry.terraform.io/bpg/proxmox tf_req_id=f7f91b2b-1218-562c-46f0-4d8d0ab12734 @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov6/tf6server/server.go:556 @module=sdk.proto error="got different PrepareProviderConfig PreparedConfig response from multiple servers, not sure which to use" tf_rpc=ValidateProviderConfig timestamp=2023-06-25T01:26:58.490+0100
2023-06-25T01:26:58.490+0100 [ERROR] plugin6.(*GRPCProvider).ValidateProviderConfig: error="rpc error: code = Unknown desc = got different PrepareProviderConfig PreparedConfig response from multiple servers, not sure which to use"
2023-06-25T01:26:58.490+0100 [ERROR] vertex "provider[\"registry.terraform.io/bpg/proxmox\"]" error: Plugin error
╷
│ Error: Plugin error
│ 
│ The plugin returned an unexpected error from plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc = got different PrepareProviderConfig
│ PreparedConfig response from multiple servers, not sure which to use
╵
2023-06-25T01:26:58.491+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-06-25T01:26:58.492+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/bpg/proxmox/0.22.0/linux_amd64/terraform-provider-proxmox_v0.22.0 pid=1351087
2023-06-25T01:26:58.492+0100 [DEBUG] provider: plugin exited
JonTheNiceGuy commented 1 year ago

Adding context, tested this morning;

variable "proxmox_username" {}
variable "proxmox_password" {}
variable "proxmox_endpoint" {}
provider "proxmox" {
  endpoint = var.proxmox_endpoint
  username = var.proxmox_username
  password = var.proxmox_password
  insecure = true
}

If I set:

export TF_VAR_proxmox_endpoint=https://192.0.2.1:8006
export TF_VAR_proxmox_username=root@pam
export TF_VAR_proxmox_password=abc123

This does work, so it's possible to load these variables from outside the provider, just not in the way that I'd expect.

bpg commented 1 year ago

Thanks for the report @JonTheNiceGuy!

Yeah, regressed when I added protocol v6 support and provider muxing as the first steps of migration to the new terraform plugin framework. Glad you found a workaround, but I'll try to fix it for the next release.