Skip to content
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_hostgroup with parameters fails #129

Open
rockpapergoat opened this issue Jul 5, 2023 · 3 comments
Open

foreman_hostgroup with parameters fails #129

rockpapergoat opened this issue Jul 5, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@rockpapergoat
Copy link

when adding a host group with parameters, i'm getting errors like this:

 Error: json: cannot unmarshal bool into Go struct field ForemanKVParameter.parameters.value of type string
│
│   with foreman_hostgroup.Compute,
│   on hostgroups.tf line 1, in resource "foreman_hostgroup" "Compute":
│    1: resource "foreman_hostgroup" "Compute" {

the resources look roughly like this:

resource "foreman_hostgroup" "Compute" {
  name       = "Compute"
  parameters = var.default_hostgroup_parameters
}

variable "default_hostgroup_parameters" {
  default = {
    "efi_bootentry"             = "NIC|Network"
    "force-puppet"              = "true"
    "kickstart_liveimg"         = "http://college.edu:8000/httpboot/rocky8_compute.tar"
    "no-resolv-override"        = "false"
    "puppet_ca_server"          = "ca.college.edu"
    "puppet_server"             = "compile01.college.edu"
    "pxe_kernel_options"        = "biosdevname=1 net.ifnames=1"
    "remote_execution_ssh_keys" = "ssh-rsa <ssh key here>"
    "remote_execution_ssh_user" = "root"
    "run-puppet-in-installer"   = "false"
    "skip-puppet-setup"         = "false"
  }
}

i've tried quoting the booleans, quoting the keys. neither seems to work, and i'm not sure if the provider's complaining about the booleans in that parameters map or something else entirely. this is happening with the 0.6.0 or the last 0.5.8 provider releases, at least.

what's the proper format for adding host group parameters? am i missing something?

@rockpapergoat
Copy link
Author

in the hostgroup resource definition, is this right?

"parameters": {
				Type:     schema.TypeMap,
				ForceNew: false,
				Optional: true,
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
				Description: "A map of parameters that will be saved as hostgroup parameters " +
					"in the group config.",
			},

the map elements can contain booleans, but it's unclear to me whether the foreman api expects bools to be passed as strings or if this element type needs to accommodate other data types, like bools.

@bitkeks
Copy link
Collaborator

bitkeks commented Oct 30, 2023

Hi @rockpapergoat,

we tested your example code and neither tf apply nor tf import show the error in our setup. Could you please dig further if the error might be caused somewhere else?

You can enable a debug log by configuring the provider as follows:

provider "foreman" {
  provider_loglevel = "DEBUG"
  provider_logfile = "terraform-provider-foreman.log"

  [... other provider-related config entries ...]
}

This might provide a trace that is better suited to solve the issue.

@bitkeks
Copy link
Collaborator

bitkeks commented Dec 21, 2023

It's the same issue as in #136, see my post #136 (comment). The host decode struct expects the value to be of type string only, so the refactoring for JSON parameters will have the same effect as a refactoring to handle booleans for this issue.

The conversion from "true" to true happens somewhere in between, but is acceptable. We should focus on the resolution to handle more than string types.

@bitkeks bitkeks added bug Something isn't working help wanted Extra attention is needed labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants