When I started using the new terraform framework I needed to set a default value for different attributes (strings, booleans etc) and I ended up (I can’t recall now how) implementing the setting of a default value using plan modifiers.
I’ve since discovered a simpler way using the <T>default
packages (e.g. booldefault, stringdefault etc).
So, my question is: what’s the difference and why/when should I use one over the other? as they both seem to do the same thing.
EDIT: I’m still using a plan modifier for the use case where I have a fully computed attribute and I can reduce the “known after plan” message. So in the following example, once a “Service ID” is generated, it never changes…
"id": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Alphanumeric string identifying the service",
PlanModifiers: []planmodifier.String{
// UseStateForUnknown is useful for reducing (known after apply) plan
// outputs for computed attributes which are known to not change over time.
stringplanmodifier.UseStateForUnknown(),
},
},
Thanks.