terraform-coop / terraform-provider-foreman

Terraform provider for Foreman
https://registry.terraform.io/providers/terraform-coop/foreman
Mozilla Public License 2.0
33 stars 31 forks source link

foreman_host: Replace the "name" attribute with "fqdn" (computed) and "shortname" (required) #121

Closed bitkeks closed 11 months ago

bitkeks commented 1 year ago

As mentioned in #116 the "name" field is problematic in Foreman. The setting "append_domain_name_for_hosts" converts a short hostname into an FQDN. This leads to "inconsistent plan" errors in Terraform.

In earlier versions, a custom unmarshaller removed the domain part from the name attribute:

if fh.DomainName != "" && strings.Contains(fh.ForemanObject.Name, fh.DomainName) {
    fh.ForemanObject.Name = strings.Replace(fh.ForemanObject.Name, "."+fh.DomainName, "", 1)
}

In this case, Foreman always used the FQDN internally, but Terraform received only the shortname in return and had no issues. Since this function is removed, the conflict appears.

For expected behaviour and consistency I propose a switch to "fqdn" and "shortname" instead of the "name" attribute. This PR is the implementation.

The result will look like this: