From 709f3270195a9a004a77643f60ea0ab505db6ffc Mon Sep 17 00:00:00 2001 From: Moumita Mukherjee Date: Thu, 22 Aug 2024 15:17:03 +0000 Subject: [PATCH 1/9] Add failure code and failure message to batch get collection --- .../opensearchserverless/collection.go | 16 +++++++++++++ .../collection_data_source.go | 10 ++++++++ internal/service/opensearchserverless/find.go | 24 +++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/internal/service/opensearchserverless/collection.go b/internal/service/opensearchserverless/collection.go index 44577f90261..4a37960117b 100644 --- a/internal/service/opensearchserverless/collection.go +++ b/internal/service/opensearchserverless/collection.go @@ -56,6 +56,8 @@ type resourceCollectionData struct { TagsAll types.Map `tfsdk:"tags_all"` Timeouts timeouts.Value `tfsdk:"timeouts"` Type types.String `tfsdk:"type"` + FailureMessage types.String `tfsdk:"failure_message"` + FailureCode types.String `tfsdk:"failure_code"` } const ( @@ -122,6 +124,20 @@ func (r *resourceCollection) Schema(ctx context.Context, req resource.SchemaRequ enum.FrameworkValidate[awstypes.StandbyReplicas](), }, }, + "failure_message": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "failure_code": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), names.AttrType: schema.StringAttribute{ diff --git a/internal/service/opensearchserverless/collection_data_source.go b/internal/service/opensearchserverless/collection_data_source.go index 0ce4e062c4e..ce6a0355196 100644 --- a/internal/service/opensearchserverless/collection_data_source.go +++ b/internal/service/opensearchserverless/collection_data_source.go @@ -73,6 +73,14 @@ func (d *dataSourceCollection) Schema(_ context.Context, _ datasource.SchemaRequ "last_modified_date": schema.StringAttribute{ Computed: true, }, + "failure_message": schema.StringAttribute{ + Optional: true, + Computed: true, + }, + "failure_code": schema.StringAttribute{ + Optional: true, + Computed: true, + }, names.AttrName: schema.StringAttribute{ Optional: true, Computed: true, @@ -169,4 +177,6 @@ type dataSourceCollectionData struct { StandbyReplicas types.String `tfsdk:"standby_replicas"` Tags types.Map `tfsdk:"tags"` Type types.String `tfsdk:"type"` + FailureMessage types.String `tfsdk:"failure_message"` + FailureCode types.String `tfsdk:"failure_code"` } diff --git a/internal/service/opensearchserverless/find.go b/internal/service/opensearchserverless/find.go index 67167cf892d..ef2493f933b 100644 --- a/internal/service/opensearchserverless/find.go +++ b/internal/service/opensearchserverless/find.go @@ -61,7 +61,17 @@ func findCollectionByID(ctx context.Context, conn *opensearchserverless.Client, return nil, tfresource.NewEmptyResultError(in) } - return &out.CollectionDetails[0], nil + collectionDetail := &out.CollectionDetails[0] + + // Ensure default values if nil + if collectionDetail.FailureCode == nil { + collectionDetail.FailureCode = aws.String("") + } + if collectionDetail.FailureMessage == nil { + collectionDetail.FailureMessage = aws.String("") + } + + return collectionDetail, nil } func findCollectionByName(ctx context.Context, conn *opensearchserverless.Client, name string) (*types.CollectionDetail, error) { @@ -89,7 +99,17 @@ func findCollectionByName(ctx context.Context, conn *opensearchserverless.Client return nil, tfresource.NewTooManyResultsError(len(out.CollectionDetails), in) } - return &out.CollectionDetails[0], nil + collectionDetail := &out.CollectionDetails[0] + + // Ensure default values if nil + if collectionDetail.FailureCode == nil { + collectionDetail.FailureCode = aws.String("") + } + if collectionDetail.FailureMessage == nil { + collectionDetail.FailureMessage = aws.String("") + } + + return collectionDetail, nil } func findSecurityConfigByID(ctx context.Context, conn *opensearchserverless.Client, id string) (*types.SecurityConfigDetail, error) { From 437404ad8f13810bb6a940c19fb6ee5d9ba306b8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 10:57:05 -0500 Subject: [PATCH 2/9] aws_opensearchserverless_collection: datasource: attributes in alphabetical order --- .../collection_data_source.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/service/opensearchserverless/collection_data_source.go b/internal/service/opensearchserverless/collection_data_source.go index 9b67a6d75b6..3d6bab18643 100644 --- a/internal/service/opensearchserverless/collection_data_source.go +++ b/internal/service/opensearchserverless/collection_data_source.go @@ -55,6 +55,12 @@ func (d *dataSourceCollection) Schema(_ context.Context, _ datasource.SchemaRequ names.AttrDescription: schema.StringAttribute{ Computed: true, }, + "failure_message": schema.StringAttribute{ + Computed: true, + }, + "failure_code": schema.StringAttribute{ + Computed: true, + }, names.AttrID: schema.StringAttribute{ Optional: true, Computed: true, @@ -73,14 +79,6 @@ func (d *dataSourceCollection) Schema(_ context.Context, _ datasource.SchemaRequ "last_modified_date": schema.StringAttribute{ Computed: true, }, - "failure_message": schema.StringAttribute{ - Optional: true, - Computed: true, - }, - "failure_code": schema.StringAttribute{ - Optional: true, - Computed: true, - }, names.AttrName: schema.StringAttribute{ Optional: true, Computed: true, @@ -168,6 +166,8 @@ type dataSourceCollectionData struct { ARN types.String `tfsdk:"arn"` CollectionEndpoint types.String `tfsdk:"collection_endpoint"` CreatedDate types.String `tfsdk:"created_date"` + FailureMessage types.String `tfsdk:"failure_message"` + FailureCode types.String `tfsdk:"failure_code"` DashboardEndpoint types.String `tfsdk:"dashboard_endpoint"` Description types.String `tfsdk:"description"` ID types.String `tfsdk:"id"` @@ -177,6 +177,4 @@ type dataSourceCollectionData struct { StandbyReplicas types.String `tfsdk:"standby_replicas"` Tags tftags.Map `tfsdk:"tags"` Type types.String `tfsdk:"type"` - FailureMessage types.String `tfsdk:"failure_message"` - FailureCode types.String `tfsdk:"failure_code"` } From dca104c187a4343ae94dc78cc37653bb872cf72d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 11:22:54 -0500 Subject: [PATCH 3/9] cleanup finders --- internal/service/opensearchserverless/find.go | 117 ++++++------------ 1 file changed, 38 insertions(+), 79 deletions(-) diff --git a/internal/service/opensearchserverless/find.go b/internal/service/opensearchserverless/find.go index c9e77ffff24..b75868cff1d 100644 --- a/internal/service/opensearchserverless/find.go +++ b/internal/service/opensearchserverless/find.go @@ -5,7 +5,6 @@ package opensearchserverless import ( "context" - "errors" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/opensearchserverless" @@ -21,15 +20,15 @@ func findAccessPolicyByNameAndType(ctx context.Context, conn *opensearchserverle Type: types.AccessPolicyType(policyType), } out, err := conn.GetAccessPolicy(ctx, in) - if err != nil { - var nfe *types.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, } + } + if err != nil { return nil, err } @@ -45,33 +44,19 @@ func findCollectionByID(ctx context.Context, conn *opensearchserverless.Client, Ids: []string{id}, } out, err := conn.BatchGetCollection(ctx, in) - if err != nil { - var nfe *types.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } - } - - return nil, err - } - if out == nil || out.CollectionDetails == nil || len(out.CollectionDetails) == 0 { - return nil, tfresource.NewEmptyResultError(in) + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } } - collectionDetail := &out.CollectionDetails[0] - - // Ensure default values if nil - if collectionDetail.FailureCode == nil { - collectionDetail.FailureCode = aws.String("") - } - if collectionDetail.FailureMessage == nil { - collectionDetail.FailureMessage = aws.String("") + if err != nil { + return nil, err } - return collectionDetail, nil + return tfresource.AssertSingleValueResult(out.CollectionDetails) } func findCollectionByName(ctx context.Context, conn *opensearchserverless.Client, name string) (*types.CollectionDetail, error) { @@ -79,37 +64,19 @@ func findCollectionByName(ctx context.Context, conn *opensearchserverless.Client Names: []string{name}, } out, err := conn.BatchGetCollection(ctx, in) - if err != nil { - var nfe *types.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } - } - - return nil, err - } - - if out == nil || out.CollectionDetails == nil || len(out.CollectionDetails) == 0 { - return nil, tfresource.NewEmptyResultError(in) - } - if len(out.CollectionDetails) > 1 { - return nil, tfresource.NewTooManyResultsError(len(out.CollectionDetails), in) + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } } - collectionDetail := &out.CollectionDetails[0] - - // Ensure default values if nil - if collectionDetail.FailureCode == nil { - collectionDetail.FailureCode = aws.String("") - } - if collectionDetail.FailureMessage == nil { - collectionDetail.FailureMessage = aws.String("") + if err != nil { + return nil, err } - return collectionDetail, nil + return tfresource.AssertSingleValueResult(out.CollectionDetails) } func findSecurityConfigByID(ctx context.Context, conn *opensearchserverless.Client, id string) (*types.SecurityConfigDetail, error) { @@ -117,15 +84,15 @@ func findSecurityConfigByID(ctx context.Context, conn *opensearchserverless.Clie Id: aws.String(id), } out, err := conn.GetSecurityConfig(ctx, in) - if err != nil { - var nfe *types.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, } + } + if err != nil { return nil, err } @@ -142,15 +109,15 @@ func findSecurityPolicyByNameAndType(ctx context.Context, conn *opensearchserver Type: types.SecurityPolicyType(policyType), } out, err := conn.GetSecurityPolicy(ctx, in) - if err != nil { - var nfe *types.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, } + } + if err != nil { return nil, err } @@ -183,13 +150,5 @@ func findLifecyclePolicyByNameAndType(ctx context.Context, conn *opensearchserve return nil, err } - if out == nil || out.LifecyclePolicyDetails == nil || len(out.LifecyclePolicyDetails) == 0 { - return nil, tfresource.NewEmptyResultError(in) - } - - if len(out.LifecyclePolicyDetails) > 1 { - return nil, tfresource.NewTooManyResultsError(len(out.LifecyclePolicyDetails), in) - } - - return &out.LifecyclePolicyDetails[0], nil + return tfresource.AssertSingleValueResult(out.LifecyclePolicyDetails) } From 3c46a4b75ed80b764767f3acd6a9f55db7b225be Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 11:44:12 -0500 Subject: [PATCH 4/9] aws_opensearchserverless_collection: add failure message to waiter error, remove attributes that will not be set because of error --- .../opensearchserverless/collection.go | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/internal/service/opensearchserverless/collection.go b/internal/service/opensearchserverless/collection.go index 04534958913..e2dfcda3c8e 100644 --- a/internal/service/opensearchserverless/collection.go +++ b/internal/service/opensearchserverless/collection.go @@ -5,6 +5,7 @@ package opensearchserverless import ( "context" + "fmt" "time" "github.com/YakDriver/regexache" @@ -56,8 +57,6 @@ type resourceCollectionData struct { TagsAll tftags.Map `tfsdk:"tags_all"` Timeouts timeouts.Value `tfsdk:"timeouts"` Type types.String `tfsdk:"type"` - FailureMessage types.String `tfsdk:"failure_message"` - FailureCode types.String `tfsdk:"failure_code"` } const ( @@ -124,20 +123,6 @@ func (r *resourceCollection) Schema(ctx context.Context, req resource.SchemaRequ enum.FrameworkValidate[awstypes.StandbyReplicas](), }, }, - "failure_message": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - "failure_code": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), names.AttrType: schema.StringAttribute{ @@ -346,6 +331,10 @@ func waitCollectionCreated(ctx context.Context, conn *opensearchserverless.Clien outputRaw, err := stateConf.WaitForStateContext(ctx) if output, ok := outputRaw.(*awstypes.CollectionDetail); ok { + if output.Status == awstypes.CollectionStatusFailed { + tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.ToString(output.FailureCode), aws.ToString(output.FailureMessage))) + } + return output, err } @@ -365,6 +354,10 @@ func waitCollectionDeleted(ctx context.Context, conn *opensearchserverless.Clien outputRaw, err := stateConf.WaitForStateContext(ctx) if output, ok := outputRaw.(*awstypes.CollectionDetail); ok { + if output.Status == awstypes.CollectionStatusFailed { + tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.ToString(output.FailureCode), aws.ToString(output.FailureMessage))) + } + return output, err } From d08a4297c677a98a51402a80f634395b6adbc16d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 11:51:35 -0500 Subject: [PATCH 5/9] aws_opensearchserverless_security_policy: use smithyjson type --- .../opensearchserverless/security_policy.go | 28 +++++++++++-------- .../service_package_gen.go | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/internal/service/opensearchserverless/security_policy.go b/internal/service/opensearchserverless/security_policy.go index a962c98f730..e5b78dbbe3b 100644 --- a/internal/service/opensearchserverless/security_policy.go +++ b/internal/service/opensearchserverless/security_policy.go @@ -11,8 +11,8 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/opensearchserverless" + "github.com/aws/aws-sdk-go-v2/service/opensearchserverless/document" awstypes "github.com/aws/aws-sdk-go-v2/service/opensearchserverless/types" - "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -26,22 +26,23 @@ import ( "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/flex" + 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" ) -// @FrameworkResource +// @FrameworkResource(name="Security Policy") func newResourceSecurityPolicy(_ context.Context) (resource.ResourceWithConfigure, error) { return &resourceSecurityPolicy{}, nil } type resourceSecurityPolicyData struct { - Description types.String `tfsdk:"description"` - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Policy jsontypes.Normalized `tfsdk:"policy"` - PolicyVersion types.String `tfsdk:"policy_version"` - Type types.String `tfsdk:"type"` + Description types.String `tfsdk:"description"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Policy fwtypes.SmithyJSON[document.Interface] `tfsdk:"policy"` + PolicyVersion types.String `tfsdk:"policy_version"` + Type types.String `tfsdk:"type"` } const ( @@ -76,7 +77,7 @@ func (r *resourceSecurityPolicy) Schema(ctx context.Context, req resource.Schema }, }, names.AttrPolicy: schema.StringAttribute{ - CustomType: jsontypes.NormalizedType{}, + CustomType: fwtypes.NewSmithyJSONType(ctx, document.NewLazyDocument), Required: true, Validators: []validator.String{ stringvalidator.LengthBetween(1, 20480), @@ -182,8 +183,13 @@ func (r *resourceSecurityPolicy) Update(ctx context.Context, req resource.Update return } - if !plan.Description.Equal(state.Description) || - !plan.Policy.Equal(state.Policy) { + diff, diags := flex.Calculate(ctx, plan, state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + if !diff.HasChanges() { input := &opensearchserverless.UpdateSecurityPolicyInput{} resp.Diagnostics.Append(flex.Expand(ctx, plan, input)...) diff --git a/internal/service/opensearchserverless/service_package_gen.go b/internal/service/opensearchserverless/service_package_gen.go index 0e23ad545cf..ef3654f9eed 100644 --- a/internal/service/opensearchserverless/service_package_gen.go +++ b/internal/service/opensearchserverless/service_package_gen.go @@ -57,6 +57,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic }, { Factory: newResourceSecurityPolicy, + Name: "Security Policy", }, { Factory: newVPCEndpointResource, From e005a320e67e7de6a5d82d59f6ec6080b97b3791 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 11:54:09 -0500 Subject: [PATCH 6/9] run go generate --- internal/service/opensearchserverless/access_policy.go | 2 +- .../service/opensearchserverless/security_policy_data_source.go | 2 +- internal/service/opensearchserverless/service_package_gen.go | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/service/opensearchserverless/access_policy.go b/internal/service/opensearchserverless/access_policy.go index 5d8441709fa..cbe2eba04ca 100644 --- a/internal/service/opensearchserverless/access_policy.go +++ b/internal/service/opensearchserverless/access_policy.go @@ -30,7 +30,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @FrameworkResource +// @FrameworkResource(name="Access Policy) func newResourceAccessPolicy(_ context.Context) (resource.ResourceWithConfigure, error) { return &resourceAccessPolicy{}, nil } diff --git a/internal/service/opensearchserverless/security_policy_data_source.go b/internal/service/opensearchserverless/security_policy_data_source.go index c4aa9017292..1ac13df479f 100644 --- a/internal/service/opensearchserverless/security_policy_data_source.go +++ b/internal/service/opensearchserverless/security_policy_data_source.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKDataSource("aws_opensearchserverless_security_policy") +// @SDKDataSource("aws_opensearchserverless_security_policy", name="Security Policy") func DataSourceSecurityPolicy() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceSecurityPolicyRead, diff --git a/internal/service/opensearchserverless/service_package_gen.go b/internal/service/opensearchserverless/service_package_gen.go index ef3654f9eed..2c16ac2432a 100644 --- a/internal/service/opensearchserverless/service_package_gen.go +++ b/internal/service/opensearchserverless/service_package_gen.go @@ -39,6 +39,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic return []*types.ServicePackageFrameworkResource{ { Factory: newResourceAccessPolicy, + Name: "Access Policy", }, { Factory: newResourceCollection, @@ -71,6 +72,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac { Factory: DataSourceSecurityPolicy, TypeName: "aws_opensearchserverless_security_policy", + Name: "Security Policy", }, { Factory: dataSourceVPCEndpoint, From c1bb60a72327593774ffdeaa1cb1eb3d676f0c39 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 12:18:52 -0500 Subject: [PATCH 7/9] aws_opensearchserverless_security_policy: use enum type for Type --- .../opensearchserverless/security_policy.go | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/service/opensearchserverless/security_policy.go b/internal/service/opensearchserverless/security_policy.go index e5b78dbbe3b..e2e273488ac 100644 --- a/internal/service/opensearchserverless/security_policy.go +++ b/internal/service/opensearchserverless/security_policy.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-provider-aws/internal/create" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "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/flex" @@ -37,12 +36,12 @@ func newResourceSecurityPolicy(_ context.Context) (resource.ResourceWithConfigur } type resourceSecurityPolicyData struct { - Description types.String `tfsdk:"description"` - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Policy fwtypes.SmithyJSON[document.Interface] `tfsdk:"policy"` - PolicyVersion types.String `tfsdk:"policy_version"` - Type types.String `tfsdk:"type"` + Description types.String `tfsdk:"description"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Policy fwtypes.SmithyJSON[document.Interface] `tfsdk:"policy"` + PolicyVersion types.String `tfsdk:"policy_version"` + Type fwtypes.StringEnum[awstypes.SecurityPolicyType] `tfsdk:"type"` } const ( @@ -90,10 +89,8 @@ func (r *resourceSecurityPolicy) Schema(ctx context.Context, req resource.Schema }, }, names.AttrType: schema.StringAttribute{ - Required: true, - Validators: []validator.String{ - enum.FrameworkValidate[awstypes.SecurityPolicyType](), - }, + CustomType: fwtypes.StringEnumType[awstypes.SecurityPolicyType](), + Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, @@ -189,7 +186,7 @@ func (r *resourceSecurityPolicy) Update(ctx context.Context, req resource.Update return } - if !diff.HasChanges() { + if diff.HasChanges() { input := &opensearchserverless.UpdateSecurityPolicyInput{} resp.Diagnostics.Append(flex.Expand(ctx, plan, input)...) @@ -226,7 +223,7 @@ func (r *resourceSecurityPolicy) Delete(ctx context.Context, req resource.Delete _, err := conn.DeleteSecurityPolicy(ctx, &opensearchserverless.DeleteSecurityPolicyInput{ ClientToken: aws.String(id.UniqueId()), Name: state.Name.ValueStringPointer(), - Type: awstypes.SecurityPolicyType(state.Type.ValueString()), + Type: state.Type.ValueEnum(), }) if err != nil { var nfe *awstypes.ResourceNotFoundException @@ -251,7 +248,7 @@ func (r *resourceSecurityPolicy) ImportState(ctx context.Context, req resource.I state := resourceSecurityPolicyData{ ID: types.StringValue(parts[0]), Name: types.StringValue(parts[0]), - Type: types.StringValue(parts[1]), + Type: fwtypes.StringEnumValue(awstypes.SecurityPolicyType(parts[1])), } diags := resp.State.Set(ctx, &state) From 32784703a6dc578610765aed61b3be53f91838c3 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 13:26:03 -0500 Subject: [PATCH 8/9] update documentation --- website/docs/d/opensearchserverless_collection.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/d/opensearchserverless_collection.html.markdown b/website/docs/d/opensearchserverless_collection.html.markdown index b729fdee862..6d0a1d67c77 100644 --- a/website/docs/d/opensearchserverless_collection.html.markdown +++ b/website/docs/d/opensearchserverless_collection.html.markdown @@ -36,6 +36,8 @@ This data source exports the following attributes in addition to the arguments a * `created_date` - Date the Collection was created. * `dashboard_endpoint` - Collection-specific endpoint used to access OpenSearch Dashboards. * `description` - Description of the collection. +* `failure_code` - A failure code associated with the collection. +* `failure_reason` - A failure reason associated with the collection. * `kms_key_arn` - The ARN of the Amazon Web Services KMS key used to encrypt the collection. * `last_modified_date` - Date the Collection was last modified. * `standby_replicas` - Indicates whether standby replicas should be used for a collection. From 395f75fc61f67c1fde12aca3b809faa88ec74f83 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 25 Sep 2024 13:27:25 -0500 Subject: [PATCH 9/9] add CHANGELOG entry --- .changelog/38995.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38995.txt diff --git a/.changelog/38995.txt b/.changelog/38995.txt new file mode 100644 index 00000000000..1ef0a130444 --- /dev/null +++ b/.changelog/38995.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +data-source/aws_opensearchserverless_collection: Add `failure_code` and `failure_reason` attributes +``` \ No newline at end of file