Read function does not detect changes

Hello,

I have this piece of HCL code:

resource "netbox_tenant" "tenant_test" {
  ...                                           
  custom_field {                                                                
    name  = "TestBoolean"                                                       
    kind  = "bool"                                                              
    value = "false"                                                             
  }                                                                             
                                                                                
  custom_field {                                                                
    name  = "TestInteger"                                                       
    kind  = "int"                                                               
    value = "10"                                                                
  }                                                                         
}

The definition in the provider is like this:

"custom_field": {                                                         
        Type:     schema.TypeSet,                                               
        Optional: true,                                                         
        Elem: &schema.Resource{                                                 
          Schema: map[string]*schema.Schema{                                    
            "name": {                                                           
              Type:     schema.TypeString,                                      
              Required: true,                                                   
            },                                                                  
            "kind": {                                                           
              Type:     schema.TypeString,                                      
              Required: true,                                                   
              ForceNew: true,                                                   
              ValidateFunc: validation.StringInSlice([]string{"string",         
                "bool", "int"}, false),                                         
            },                                                                  
            "value": {                                                          
              Type:     schema.TypeString,                                      
              Required: true,                                                   
            },                                                                  
          },                                                                    
        },                                                                      
      },

In the read function I have d.Set(“custom_fields”, convertApiToCF(tenant.CustomFields)).
convertApiToCF is returning a type [ ]map[string]string, is-it correct ?
Terraform is not detecting changes …

Thanks.

In addition, the data are stored like that in terraform tfstate:

 "tenant_test",                                                    
      "provider": "provider.netbox",                                            
      "instances": [                                                            
        {                                                                       
          "schema_version": 0,                                                  
          "attributes": {                                                       
            "comments": "Some test comments",                                   
            "custom_field": [                                                   
              {                                                                 
                "kind": "bool",                                                 
                "name": "TestBoolean",                                          
                "value": "false"                                                
              },                                                                
              {                                                                 
                "kind": "int",                                                  
                "name": "TestInteger",
"value": "10"                                                   
              }                                                                 
            ],                                                                  
            "description": "Tenant created by terraform",                       
            "id": "22",                                                         
            "name": "Test_Tenant",                                              
            "slug": "Test_Tenant",                                              
            "tags": [                                                           
              "tag1",                                                           
              "tag3"                                                            
            ],                                                                  
            "tenant_group_id": 20                                               
          },                                                                    
          "private": "bnVsbA==",                                                
          "dependencies": [                                                     
            "netbox_tenancy_tenant_group.tenant_group_test"                     
          ]                                                                     
        }                                                                       
      ]                                                                         
    },

Hello,

Any ideas ?
I would like to know if custom_field is stored as a [ ]map[string]string in the tfstate …

Thanks.

Hello,

When the resource is created, the custom fields data is defined like that in the TF:
[map[kind:bool name:TestBoolean value:false] map[kind:int name:TestInteger value:10]]
So I convert into this to send the data to the API:
map[TestBoolean:false TestInteger:10]

When the resource is read, I receive from the API:
map[TestBoolean:false TestDate:<nil> TestInteger:10 TestSelection:<nil> TestString:<nil> TestUrl:<nil>]
So I convert into this to use Set function:
[map[kind:int name:TestInteger value:15] map[kind:bool name:TestBoolean value:false]]

We can see that the value of TestInteger has been changed manually 10 => 15 for a test.
So terraform should told me to update this resource to put 10 instead of 15.
But terraform is displaying that there is no change on this resource, why ?