Assuming that we have a field of a certain type (int
, boolean
, string
etc..), that field can either be nullable or not and also can have various defaults. We need our modifiers to work with all these scenarios.
nullable | null default | empty default1 | known default | random default |
---|---|---|---|---|
no | X2 | DefaultType |
DefaultType |
UseStateForUnknown |
yes | NullableType |
DefaultType 3 |
DefaultType 3 |
UseStateForUnknown 3 |
We also have more modifiers that helps with ergonomics.
Use the appropriate function for type whose name starts with Default
.
modifiers.DefaultBool(true)
modifiers.DefaultString("")
modifiers.DefaultFloat(3)
Use the appropriate function for type whose name starts with Nullable
.
modifiers.NullableBool()
modifiers.NullableString()
modifiers.NullableFloat()
Use UseStateForUnknown
from Terraform plugin framework.
UseStateForUnknown()
NOTE: Make sure that you omit this property when sending payloads during both creation and updation.
Use this when you have a nested block of SingleNestedAttributes
and the block is fully optional.
modifiers.UnknownAttributesOnUnknown()
Footnotes
-
empty default means that the default value of the field on the server is the empty value for that type in golang. e.g. boolean
false
, string""
, int0
etc.. ↩ -
This scenairo is impossible. ↩
-
End users will not be able to set the value of the field as
null
in the server. This is a limitation on terraform itself. ↩ ↩2 ↩3