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

Foreign key constraint violation when creating subnet without dhcp_Id #36

Closed covert8 closed 3 years ago

covert8 commented 3 years ago

Hi, first of thank you for all you hard work.

When applying a subnet: │ Error: HTTP Error:{ │ endpoint: [https://foreman.be/api/subnets] │ statusCode: [500] │ respBody: [{ │ "error": {"message":"PG::ForeignKeyViolation: ERROR: insert or update on table \"subnets\" violates foreign key constraint \"subnets_dhcp_id_fk\"\nDETAIL: Key (dhcp_id)=(0) is not present in table \"smart_proxies\".\n"} │ } │ ] │ } │ │ with foreman_subnet.tier3-mgmt, │ on foreman_subnet.tf line 806, in resource "foreman_subnet" "tier3-mgmt": │ 806: resource "foreman_subnet" "tier3-mgmt"

It would seem that when a dhcp_id is not set, it is given the value 0 instead of being truly optional. When creating a subnet via the web interface and not setting dhcp_id it creates successfully.

How would i go about fixing this? I looked at the code and the variable is marked optional so it would seem that the problem is within the api implementation.