terraform-coop / terraform-provider-foreman

Terraform provider for Foreman
https://registry.terraform.io/providers/terraform-coop/foreman
Mozilla Public License 2.0
35 stars 32 forks source link

Refactor host and add managed fields #58

Closed MrFreezeex closed 2 years ago

MrFreezeex commented 2 years ago

The first commit add a managed field to host. This allow to not specify the mac address/ip address if you set it to false (not sure if this is redundant to manage_build, I think it should be ok like that though).

The second commit refactor a bit the ForemanHost mainly adding a bunch of omitempty (and having *int instead of int so that omitempty actually works), removing the custom marshaling and making ComputeAttributes type a little more precise (from interface{} to map[string]interface{}). I also removed all the GetOk call while building the ForemanHost struct as if the schema attribute is computed this method always return true false (https://github.com/hashicorp/terraform-plugin-sdk/blob/9bdb216a4ab835003a624b0a15ac39c58ef2861e/helper/schema/resource_diff.go#L386).

MrFreezeex commented 2 years ago

Ah yes indeed, I need to fix some type in the tests

lhw commented 2 years ago

I also removed all the GetOk call while building the ForemanHost struct as if the schema attribute is computed this method always return true (https://github.com/hashicorp/terraform-plugin-sdk/blob/9bdb216a4ab835003a624b0a15ac39c58ef2861e/helper/schema/resource_diff.go#L386).

Wow. I never realized that. Thats all still code from wayfair and I presumed its basically just a != nil check.

MrFreezeex commented 2 years ago

I also removed all the GetOk call while building the ForemanHost struct as if the schema attribute is computed this method always return true (https://github.com/hashicorp/terraform-plugin-sdk/blob/9bdb216a4ab835003a624b0a15ac39c58ef2861e/helper/schema/resource_diff.go#L386).

Wow. I never realized that. Thats all still code from wayfair and I presumed its basically just a != nil check.

Yes... Fortunately for us the foreman api is forgiving if you give him a bunch of id that equals to 0 etc that sort of works.

MrFreezeex commented 2 years ago

Ah yes indeed, I need to fix some type in the tests

Should be good now :+1: