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

data_source_foreman_puppetclass: only able to define top level puppet classes without colons #98

Closed gerg91 closed 1 year ago

gerg91 commented 1 year ago

Hello,

First of all I've been extremely impressed with this provider and all the options it has.

This appears to be a new feature, but I'm also new to Terraform so I could be completely misunderstanding how to use it.

Using this data source works:

data "foreman_puppetclass" "example" {
  name = "apache"
}

But adding a nested Puppet class does not work

data "foreman_puppetclass" "example" {
  name = "apache::dev"
}

I get the message: Error: Data source results contain unexpected type. Expected [api.ForemanPuppetClass], got [<nil>]

Foreman appears to handle the request correctly:

2022/10/12 17:44:07 [DEBUG] server response:{
  endpoint:   [https://$FOREMAN_URL/foreman_puppet/api/puppetclasses?search=name%3D%22apache%3A%3Adev%22]
  method:     [GET]
  statusCode: [200]
  respBody:   [{
  "total": 1718,
  "subtotal": 1,
  "page": 1,
  "per_page": 20,
  "search": "name=\"apache::dev\"",
  "sort": {
    "by": null,
    "order": null
  },
  "results": {"apache":[{"id":6,"name":"apache::dev","created_at":"2022-05-23T17:54:40.182Z","updated_at":"2022-05-23T17:54:40.182Z"}]}
}
]
}

But I suspect the issue is related to the unescaped double colons here:

2022/10/12 17:44:08 [TRACE] data_source_foreman_puppetclass.go#Read
2022/10/12 17:44:08 [DEBUG] ForemanPuppetClass: [&{ForemanObject:{Id:0 Name:apache::dev CreatedAt: UpdatedAt:}}]

not-working-terraform-trace.log not-working-terraform-provider-foreman.log