dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

Using provider with a SSH key via local_sensitive_file doesn't work #984

Open thequailman opened 1 year ago

thequailman commented 1 year ago

System Information

Linux distribution

Debian 11

Terraform version

on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.7.0

Checklist

Description of Issue/Question

I'm trying to us this provider with a sshkey provided via a separate Terraform resource. The provider seems to init too fast and doesn't let the uri value render first.

Setup

This was my final attempt to make the provider work via inducing a dependency for the URI to a data read

terraform {
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "~> 0.7"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://root@libvirt:2222/system?no_verify=1&keyfile=${data.external.id_rsa.result.path}"
}

data "external" "id_rsa" {
  program = ["echo", <<EOT
{"path": "./id_rsa"}
EOT
  ]

  depends_on = [
    local_sensitive_file.id_rsa
  ]
}

resource "local_sensitive_file" "id_rsa" {
  content = ${some_other_resource.key}
}

Steps to Reproduce Issue

See above


Additional information:

Do you have SELinux or Apparmor/Firewall enabled? Some special configuration? Have you tried to reproduce the issue without them enabled?

thequailman commented 1 year ago

You can see how other terraform providers lazy load options here: https://github.com/hashicorp/terraform-provider-mysql/blob/master/mysql/provider.go#L195