vatesfr / terraform-provider-xenorchestra

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

Error: malformed ws or wss URL #275

Closed GilbertK99 closed 8 months ago

GilbertK99 commented 8 months ago

Hello

I get this error below when i run terraform plan.

Planning failed. Terraform encountered an error while generating this plan. Error: malformed ws or wss URL │ │ with provider["registry.terraform.io/terra-farm/xenorchestra"], │ on providers.tf line 11, in provider "xenorchestra": │ 11: provider "xenorchestra" {

This only happens when i use XOA_URL, XOA_USER and XOA_PASSWORD environment variables. When i replace the variables with the actual values eg. url = "wss://192.168.xx.xx" etc, the terraform plan works as expected.

This is my terraform code:

  # Instruct terraform to download the provider on `terraform init`
  terraform {
    required_providers {
      xenorchestra = {
        source = "terra-farm/xenorchestra"
      }
    }
  }

  # Configure the XenServer Provider
  provider "xenorchestra" {
    # Must be ws or wss
    url      = "XOA_URL"               # Or set XOA_URL environment variable
    username = "XOA_USER"              # Or set XOA_USER environment variable
    password = "XOA_PASSWORD"          # Or set XOA_PASSWORD environment variable

    # This is false by default and
    # will disable ssl verification if true.
    # This is useful if your deployment uses
    # a self signed certificate but should be
    # used sparingly!
    insecure = true              # Or set XOA_INSECURE environment variable to any value
  }

Any suggestions on what the issue could be?

ackjewtn commented 8 months ago

I haven't skimmed through the code yet, but something is wrong with the validation for the url property indeed.

But this works for me. So at least you don't need to add any secrets to the config.

provider "xenorchestra" {
  # Must be ws or wss
  #  username = ""
  #  password = ""
  url = "ws://my.server.int"
  insecure = true
}
GilbertK99 commented 8 months ago

Thanks for the info. Commenting out the username and password sections does work. Running terraform plan command prompts input of the username and password fields. This is a good workaround for the moment.

Hopefully an update will enable use of normal environment variables soon.

Much appreciated!

ddelnano commented 8 months ago

@GilbertK99 the url, username and password HCL arguments should be omitted when you want it to fall back to the environment variables. They do not provide a mechanism for instructing Terraform which environment variables to look at.

See that they are specified for each one: url, username, password. It's also worth mentioning that the values set in the provider block will always override the environment variables.

Assuming the code you mentioned above is what you are testing with, this would be expected behavior (XOA_URL is not a valid websocket server address).

GilbertK99 commented 8 months ago

Thank you so much! @ddelnano @ackjewtn I understand how its meant to work now. My mistake was including the HCL arguments in the code. VS Code kinda fooled me into thinking the attribute is required due to it showing some code errors as shown on this screenshot below. VSCode