TypeSet saving null instead of [] to terraform state

I have built a basic plugin for managing an API provider we use extensively.

The API has 3 json array fields that I don’t care about ordering, therefore using Set, but I’ve been facing this issue that the API of the provider returns an empty json array “” and during the creation, even after setting the value explicitly to []string{} or make([]string, 0) it saves as “null” on terraform state.

That results on changes after creation that are empty,


  # statuscake_contact_group.another_one has been changed
  ~ resource "statuscake_contact_group" "another_one" {
      + email_addresses = []
        id              = "888888"
      + integration_ids = []
      + mobile_numbers  = []
        name            = "NOPE
    }

Whereas terraform should already have saved [] as []

TF State shows something like:

          "attributes": {
            "email_addresses": null,

terraform plan → works well
terraform apply → says all ok
terraform plan → shows changes???

After I accept the changes, with a second apply, it all stays stable…

I’m wondering if I’m doing something wrong or if that is a bug with Set (which I find hard to believe since it seems like an obvious behaviour).

I appreciate any help, the code for the provider is available here: terraform-provider-statuscake/contact_group_resource.go at master · marceloboeira/terraform-provider-statuscake · GitHub

3 Likes