Hi Community,
I am developing a provider for the ServiceNow CMDB that has a large number of resources (can be upwards of 700) and each resource has a large number of schema elements (at least 96 elements), many of the elements are optional. My repository is here: (https://github.com/philw764/terraform-provider-servicenowcmdb)
My question is what is the best method to determine what elements have values set. It would be nice if there was a method provided by Terraform to get a list of the schema element keys that have values defined.
The approach I am currently thinking is to range over ResourceData.State() and process the key and value pairs and using “GetOk()” method to access the ResourceData. Something along the lines of the following:
x := resourceData.State()
for key, value := range x.Attributes {
if val, ok := resourceData.GetOk(key); ok {
…….do something with key and val
} else {
…. ignore
}
}
Coding in Golang and Terraform is very new to me so I am still learning, any advice appreciated.
Phil.