# Read function does not detect changes

**URL:** <https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297>\
**Category:** Plugin Development\
**Created:** [November 30, 2019, 9:48pm UTC](https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297 "2019-11-30T21:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [November 30, 2019, 9:48pm UTC](https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297/1 "2019-11-30T21:48:45Z")

</div>

Hello,

I have this piece of HCL code:

```auto
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:

```auto
"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.

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [December 2, 2019, 9:08pm UTC](https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297/2 "2019-12-02T21:08:28Z")

</div>

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

```json
 "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"                     
          ]                                                                     
        }                                                                       
      ]                                                                         
    },

```

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [December 8, 2019, 11:12am UTC](https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297/3 "2019-12-08T11:12:00Z")

</div>

Hello,

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

Thanks.

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [December 15, 2019, 9:10pm UTC](https://discuss.hashicorp.com/t/read-function-does-not-detect-changes/4297/4 "2019-12-15T21:10:21Z")

</div>

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 ?
