Hello,
I’m trying to write a Terraform test (using the terraform test command) with the non-hashicorp Proxmox provider, but pulling the secrets from HashiCorp Vault. According to the documentation, this is achieved by adding a run block with a setup module
tests/test.tftest.hcl
provider "vault" {
address = "<my_address>"
}
provider "proxmox" {
pm_api_url = "<pm_api_url>"
pm_user = run.setup.proxmox_user["username"]
pm_password = run.setup.proxmox_user["password"]
}
run "setup" {
module {
source = "./tests/setup"
}
}
run "verify_linux_instance" {
command = plan
}
tests/setup/main.tf
data "vault_kv_secret_v2" "proxmox_user" {
....
}
output "proxmox_user" {
value = data.vault_kv_secret_v2.proxmox_user.data
sensitive = true
}
I have the required_providers set up in the root module:
providers.tf
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "3.0.1-rc1"
}
}
}
When I do this, I am getting an error that I hadn’t seen before adding the setup run block:
│ Error: Provider type mismatch
│
│ on tests/test.tftest.hcl line 20:
│ 20: provider "proxmox" {
│
│ The provider "proxmox" in tests/test.tftest.hcl represents provider
│ "registry.terraform.io/hashicorp/proxmox", but "proxmox" in the root module
│ represents "registry.terraform.io/telmate/proxmox".
│
│ This means the provider definition for "proxmox" within tests/test.tftest.hcl, or
│ other provider definitions with the same name, have been referenced by multiple run
│ blocks and assigned to different provider types.
As I write this, I am now able to work around this by adding an alias to my provider
provider "proxmox" {
alias = "primary"
...
}
and adding a reference to the provider alias
run "verify_linux_instance" {
providers = {
proxmox = proxmox.primary
}
command = plan
}
this seems to remove the provider from the scope of the setup block, and therefore said provider is not affected by said block, but it appears that this setup block affects the provider sources even when said providers aren’t used (can’t be used even, as they depend upon this) in the setup block.
(Terraform v1.7.5 on MacOS)
Thanks!