diff --git a/internal/framework/boolplanmodifier/default_value.go b/internal/framework/boolplanmodifier/default_value.go deleted file mode 100644 index 3f98c62e60d..00000000000 --- a/internal/framework/boolplanmodifier/default_value.go +++ /dev/null @@ -1,42 +0,0 @@ -package boolplanmodifier - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -type defaultValue struct { - val bool -} - -// DefaultValue return a bool plan modifier that sets the specified value if the planned value is Null. -func DefaultValue(b bool) planmodifier.Bool { - return defaultValue{ - val: b, - } -} - -func (m defaultValue) Description(context.Context) string { - return fmt.Sprintf("If value is not configured, defaults to %t", m.val) -} - -func (m defaultValue) MarkdownDescription(ctx context.Context) string { - return m.Description(ctx) -} - -func (m defaultValue) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { - 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 - } - - resp.PlanValue = types.BoolValue(m.val) -} diff --git a/internal/framework/boolplanmodifier/default_value_test.go b/internal/framework/boolplanmodifier/default_value_test.go deleted file mode 100644 index 06554f68e0f..00000000000 --- a/internal/framework/boolplanmodifier/default_value_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package boolplanmodifier - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func TestDefaultValue(t *testing.T) { - t.Parallel() - - type testCase struct { - plannedValue types.Bool - currentValue types.Bool - defaultValue bool - expectedValue types.Bool - expectError bool - } - tests := map[string]testCase{ - "default bool": { - plannedValue: types.BoolNull(), - currentValue: types.BoolValue(true), - defaultValue: true, - expectedValue: types.BoolValue(true), - }, - "default bool on create": { - plannedValue: types.BoolNull(), - currentValue: types.BoolNull(), - defaultValue: true, - expectedValue: types.BoolValue(true), - }, - } - - for name, test := range tests { - name, test := name, test - t.Run(name, func(t *testing.T) { - t.Parallel() - - ctx := context.Background() - request := planmodifier.BoolRequest{ - Path: path.Root("test"), - PlanValue: test.plannedValue, - StateValue: test.currentValue, - } - response := planmodifier.BoolResponse{ - PlanValue: request.PlanValue, - } - DefaultValue(test.defaultValue).PlanModifyBool(ctx, request, &response) - - if !response.Diagnostics.HasError() && test.expectError { - t.Fatal("expected error, got no error") - } - - if response.Diagnostics.HasError() && !test.expectError { - t.Fatalf("got unexpected error: %s", response.Diagnostics) - } - - if diff := cmp.Diff(response.PlanValue, test.expectedValue); diff != "" { - t.Errorf("unexpected diff (+wanted, -got): %s", diff) - } - }) - } -} diff --git a/internal/framework/int64planmodifier/default_value.go b/internal/framework/int64planmodifier/default_value.go deleted file mode 100644 index 7ff39b433b8..00000000000 --- a/internal/framework/int64planmodifier/default_value.go +++ /dev/null @@ -1,42 +0,0 @@ -package int64planmodifier - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -type defaultValue struct { - val int64 -} - -// DefaultValue return a bool plan modifier that sets the specified value if the planned value is Null. -func DefaultValue(i int64) planmodifier.Int64 { - return defaultValue{ - val: i, - } -} - -func (m defaultValue) Description(context.Context) string { - return fmt.Sprintf("If value is not configured, defaults to %d", m.val) -} - -func (m defaultValue) MarkdownDescription(ctx context.Context) string { - return m.Description(ctx) -} - -func (m defaultValue) PlanModifyInt64(ctx context.Context, req planmodifier.Int64Request, resp *planmodifier.Int64Response) { - 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 - } - - resp.PlanValue = types.Int64Value(m.val) -} diff --git a/internal/framework/int64planmodifier/default_value_test.go b/internal/framework/int64planmodifier/default_value_test.go deleted file mode 100644 index 011f878ced7..00000000000 --- a/internal/framework/int64planmodifier/default_value_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package int64planmodifier - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func TestDefaultValue(t *testing.T) { - t.Parallel() - - type testCase struct { - plannedValue types.Int64 - currentValue types.Int64 - defaultValue int64 - expectedValue types.Int64 - expectError bool - } - tests := map[string]testCase{ - "default int64": { - plannedValue: types.Int64Null(), - currentValue: types.Int64Value(1), - defaultValue: 1, - expectedValue: types.Int64Value(1), - }, - "default int64 on create": { - plannedValue: types.Int64Null(), - currentValue: types.Int64Null(), - defaultValue: 1, - expectedValue: types.Int64Value(1), - }, - } - - for name, test := range tests { - name, test := name, test - t.Run(name, func(t *testing.T) { - t.Parallel() - - ctx := context.Background() - request := planmodifier.Int64Request{ - Path: path.Root("test"), - PlanValue: test.plannedValue, - StateValue: test.currentValue, - } - response := planmodifier.Int64Response{ - PlanValue: request.PlanValue, - } - DefaultValue(test.defaultValue).PlanModifyInt64(ctx, request, &response) - - if !response.Diagnostics.HasError() && test.expectError { - t.Fatal("expected error, got no error") - } - - if response.Diagnostics.HasError() && !test.expectError { - t.Fatalf("got unexpected error: %s", response.Diagnostics) - } - - if diff := cmp.Diff(response.PlanValue, test.expectedValue); diff != "" { - t.Errorf("unexpected diff (+wanted, -got): %s", diff) - } - }) - } -} diff --git a/internal/framework/stringplanmodifier/README.md b/internal/framework/stringplanmodifier/README.md deleted file mode 100644 index 7f6bf3c0209..00000000000 --- a/internal/framework/stringplanmodifier/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Terraform Plugin Framework String Plan Modifiers - -This package contains Terraform Plugin Framework [string plan modifiers](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification). diff --git a/internal/framework/stringplanmodifier/default_value.go b/internal/framework/stringplanmodifier/default_value.go deleted file mode 100644 index 33771e45082..00000000000 --- a/internal/framework/stringplanmodifier/default_value.go +++ /dev/null @@ -1,43 +0,0 @@ -package stringplanmodifier - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -type defaultValue struct { - val string -} - -// DefaultValue return a string plan modifier that sets the specified value if the planned value is Null. -func DefaultValue(s string) planmodifier.String { - return defaultValue{ - val: s, - } -} - -func (m defaultValue) Description(context.Context) string { - return fmt.Sprintf("If value is not configured, defaults to %s", m.val) -} - -func (m defaultValue) MarkdownDescription(ctx context.Context) string { - return m.Description(ctx) -} - -func (m defaultValue) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *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 - } - - resp.PlanValue = types.StringValue(m.val) -} diff --git a/internal/framework/stringplanmodifier/default_value_test.go b/internal/framework/stringplanmodifier/default_value_test.go deleted file mode 100644 index 03f9a675df5..00000000000 --- a/internal/framework/stringplanmodifier/default_value_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package stringplanmodifier - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func TestDefaultValue(t *testing.T) { - t.Parallel() - - type testCase struct { - plannedValue types.String - currentValue types.String - defaultValue string - expectedValue types.String - expectError bool - } - tests := map[string]testCase{ - "non-default non-Null string": { - plannedValue: types.StringValue("gamma"), - currentValue: types.StringValue("beta"), - defaultValue: "alpha", - expectedValue: types.StringValue("gamma"), - }, - "non-default non-Null string, current Null": { - plannedValue: types.StringValue("gamma"), - currentValue: types.StringNull(), - defaultValue: "alpha", - expectedValue: types.StringValue("gamma"), - }, - "non-default Null string, current Null": { - plannedValue: types.StringNull(), - currentValue: types.StringValue("beta"), - defaultValue: "alpha", - expectedValue: types.StringValue("alpha"), - }, - "default string": { - plannedValue: types.StringNull(), - currentValue: types.StringValue("alpha"), - defaultValue: "alpha", - expectedValue: types.StringValue("alpha"), - }, - "default string on create": { - plannedValue: types.StringNull(), - currentValue: types.StringNull(), - defaultValue: "alpha", - expectedValue: types.StringValue("alpha"), - }, - } - - for name, test := range tests { - name, test := name, test - t.Run(name, func(t *testing.T) { - t.Parallel() - - ctx := context.Background() - request := planmodifier.StringRequest{ - Path: path.Root("test"), - PlanValue: test.plannedValue, - StateValue: test.currentValue, - } - response := planmodifier.StringResponse{ - PlanValue: request.PlanValue, - } - DefaultValue(test.defaultValue).PlanModifyString(ctx, request, &response) - - if !response.Diagnostics.HasError() && test.expectError { - t.Fatal("expected error, got no error") - } - - if response.Diagnostics.HasError() && !test.expectError { - t.Fatalf("got unexpected error: %s", response.Diagnostics) - } - - if diff := cmp.Diff(response.PlanValue, test.expectedValue); diff != "" { - t.Errorf("unexpected diff (+wanted, -got): %s", diff) - } - }) - } -} diff --git a/internal/service/cognitoidp/managed_user_pool_client.go b/internal/service/cognitoidp/managed_user_pool_client.go index ff84e79931a..c615a80f0df 100644 --- a/internal/service/cognitoidp/managed_user_pool_client.go +++ b/internal/service/cognitoidp/managed_user_pool_client.go @@ -21,13 +21,13 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" - fwstringplanmodifier "github.com/hashicorp/terraform-provider-aws/internal/framework/stringplanmodifier" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -305,9 +305,7 @@ func (r *resourceManagedUserPoolClient) Schema(ctx context.Context, request reso "access_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeHours), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeHours), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, @@ -315,9 +313,7 @@ func (r *resourceManagedUserPoolClient) Schema(ctx context.Context, request reso "id_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeHours), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeHours), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, @@ -325,9 +321,7 @@ func (r *resourceManagedUserPoolClient) Schema(ctx context.Context, request reso "refresh_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeDays), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeDays), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, diff --git a/internal/service/cognitoidp/user_pool_client.go b/internal/service/cognitoidp/user_pool_client.go index 211f004a25d..17426ff897f 100644 --- a/internal/service/cognitoidp/user_pool_client.go +++ b/internal/service/cognitoidp/user_pool_client.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -30,7 +31,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" - fwstringplanmodifier "github.com/hashicorp/terraform-provider-aws/internal/framework/stringplanmodifier" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -300,9 +300,7 @@ func (r *resourceUserPoolClient) Schema(ctx context.Context, request resource.Sc "access_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeHours), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeHours), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, @@ -310,9 +308,7 @@ func (r *resourceUserPoolClient) Schema(ctx context.Context, request resource.Sc "id_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeHours), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeHours), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, @@ -320,9 +316,7 @@ func (r *resourceUserPoolClient) Schema(ctx context.Context, request resource.Sc "refresh_token": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(cognitoidentityprovider.TimeUnitsTypeDays), - }, + Default: stringdefault.StaticString(cognitoidentityprovider.TimeUnitsTypeDays), Validators: []validator.String{ stringvalidator.OneOf(cognitoidentityprovider.TimeUnitsType_Values()...), }, diff --git a/internal/service/ds/trust.go b/internal/service/ds/trust.go index 36b724c9aa2..0fdc0074d8a 100644 --- a/internal/service/ds/trust.go +++ b/internal/service/ds/trust.go @@ -15,8 +15,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -26,9 +28,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/framework" - "github.com/hashicorp/terraform-provider-aws/internal/framework/boolplanmodifier" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" - fwstringplanmodifier "github.com/hashicorp/terraform-provider-aws/internal/framework/stringplanmodifier" fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -79,9 +79,7 @@ func (r *resourceTrust) Schema(ctx context.Context, req resource.SchemaRequest, "delete_associated_conditional_forwarder": schema.BoolAttribute{ Computed: true, Optional: true, - PlanModifiers: []planmodifier.Bool{ - boolplanmodifier.DefaultValue(false), - }, + Default: booldefault.StaticBool(false), }, "directory_id": schema.StringAttribute{ Required: true, @@ -144,12 +142,10 @@ func (r *resourceTrust) Schema(ctx context.Context, req resource.SchemaRequest, "trust_type": schema.StringAttribute{ Optional: true, Computed: true, + Default: stringdefault.StaticString(string(awstypes.TrustTypeForest)), Validators: []validator.String{ enum.FrameworkValidate[awstypes.TrustType](), }, - PlanModifiers: []planmodifier.String{ - fwstringplanmodifier.DefaultValue(string(awstypes.TrustTypeForest)), - }, }, }, } diff --git a/internal/service/resourceexplorer2/view.go b/internal/service/resourceexplorer2/view.go index 737c403a1d3..2881c9fe67e 100644 --- a/internal/service/resourceexplorer2/view.go +++ b/internal/service/resourceexplorer2/view.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" @@ -27,7 +28,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/framework" - fwboolplanmodifier "github.com/hashicorp/terraform-provider-aws/internal/framework/boolplanmodifier" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -60,9 +60,7 @@ func (r *resourceView) Schema(ctx context.Context, request resource.SchemaReques "default_view": schema.BoolAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.Bool{ - fwboolplanmodifier.DefaultValue(false), - }, + Default: booldefault.StaticBool(false), }, "id": framework.IDAttribute(), "name": schema.StringAttribute{