The API must work like Terraform. If a value is not set, nothing is sent to the API.
For each attribute, we must think about three flows.
- The attribute is set to some value and sent to the API.
- The attribute is set to a zero value and sent to the API.
- The attribute is not set (
nil) and sent to the API.
For each of these flows there is an associated read from the API. We need to have a clear understanding of what the API should return in each of these cases. The API should be designed to be consumed by Terraform.
For this example I will use the comment attribute of the Network object.
- The
commentattribute is set to "test" in theNetworkobject and sent to the API. - The API will return the
Networkobject with thecommentattribute set to "test". - The
commentattribute is not set (nil) in theNetworkobject and sent to the API. - The API will return the
Networkobject with thecommentattribute set to "test". - The
commentattribute is set to "" in theNetworkobject and sent to the API. - The API will return the
Networkobject with thecommentattribute set to "".
For attributes like these, we use a pointer, so we can differentiate between the zero value and nil.
"test" --> create --> "test"
"test" <-- read <-- "test"
"" --> update --> ""
"" <-- read <-- ""
nil --> update --> ""
"" <-- read <-- ""