Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exist Check on Primitive Types rather than checking if they has been set to a non-zero value #1140

Open
DDDDarrenWB opened this issue Feb 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@DDDDarrenWB
Copy link

DDDDarrenWB commented Feb 7, 2023

SDK version

v2.24.0

Use-cases

Example field,

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,

  1. enable_example field not set by user ------> UNSPECIFIED
  2. enable_example field is set to TRUE ------> Enabled
  3. 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.

func (d *ResourceData) GetExist(key string) (value interface{}, exist bool)

References

Similar issue: #784

@DDDDarrenWB DDDDarrenWB added the enhancement New feature or request label Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant