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

Error about missing location id with foreman_host #114

Open rogermartensson opened 1 year ago

rogermartensson commented 1 year ago

Using foreman version 3.4.1.

I'm trying to set up a very simple server using the example found in the documentation.

resource "foreman_host" "testserver" {
  name = "testserver.example.org"
}

The error message I get is:

│ Error: HTTP Error:{
│   endpoint:   [https://fmantest.server.miun.se/api/hosts]
│   statusCode: [404]
│   respBody:   [{"message":"Location with id 0 not found"}]
│ }
│
│   with foreman_host.testserver,
│   on main.tf line 60, in resource "foreman_host" "testserver":
│   60: resource "foreman_host" "testserver" {

There doesn't seem to be a way for me to set this.

agriffit79 commented 1 year ago

You need to set location_id and organization_id in your provider configuration.

rogermartensson commented 1 year ago

I see. Is it possible to enhance the error message to say that there are missing parameters in the provider configuration? Or maybe set these as mandatory in the provider?

Don't seem to be a data source for locations and organizations either. Or can I find that in some other data source?

agriffit79 commented 1 year ago

I think some older versions of Foreman didn't need those parameters, hence they were optional.

You can use the GUI to find the values for your environment. Under the Administer->Locatons/Organizations menu. When you click on a Location or Org the ID will be visible in the URL, prepending the name.

togoschi commented 1 year ago

You need to set location_id and organization_id since foreman version 1.21

agriffit79 commented 1 year ago

There's an argument for making them required fields now, as versions <1.21 are ancient and haven't been supported for years.

bitkeks commented 6 months ago

Should we do this? It might be as easy as switching from Optional to Required in provider.go:

"organization_id": {
    Type:     schema.TypeInt,
    Required: true,
    Default:  0,
    Description: "The organization for all resource requsted and created by the Provier " +
        "Defaults to \"0\". Set organization_id and location_id to a value < 0 if you need " +
        "to disable Locations and Organizations on Foreman older than 1.21",
},
"location_id": {
    Type:     schema.TypeInt,
    Optional: true,
    Required:  0,
    Description: "The location for all resources requested and created by the provider" +
        "Defaults to \"0\". Set organization_id and location_id to a value < 0 if you need " +
        "to disable Locations and Organizations on Foreman older than 1.21",
},