Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_simpledb_domain: Deprecate resource #39536

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/39536.txt
Original file line number Diff line number Diff line change
@@ -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
```
69 changes: 20 additions & 49 deletions internal/service/simpledb/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand All @@ -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
}
Expand All @@ -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))
Expand All @@ -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
}
Expand All @@ -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),
}
Expand Down
6 changes: 5 additions & 1 deletion internal/service/simpledb/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
package simpledb

// Exports for use in tests only.
var ResourceDomain = newResourceDomain
var (
ResourceDomain = newDomainResource

FindDomainByName = findDomainByName
)
2 changes: 1 addition & 1 deletion internal/service/simpledb/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/simpledb/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
))
}
Expand Down
Loading