Skip to content

Latest commit

 

History

History
65 lines (41 loc) · 2.05 KB

File metadata and controls

65 lines (41 loc) · 2.05 KB

Terraform Plugin Framework Utilities

Modifiers

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 DefaultType3 DefaultType3 UseStateForUnknown3

We also have more modifiers that helps with ergonomics.

DefaultType

Use the appropriate function for type whose name starts with Default.

modifiers.DefaultBool(true)

modifiers.DefaultString("")

modifiers.DefaultFloat(3)

NullableType

Use the appropriate function for type whose name starts with Nullable.

modifiers.NullableBool()

modifiers.NullableString()

modifiers.NullableFloat()

UseStateForUnknown

Use UseStateForUnknown from Terraform plugin framework.

UseStateForUnknown()

NOTE: Make sure that you omit this property when sending payloads during both creation and updation.

UnknownAttributesOnUnknown

Use this when you have a nested block of SingleNestedAttributes and the block is fully optional.

modifiers.UnknownAttributesOnUnknown()

Footnotes

  1. 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 "", int 0 etc..

  2. This scenairo is impossible.

  3. 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