Closed togoschi closed 1 year ago
Verified the issue with a simple foreman host and an example parameter for debugging (debugstr
)
resource "foreman_host" "proposal" {
name = var.hostname
method = "build"
...
parameters = {
debugstr = "test string for debug purposes"
}
}
data "template_file" "preinstall" {
template = file("${path.module}/templates/preinstall.erb")
vars = {
hostgroup = var.group
var_debug = "${foreman_host.proposal.parameters["debugstr"]}"
}
}
resource "foreman_provisioningtemplate" "preinstall" {
name = "${var.group} preinstall"
template = data.template_file.preinstall.rendered
snippet = true
}
The (vsphere virtual) machine was successfully deployed with foreman provider 0.4.5.
After updating the foreman provider to 0.5.3 (and replacing method
with managed
and build
attribute) tf apply
throws error (tf plan
still works)
Error: Invalid index
│
│ on provision.tf line 76, in data "template_file" "preinstall":
│ 76: var_debug = "${foreman_host.proposal.parameters["debugstr"]}"
│ ├────────────────
│ │ foreman_host.proposal.parameters is empty map of string
│
│ The given key does not identify an element in this collection value.
The output of tf apply
with terraform TRACE log shows that the parameter is "vanished" although the foreman host parameter is already set
2022-08-18T15:31:00.755+0200 [WARN] Provider "provider[\"registry.terraform.io/hansemerkur/foreman\"]" produced an unexpected new value for foreman_host.proposal, but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
- .parameters: element "debugstr" has vanished
$ curl -s -k -u xxx:xxx https://foremanhost/api/v2/hosts/1094 | jq '.parameters?'
[
{
"priority": 70,
"created_at": "2022-08-18T13:14:26.368Z",
"updated_at": "2022-08-18T13:14:26.368Z",
"id": 6042,
"name": "debugstr",
"value": "test string for debug purposes"
}
]
While running tf apply
i've also created a foreman provider log output
provider "foreman" {
provider_loglevel = "DEBUG"
provider_logfile = "terraform-provider-foreman.log"
...
}
Closed by #95
Latest provider version is no longer able to read host parameters which are already set in foreman. The resulting error when running tf apply is as follows (tf plan isn't affected)
But the missing key is available in API
Terraform TRACE log shows