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

Can't modify volume using xslt #862

Open boscard opened 3 years ago

boscard commented 3 years ago

System Information

Linux distribution

Debian 10

Terraform version

terraform -v
v0.13.7

Provider and libvirt versions

terraform-provider-libvirt -version
0.6.3

Checklist

Description of Issue/Question

Hi, I'm trying to modify volume using xslt but it seems to not work.

Setup

main.tf

terraform {
 required_version = ">= 0.13"
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "0.6.3"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://root@192.168.1.5/system"
}

resource "libvirt_pool" "ubuntu" {
  name = "ubuntu"
  type = "dir"
  path = "/basic/libvirt/pool/ubuntu-example"
}

resource "libvirt_volume" "ubuntu-qcow2" {
  name   = "ubuntu-qcow2"
  pool   = libvirt_pool.ubuntu.name
  source = "https://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
  format = "qcow2"
                xml {
                xslt = templatefile("volume.xsl",
                          {
                                  pool_path = "/basic/libvirt/pool/ubuntu-example",
                            volume = "ubuntu-qcow2"
                                })
        }
}

data "template_file" "user_data" {
  template = file("${path.module}/cloud_init.cfg")
}

data "template_file" "network_config" {
  template = file("${path.module}/network_config.cfg")
}

resource "libvirt_cloudinit_disk" "commoninit" {
  name           = "commoninit.iso"
  user_data      = data.template_file.user_data.rendered
  network_config = data.template_file.network_config.rendered
  pool           = libvirt_pool.ubuntu.name
}

resource "libvirt_domain" "domain-ubuntu" {
  name   = "ubuntu-terraform"
  memory = "512"
  vcpu   = 1

  cloudinit = libvirt_cloudinit_disk.commoninit.id

  network_interface {
    network_name = "default"
  }
  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }

  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }

  disk {
    volume_id = libvirt_volume.ubuntu-qcow2.id
  }

  graphics {
    type        = "spice"
    listen_type = "address"
    autoport    = true
  }

}

volume.xsl

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
  </xsl:template>

  <xsl:template match="disk[@device='disk']/@type">
    <xsl:attribute name="type">
      <xsl:value-of select="'file'"/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="disk/source">
          <source file='${pool_path}/${volume}' />
  </xsl:template>
</xsl:stylesheet>

Steps to Reproduce Issue

Terraform apply will create domain with unmodified volumes


Additional information:

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

dmacvicar commented 3 years ago

Can you paste the output with TF_LOG=DEBUG? There should be some output about the original and transformed XML.

boscard commented 3 years ago

Sorry for my late response. Logs are in attachment. tf.log