Trying to create VMs in foreman using terraform with customization

I am creating multiple vms in foreman using terraform with some customization however while running terraform apply it gives error.

Error: Unsupported argument

on main.tf line 33, in resource “foreman_host” “vms”:
33: location_id = each.value[“LOCATION_ID”]

An argument named “location_id” is not expected here.

Also unable to pass compute attributes as it tells

Error: “compute_attributes” contains an invalid JSON: invalid character ‘C’ after object key:value pair

Below is my main.tf file. I am using provider terraform-coop/foreman/0.7.0

==============================================
locals {
csv_data = file(“${path.module}/vms.csv”)
vm_metadata = csvdecode(local.csv_data)
}

resource “foreman_host” “vms” {
for_each = { for vm_metadata in local.vm_metadata : vm_metadata.HOSTNAME => vm_metadata }
name = each.value[“HOSTNAME”]
hostgroup_id = each.value[“HOSTGROUP”]
managed = true
set_build_flag = true
location_id = each.value[“LOCATION_ID”]
compute_attributes = <<EOF
{
“cpus” : “each.value[“CPU”]”,
“memory_mb” : “each.value[“MEMORY”]”
}
EOF
}

How we can customize CPU/Memory/location/organization or does this not supported

I figured organization ID and location should be in foreman provider.
however still not able to customize CPU and Memory
if any one come across such scenario please let me know

%%%%
server_protocol = “https”
location_id = 2
organization_id = 1
%%%%%%%%

I was able to fix it. we can close it.

Greetings,
I am sending you this message to ask you a question about the “location_id” and “organization_id”. I am trying to create a host resource but when I apply it I get the following error:

"error": {"id":null,"errors":{"location_id":["can't be blank"]},"full_messages":["Location can't be blank"]}

I’ve added the location and organization id to the provider of foreman.

Could you please provide me your .tf files?

My set up is:
terraform-coop/foreman: v0.7.0
foreman: v3.10.0

Thanks a lot!

Hi @nchris10 ,

I added organization ID and location id in foreman provider stanza.

==========================
provider “foreman” {
provider_loglevel = “INFO”
provider_logfile = “terraform-foreman-build.log”

client_username = “admin”
client_password = “1234567892”
client_tls_insecure = “true”

server_hostname = “fqdn_foreman_server”
server_protocol = “https”
location_id = 2
organization_id = 1
}

============================================

Also you can refer my github page where i have working terraform code for this.

Hope it will helps.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.