43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
)
|
|
|
|
// Hashicorp, what the fuck are you making me write this shit for?. Give me back sdkv2 defaults. This is insane
|
|
|
|
func StringDefaultValue(v types.String) *stringDefaultValue {
|
|
return &stringDefaultValue{v}
|
|
}
|
|
|
|
type stringDefaultValue struct {
|
|
DefaultValue types.String
|
|
}
|
|
|
|
var _ planmodifier.String = (*stringDefaultValue)(nil)
|
|
|
|
func (s *stringDefaultValue) Description(ctx context.Context) string {
|
|
return "stringDefaultValue Description"
|
|
}
|
|
|
|
func (s *stringDefaultValue) MarkdownDescription(ctx context.Context) string {
|
|
return "stringDefaultValue MarkdownDescription"
|
|
}
|
|
|
|
func (s *stringDefaultValue) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, res *planmodifier.StringResponse) {
|
|
// If the attribute configuration is not null, we are done here
|
|
if !req.ConfigValue.IsNull() {
|
|
return
|
|
}
|
|
|
|
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence
|
|
// has already been applied, and we don't want to interfere.
|
|
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() {
|
|
return
|
|
}
|
|
|
|
res.PlanValue = s.DefaultValue
|
|
}
|