-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
foreman_host: Replace the "name" attribute with "fqdn" (computed) and "shortname" (required) #121
Merged
bitkeks
merged 10 commits into
terraform-coop:master
from
mindfulsecurity:host_name_fix
Jul 19, 2023
Merged
foreman_host: Replace the "name" attribute with "fqdn" (computed) and "shortname" (required) #121
bitkeks
merged 10 commits into
terraform-coop:master
from
mindfulsecurity:host_name_fix
Jul 19, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces the new attributes "fqdn" and "shortname" to the Terraform provider for foreman_host objects. Formerly, the "name" attribute was used to configure and read the hostname of a host. But this value can be inconsistent, because Foreman might expand a short hostname to an FQDN, depending on a setting. (this is not a bug) Because of this unexpected behaviour (results in "inconstistent plan" in Terraform) the name attribute is now bypassed. Shortname is the new required input variable. Summary: * name: was required, is now optional and computed * fqdn: new, read-only, always returns the FQDN * shortname: required and checked for dots (".") to issue warnings Refs terraform-coop#116
"Shortname" does not exist in the Foreman API, only "name" which is either shortname or FQDN depending on a setting. For a more expected behaviour the shortname and fqdn fields were introduced. This commit fills the Shortname field in the ForemanHost API struct.
bitkeks
changed the title
Host name fix
foreman_host: Replace the "name" attribute with "fqdn" (computed) and "shortname" (required)
May 17, 2023
bitkeks
commented
Jun 12, 2023
The tests use an API mock response file to check against a mocked Terraform schema. Since neither "shortname" nor "fqdn" host attributes are in the Foreman API, we exclude them in the tests. They are constructed from the "name" given by Foreman, or passed in in case of the shortname. To enforce the switch from "name" to "shortname", name is now a deprecated argument. It is still accessible via the name attribute, which is filled when the resource is read from the API.
lhw
reviewed
Jul 11, 2023
lhw
approved these changes
Jul 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
name
: Read-only, used in Foreman API as a unique name for a host. Can be either the short name or the expanded FQDN, depending on the respective Foreman setting.shortname
: The "new" "name" argument that you should use in Terraform for your hosts. In combination with thedomain_id
Foreman knows what the domain part should be.fqdn
: Read-only, only exists in the Terraform provider. Is constructed from the name received from Foreman. Can be used as a consistent variable value in other parts of the Terraform module files and blocks.