go-gandi / terraform-provider-gandi

Terraform provider for the Gandi Domain services
Mozilla Public License 2.0
152 stars 45 forks source link

domain: allocate the nameservers array #110

Closed nlewo closed 2 years ago

nlewo commented 2 years ago

This is to JSON encode an empty nameservers array to [] instead of null. See https://apoorvam.github.io/blog/2017/golang-json-marshal-slice-as-empty-array-not-null/

Without this patch:

2022-04-05T10:33:22.103+0200 [INFO]  provider.terraform-provider-gandi: 2022/04/05 10:33:22 Response : [400 Bad Request]
2022-04-05T10:33:22.103+0200 [INFO]  provider.terraform-provider-gandi: 2022/04/05 10:33:22 Response body: {"status": "error", "errors": [{"location": "body", "name": "nameservers", "description": "\"None\" is not iterable"}]}: timestamp=2022-04-05T10:33:22.103+0200

With this patch:

2022-04-05T11:24:47.017+0200 [INFO]  provider.terraform-provider-gandi: 2022/04/05 11:24:47 Request:  curl -X 'PUT' -d '{"nameservers":[]}' -H 'Authorization: Apikey X' -H 'Content-Type: application/json' 'https://api.gandi.net/v5/domain/domains/bla.fr/nameservers': timestamp=2022-04-05T11:24:47.017+0200
2022-04-05T11:24:47.301+0200 [INFO]  provider.terraform-provider-gandi: 2022/04/05 11:24:47 Response : [400 Bad Request]
2022-04-05T11:24:47.301+0200 [INFO]  provider.terraform-provider-gandi: 2022/04/05 11:24:47 Response body: {"status": "error", "errors": [{"location": "body", "name": "nameservers.0", "description": "At least one nameserver is required"}]}: timestamp=2022-04-05T11:24:47.301+0200

Draft because it depends on https://github.com/go-gandi/go-gandi/pull/64