Skip to content

Commit

Permalink
Acceptance test output:
Browse files Browse the repository at this point in the history
% make testacc TESTARGS='-run=TestAccSimpleDBDomain_' PKG=simpledb
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.1 test ./internal/service/simpledb/... -v -count 1 -parallel 20  -run=TestAccSimpleDBDomain_ -timeout 360m
=== RUN   TestAccSimpleDBDomain_basic
=== PAUSE TestAccSimpleDBDomain_basic
=== RUN   TestAccSimpleDBDomain_disappears
=== PAUSE TestAccSimpleDBDomain_disappears
=== RUN   TestAccSimpleDBDomain_MigrateFromPluginSDK
=== PAUSE TestAccSimpleDBDomain_MigrateFromPluginSDK
=== CONT  TestAccSimpleDBDomain_basic
=== CONT  TestAccSimpleDBDomain_MigrateFromPluginSDK
=== CONT  TestAccSimpleDBDomain_disappears
--- PASS: TestAccSimpleDBDomain_disappears (12.13s)
--- PASS: TestAccSimpleDBDomain_basic (14.48s)
--- PASS: TestAccSimpleDBDomain_MigrateFromPluginSDK (28.61s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/simpledb	34.191s
  • Loading branch information
ewbankkit committed Sep 30, 2024
1 parent 5f3c708 commit 992e9ac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 52 deletions.
68 changes: 19 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 @@ -57,13 +55,9 @@ func (r *resourceDomain) Schema(ctx context.Context, req resource.SchemaRequest,
}
}

// 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 +82,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 +106,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 +135,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

0 comments on commit 992e9ac

Please sign in to comment.