diff --git a/.changelog/39536.txt b/.changelog/39536.txt new file mode 100644 index 00000000000..e36b40806e7 --- /dev/null +++ b/.changelog/39536.txt @@ -0,0 +1,3 @@ +```release-note:note +resource/aws_simpledb_domain: The `aws_simpledb_domain` resource has been deprecated and will be removed in a future version. Use Amazon DynamoDB instead +``` diff --git a/internal/service/simpledb/domain.go b/internal/service/simpledb/domain.go index 13452d14548..9888c4eef61 100644 --- a/internal/service/simpledb/domain.go +++ b/internal/service/simpledb/domain.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/simpledb" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "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/planmodifier" @@ -26,25 +25,24 @@ import ( ) // @FrameworkResource -func newResourceDomain(context.Context) (resource.ResourceWithConfigure, error) { - r := &resourceDomain{} +func newDomainResource(context.Context) (resource.ResourceWithConfigure, error) { + r := &domainResource{} return r, nil } -type resourceDomain struct { +type domainResource struct { framework.ResourceWithConfigure + framework.WithNoUpdate + framework.WithImportByID } -// Metadata should return the full name of the resource, such as -// examplecloud_thing. -func (r *resourceDomain) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { +func (*domainResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { response.TypeName = "aws_simpledb_domain" } -// Schema returns the schema for this resource. -func (r *resourceDomain) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ +func (r *domainResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ names.AttrID: framework.IDAttribute(), names.AttrName: schema.StringAttribute{ @@ -54,16 +52,13 @@ func (r *resourceDomain) Schema(ctx context.Context, req resource.SchemaRequest, }, }, }, + DeprecationMessage: `The aws_simpledb_domain resource has been deprecated and will be removed in a future version. Use Amazon DynamoDB instead.`, } } -// Create is called when the provider must create a new resource. -// Config and planned state values should be read from the CreateRequest and new state values set on the CreateResponse. -func (r *resourceDomain) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { - var data resourceDomainData - +func (r *domainResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var data domainResourceModel response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) - if response.Diagnostics.HasError() { return } @@ -88,20 +83,16 @@ func (r *resourceDomain) Create(ctx context.Context, request resource.CreateRequ response.Diagnostics.Append(response.State.Set(ctx, &data)...) } -// Read is called when the provider must read resource values in order to update state. -// Planned state values should be read from the ReadRequest and new state values set on the ReadResponse. -func (r *resourceDomain) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { - var data resourceDomainData - +func (r *domainResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var data domainResourceModel response.Diagnostics.Append(request.State.Get(ctx, &data)...) - if response.Diagnostics.HasError() { return } conn := r.Meta().SimpleDBConn(ctx) - _, err := FindDomainByName(ctx, conn, data.ID.ValueString()) + _, err := findDomainByName(ctx, conn, data.ID.ValueString()) if tfresource.NotFound(err) { response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) @@ -116,25 +107,14 @@ func (r *resourceDomain) Read(ctx context.Context, request resource.ReadRequest, return } - response.Diagnostics.Append(response.State.Set(ctx, &data)...) -} + data.Name = data.ID -// Update is called to update the state of the resource. -// Config, planned state, and prior state values should be read from the UpdateRequest and new state values set on the UpdateResponse. -func (r *resourceDomain) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { - // Noop. + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } -// Delete is called when the provider must delete the resource. -// Config values may be read from the DeleteRequest. -// -// If execution completes without error, the framework will automatically call DeleteResponse.State.RemoveResource(), -// so it can be omitted from provider logic. -func (r *resourceDomain) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { - var data resourceDomainData - +func (r *domainResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var data domainResourceModel response.Diagnostics.Append(request.State.Get(ctx, &data)...) - if response.Diagnostics.HasError() { return } @@ -156,21 +136,12 @@ func (r *resourceDomain) Delete(ctx context.Context, request resource.DeleteRequ } } -// ImportState is called when the provider must import the state of a resource instance. -// This method must return enough state so the Read method can properly refresh the full resource. -// -// If setting an attribute with the import identifier, it is recommended to use the ImportStatePassthroughID() call in this method. -func (r *resourceDomain) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrID), request.ID)...) - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrName), request.ID)...) -} - -type resourceDomainData struct { +type domainResourceModel struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` } -func FindDomainByName(ctx context.Context, conn *simpledb.SimpleDB, name string) (*simpledb.DomainMetadataOutput, error) { +func findDomainByName(ctx context.Context, conn *simpledb.SimpleDB, name string) (*simpledb.DomainMetadataOutput, error) { input := &simpledb.DomainMetadataInput{ DomainName: aws.String(name), } diff --git a/internal/service/simpledb/exports_test.go b/internal/service/simpledb/exports_test.go index 4e604242d3b..8f32eaa4ec8 100644 --- a/internal/service/simpledb/exports_test.go +++ b/internal/service/simpledb/exports_test.go @@ -4,4 +4,8 @@ package simpledb // Exports for use in tests only. -var ResourceDomain = newResourceDomain +var ( + ResourceDomain = newDomainResource + + FindDomainByName = findDomainByName +) diff --git a/internal/service/simpledb/service_package_gen.go b/internal/service/simpledb/service_package_gen.go index 2f25ee7b39f..2845ce69071 100644 --- a/internal/service/simpledb/service_package_gen.go +++ b/internal/service/simpledb/service_package_gen.go @@ -23,7 +23,7 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { return []*types.ServicePackageFrameworkResource{ { - Factory: newResourceDomain, + Factory: newDomainResource, }, } } diff --git a/internal/service/simpledb/sweep.go b/internal/service/simpledb/sweep.go index 75ae8fb888c..7d08b2ff175 100644 --- a/internal/service/simpledb/sweep.go +++ b/internal/service/simpledb/sweep.go @@ -39,7 +39,7 @@ func sweepDomains(region string) error { } for _, v := range page.DomainNames { - sweepResources = append(sweepResources, framework.NewSweepResource(newResourceDomain, client, + sweepResources = append(sweepResources, framework.NewSweepResource(newDomainResource, client, framework.NewAttribute(names.AttrID, aws.StringValue(v)), )) }