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

utils_xslt: display xsltproc stderr when it fails #1002

Open alexandre-janniaux opened 1 year ago

alexandre-janniaux commented 1 year ago

It's easy to have xsltproc failing to process the XML from a libvirt terraform configuration. Indeed, syntax error will trigger such failure, and a bad terraform configuration where xslt= property is confused as file path instead of content would likely generate syntax errors:

resource "libvirt_domain" "example" {
  # ...
  xml {
    xslt = "${path.module}/transform.xslt"
  }
}

Currently, when xsltproc fails, with TF_LOG=1, the following is displayed:

2023-02-21T14:00:35.620+0100 [INFO]  provider.terraform-provider-libvirt: 2023/02/21 14:00:35 [ERROR] Failed to run xsltproc (is it installed?): timestamp=2023-02-21T14:00:35.620+0100

Which is confusing when xsltproc is available. With this patch and TF_LOG=1, the following would be displayed:

2023-02-21T14:00:35.620+0100 [INFO]  provider.terraform-provider-libvirt: 2023/02/21 14:00:35 [ERROR] Failed to run xsltproc (is it installed?): timestamp=2023-02-21T14:00:35.620+0100
2023-02-21T14:00:35.620+0100 [INFO]  provider.terraform-provider-libvirt: 2023/02/21 14:00:35 [ERROR] Error: {/tmp/terraform-provider-libvirt-xslt1179436507:1: parser error : Start tag expected, '<' not found
transform.xslt
^

Refs #999

Please make sure you read the contributor documentation before opening a Pull Request.