You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Schema: map[string]*schema.Schema{
"enable_example": {
Type: schema.TypeBool,
Optional: true,
Description: 'Specifies whether the test field is enabled'
},
}
Example API,
type ExampleConfig struct {
// Mode: Mode defines enablement mode for Example features.
//
// Possible values:
// "UNSPECIFIED" - Default value not specified.
// "Disabled" - Disables Example features.
// "Enabled" - Enable Example features.
Mode string `json:"mode,omitempty"`
ForceSendFields []string `json:"-"`
NullFields []string `json:"-"`
}
The field is of a boolean type. We want to map field values to the API config like below,
enable_example field not set by user ------> UNSPECIFIED
enable_example field is set to TRUE ------> Enabled
enable_example field is set to FALSE ------> DISABLED
By doing *ResourceData.Get() or *ResourceData.GetOk(), they either return zero value for primitive types or check whether or not the key has been set to a non-zero value at some point. For boolean, it's false.
We need a Exist flag to determine if a primitive field is set by user in the configuration.
Attempted Solutions
N/A
Proposal
Maybe the following function can be implemented to return both value and exist in configuration.
SDK version
Use-cases
Example field,
Example API,
The field is of a boolean type. We want to map field values to the API config like below,
enable_example
field not set by user ------> UNSPECIFIEDenable_example
field is set to TRUE ------> Enabledenable_example
field is set to FALSE ------> DISABLEDBy doing
*ResourceData.Get()
or*ResourceData.GetOk()
, they either return zero value for primitive types or check whether or not the key has been set to a non-zero value at some point. For boolean, it'sfalse
.We need a Exist flag to determine if a primitive field is set by user in the configuration.
Attempted Solutions
N/A
Proposal
Maybe the following function can be implemented to return both value and exist in configuration.
References
Similar issue: #784
The text was updated successfully, but these errors were encountered: