vmware / terraform-provider-nsxt

Terraform VMware NSX-T provider
https://www.terraform.io/docs/providers/nsxt/
Other
123 stars 80 forks source link

[WIP] Skip attribute processing when no values is assigned in schema #1242

Closed ksamoray closed 2 weeks ago

ksamoray commented 3 weeks ago

When a value is not assigned to the schema for some attribute, using d.Get("attr_name").(type) will return a zero or a null string.

That would break when this value is not allowed by NSX and usually we protect against this with an if statement which would assign this attribute a value only when it's set in the schema. With required attributes that cannot happen as NSX will check that a value is assigned prior to the Create() call.

ksamoray commented 3 weeks ago

/test-all

ksamoray commented 3 weeks ago

/test-all

ksamoray commented 3 weeks ago

/test-all

ksamoray commented 3 weeks ago

/test-all

annakhm commented 3 weeks ago

We need to be able to set empty value as in some cases, this is the way to nullify value on update. We have OmitIfEmpty boolean flag to control this behavior

ksamoray commented 3 weeks ago

@annakhm Isn't it better to nullify by default and set when needed?

annakhm commented 3 weeks ago

@annakhm Isn't it better to nullify by default and set when needed?

There is a difference between empty value (translates to field name with empty value in API call) and nil value (field name is not mentioned in the request). The latter is sometimes ignored with NSX Patch behavior (which is correct behavior, since attributes that are not specified should not be touched with Patch. In those cases, explicit empty value is needed to remove assigned value.

ksamoray commented 3 weeks ago

/test-all