Skip to content

Utilities for building terraform plugins based on Terraform Plugin Framework

License

Notifications You must be signed in to change notification settings

myoung34/terraform-plugin-framework-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

resource.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()

Validators

FloatInSlice

Validates that the number is one of certain values.

validators.FloatInSlice(1, 4, 6)

StringInSlice

Validates that the string is one of certain values.

validators.StringInSlice(true, "one", "two", "three")

validators.StringInSlice(false, "OnE", "tWo", "tHrEe")

Match

Validates that the string matches a certain regex.

validators.Match(regexp.MustCompile("^[0-9a-fA-F]{6}$"))

NotMatch

Validates that the string does not match a certain regex.

validators.NotMatch(regexp.MustCompile("\\s"))

MinLength

Validates that the string's length is at least of a certain value.

validators.MinLength(1)

MaxLength

Validates that the string's length is at most of a certain value.

validators.MaxLength(5)

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

About

Utilities for building terraform plugins based on Terraform Plugin Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages