From c4effd31b7b16d89238d43d8e56adc14632ad57d Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 19 Dec 2022 10:38:17 -0500 Subject: [PATCH] temp(do not merge): disable use of framework-timeouts dep this just allows the provider to compile while we wait on updates to this dependency to work with the latest plugin framework changes --- go.mod | 1 - go.sum | 2 - .../service/resourceexplorer2/exports_test.go | 8 +- internal/service/resourceexplorer2/index.go | 671 +++++++++--------- .../service/resourceexplorer2/index_test.go | 426 +++++------ .../resourceexplorer2_test.go | 48 +- 6 files changed, 577 insertions(+), 579 deletions(-) diff --git a/go.mod b/go.mod index c010b710ea2f..7b9827e84e80 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,6 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/hcl/v2 v2.15.0 github.com/hashicorp/terraform-plugin-framework v1.0.0 - github.com/hashicorp/terraform-plugin-framework-timeouts v0.2.0 github.com/hashicorp/terraform-plugin-framework-validators v0.8.0 github.com/hashicorp/terraform-plugin-go v0.14.2 github.com/hashicorp/terraform-plugin-log v0.7.0 diff --git a/go.sum b/go.sum index 170020383e72..1e1f128b99c6 100644 --- a/go.sum +++ b/go.sum @@ -217,8 +217,6 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-framework v1.0.0 h1:0Mls4TrMTrDysBUby/UmlbcTOMM+n5JBDyB5k+XkGWg= github.com/hashicorp/terraform-plugin-framework v1.0.0/go.mod h1:FV97t2BZOARkL7NNlsc/N25c84MyeSSz72uPp7Vq1lg= -github.com/hashicorp/terraform-plugin-framework-timeouts v0.2.0 h1:qo+9WNxAg9UlD0NHoOhi6GJOjQKN6b+JLZJOZ5Nqr8g= -github.com/hashicorp/terraform-plugin-framework-timeouts v0.2.0/go.mod h1:jIV0yknjnzb3Al+DRMtr25BPlQq8LLoy+36bYQduIg8= github.com/hashicorp/terraform-plugin-framework-validators v0.8.0 h1:hKCuQMjD7W7reAoWn6GLkNwrDNjY9RCBWQZOJxe5LlQ= github.com/hashicorp/terraform-plugin-framework-validators v0.8.0/go.mod h1:qkrZ542jRiCwwl3ZN/3eTKhGJ4HIBkSxGXnjJoAWtxo= github.com/hashicorp/terraform-plugin-go v0.14.2 h1:rhsVEOGCnY04msNymSvbUsXfRLKh9znXZmHlf5e8mhE= diff --git a/internal/service/resourceexplorer2/exports_test.go b/internal/service/resourceexplorer2/exports_test.go index 344e59d90e94..45e95813d093 100644 --- a/internal/service/resourceexplorer2/exports_test.go +++ b/internal/service/resourceexplorer2/exports_test.go @@ -1,7 +1,7 @@ package resourceexplorer2 // Exports for use in tests only. -var ( - FindIndex = findIndex - ResourceIndex = newResourceIndex -) +// var ( +// FindIndex = findIndex +// ResourceIndex = newResourceIndex +// ) diff --git a/internal/service/resourceexplorer2/index.go b/internal/service/resourceexplorer2/index.go index e7e3b9e3963f..1bce067c0eb9 100644 --- a/internal/service/resourceexplorer2/index.go +++ b/internal/service/resourceexplorer2/index.go @@ -1,388 +1,389 @@ package resourceexplorer2 -import ( - "context" - "fmt" - "time" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2" - awstypes "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2/types" - "github.com/hashicorp/terraform-plugin-framework-timeouts/timeouts" - "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" - "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-plugin-log/tflog" - sdkresource "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-provider-aws/internal/enum" - "github.com/hashicorp/terraform-provider-aws/internal/errs" - "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" - "github.com/hashicorp/terraform-provider-aws/internal/flex" - "github.com/hashicorp/terraform-provider-aws/internal/framework" - tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" -) - -func init() { - registerFrameworkResourceFactory(newResourceIndex) -} - -func newResourceIndex(context.Context) (resource.ResourceWithConfigure, error) { - return &resourceIndex{ - defaultCreateTimeout: 2 * time.Hour, - defaultUpdateTimeout: 2 * time.Hour, - defaultDeleteTimeout: 10 * time.Minute, - }, nil -} - -type resourceIndex struct { - framework.ResourceWithConfigure - - defaultCreateTimeout time.Duration - defaultUpdateTimeout time.Duration - defaultDeleteTimeout time.Duration -} - -func (r *resourceIndex) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = "aws_resourceexplorer2_index" -} - -func (r *resourceIndex) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { - response.Schema = schema.Schema{ - Attributes: map[string]schema.Attribute{ - "arn": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - "id": framework.IDAttribute(), - "tags": tftags.TagsAttribute(), - "tags_all": tftags.TagsAttributeComputedOnly(), - "type": schema.StringAttribute{ - Required: true, - Validators: []validator.String{ - enum.FrameworkValidate[awstypes.IndexType](), - }, - }, - }, - Blocks: map[string]schema.Block{ - "timeouts": timeouts.Block(ctx, timeouts.Opts{ - Create: true, - Update: true, - Delete: true, - }), - }, - } -} - -func (r *resourceIndex) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { - var data resourceIndexData - - response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) - - if response.Diagnostics.HasError() { - return - } - - conn := r.Meta().ResourceExplorer2Client - createTimeout := timeouts.Create(ctx, data.Timeouts, r.defaultCreateTimeout) - defaultTagsConfig := r.Meta().DefaultTagsConfig - ignoreTagsConfig := r.Meta().IgnoreTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(data.Tags)) - - input := &resourceexplorer2.CreateIndexInput{ - ClientToken: aws.String(sdkresource.UniqueId()), - } - - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - - output, err := conn.CreateIndex(ctx, input) - - if err != nil { - response.Diagnostics.AddError("creating Resource Explorer Index", err.Error()) - - return - } - - arn := aws.ToString(output.Arn) - data.ID = types.StringValue(arn) - - if _, err := waitIndexCreated(ctx, conn, createTimeout); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) create", data.ID.ValueString()), err.Error()) - - return - } - - if data.Type.ValueString() == string(awstypes.IndexTypeAggregator) { - input := &resourceexplorer2.UpdateIndexTypeInput{ - Arn: flex.StringFromFramework(ctx, data.ID), - Type: awstypes.IndexTypeAggregator, - } +// import ( +// "context" +// "fmt" +// "time" + +// "github.com/aws/aws-sdk-go-v2/aws" +// "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2" +// awstypes "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2/types" + +// "github.com/hashicorp/terraform-plugin-framework-timeouts/timeouts" +// "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" +// "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-plugin-log/tflog" +// sdkresource "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +// "github.com/hashicorp/terraform-provider-aws/internal/enum" +// "github.com/hashicorp/terraform-provider-aws/internal/errs" +// "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" +// "github.com/hashicorp/terraform-provider-aws/internal/flex" +// "github.com/hashicorp/terraform-provider-aws/internal/framework" +// tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" +// "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +// ) + +// func init() { +// registerFrameworkResourceFactory(newResourceIndex) +// } + +// func newResourceIndex(context.Context) (resource.ResourceWithConfigure, error) { +// return &resourceIndex{ +// defaultCreateTimeout: 2 * time.Hour, +// defaultUpdateTimeout: 2 * time.Hour, +// defaultDeleteTimeout: 10 * time.Minute, +// }, nil +// } + +// type resourceIndex struct { +// framework.ResourceWithConfigure + +// defaultCreateTimeout time.Duration +// defaultUpdateTimeout time.Duration +// defaultDeleteTimeout time.Duration +// } + +// func (r *resourceIndex) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { +// response.TypeName = "aws_resourceexplorer2_index" +// } + +// func (r *resourceIndex) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { +// response.Schema = schema.Schema{ +// Attributes: map[string]schema.Attribute{ +// "arn": schema.StringAttribute{ +// Computed: true, +// PlanModifiers: []planmodifier.String{ +// stringplanmodifier.UseStateForUnknown(), +// }, +// }, +// "id": framework.IDAttribute(), +// "tags": tftags.TagsAttribute(), +// "tags_all": tftags.TagsAttributeComputedOnly(), +// "type": schema.StringAttribute{ +// Required: true, +// Validators: []validator.String{ +// enum.FrameworkValidate[awstypes.IndexType](), +// }, +// }, +// }, +// // Blocks: map[string]schema.Block{ +// // "timeouts": timeouts.Block(ctx, timeouts.Opts{ +// // Create: true, +// // Update: true, +// // Delete: true, +// // }), +// // }, +// } +// } + +// func (r *resourceIndex) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { +// var data resourceIndexData + +// response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + +// if response.Diagnostics.HasError() { +// return +// } + +// conn := r.Meta().ResourceExplorer2Client +// createTimeout := timeouts.Create(ctx, data.Timeouts, r.defaultCreateTimeout) +// defaultTagsConfig := r.Meta().DefaultTagsConfig +// ignoreTagsConfig := r.Meta().IgnoreTagsConfig +// tags := defaultTagsConfig.MergeTags(tftags.New(data.Tags)) + +// input := &resourceexplorer2.CreateIndexInput{ +// ClientToken: aws.String(sdkresource.UniqueId()), +// } + +// if len(tags) > 0 { +// input.Tags = Tags(tags.IgnoreAWS()) +// } + +// output, err := conn.CreateIndex(ctx, input) + +// if err != nil { +// response.Diagnostics.AddError("creating Resource Explorer Index", err.Error()) + +// return +// } + +// arn := aws.ToString(output.Arn) +// data.ID = types.StringValue(arn) + +// if _, err := waitIndexCreated(ctx, conn, createTimeout); err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) create", data.ID.ValueString()), err.Error()) + +// return +// } + +// if data.Type.ValueString() == string(awstypes.IndexTypeAggregator) { +// input := &resourceexplorer2.UpdateIndexTypeInput{ +// Arn: flex.StringFromFramework(ctx, data.ID), +// Type: awstypes.IndexTypeAggregator, +// } - _, err := conn.UpdateIndexType(ctx, input) - - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) +// _, err := conn.UpdateIndexType(ctx, input) + +// if err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) - return - } +// return +// } - if _, err := waitIndexUpdated(ctx, conn, createTimeout); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) update", data.ID.ValueString()), err.Error()) +// if _, err := waitIndexUpdated(ctx, conn, createTimeout); err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) update", data.ID.ValueString()), err.Error()) - return - } - } +// return +// } +// } - // Set values for unknowns. - data.ARN = types.StringValue(arn) - data.TagsAll = flex.FlattenFrameworkStringValueMap(ctx, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) +// // Set values for unknowns. +// data.ARN = types.StringValue(arn) +// data.TagsAll = flex.FlattenFrameworkStringValueMap(ctx, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) - response.Diagnostics.Append(response.State.Set(ctx, &data)...) -} +// response.Diagnostics.Append(response.State.Set(ctx, &data)...) +// } -func (r *resourceIndex) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { - var data resourceIndexData +// func (r *resourceIndex) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { +// var data resourceIndexData - response.Diagnostics.Append(request.State.Get(ctx, &data)...) +// response.Diagnostics.Append(request.State.Get(ctx, &data)...) - if response.Diagnostics.HasError() { - return - } +// if response.Diagnostics.HasError() { +// return +// } - conn := r.Meta().ResourceExplorer2Client - defaultTagsConfig := r.Meta().DefaultTagsConfig - ignoreTagsConfig := r.Meta().IgnoreTagsConfig +// conn := r.Meta().ResourceExplorer2Client +// defaultTagsConfig := r.Meta().DefaultTagsConfig +// ignoreTagsConfig := r.Meta().IgnoreTagsConfig - output, err := findIndex(ctx, conn) +// output, err := findIndex(ctx, conn) - if tfresource.NotFound(err) { - response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) - response.State.RemoveResource(ctx) +// if tfresource.NotFound(err) { +// response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) +// response.State.RemoveResource(ctx) - return - } +// return +// } - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("reading Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) +// if err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("reading Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) - return - } +// return +// } - data.ARN = flex.StringToFramework(ctx, output.Arn) - data.Type = types.StringValue(string(output.Type)) +// data.ARN = flex.StringToFramework(ctx, output.Arn) +// data.Type = types.StringValue(string(output.Type)) - tags := KeyValueTags(output.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - // AWS APIs often return empty lists of tags when none have been configured. - if tags := tags.RemoveDefaultConfig(defaultTagsConfig).Map(); len(tags) == 0 { - data.Tags = tftags.Null - } else { - data.Tags = flex.FlattenFrameworkStringValueMap(ctx, tags) - } - data.TagsAll = flex.FlattenFrameworkStringValueMap(ctx, tags.Map()) +// tags := KeyValueTags(output.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) +// // AWS APIs often return empty lists of tags when none have been configured. +// if tags := tags.RemoveDefaultConfig(defaultTagsConfig).Map(); len(tags) == 0 { +// data.Tags = tftags.Null +// } else { +// data.Tags = flex.FlattenFrameworkStringValueMap(ctx, tags) +// } +// data.TagsAll = flex.FlattenFrameworkStringValueMap(ctx, tags.Map()) - response.Diagnostics.Append(response.State.Set(ctx, &data)...) -} +// response.Diagnostics.Append(response.State.Set(ctx, &data)...) +// } -func (r *resourceIndex) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { - var old, new resourceIndexData +// func (r *resourceIndex) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { +// var old, new resourceIndexData - response.Diagnostics.Append(request.State.Get(ctx, &old)...) +// response.Diagnostics.Append(request.State.Get(ctx, &old)...) - if response.Diagnostics.HasError() { - return - } +// if response.Diagnostics.HasError() { +// return +// } - response.Diagnostics.Append(request.Plan.Get(ctx, &new)...) +// response.Diagnostics.Append(request.Plan.Get(ctx, &new)...) - if response.Diagnostics.HasError() { - return - } +// if response.Diagnostics.HasError() { +// return +// } - conn := r.Meta().ResourceExplorer2Client - updateTimeout := timeouts.Update(ctx, new.Timeouts, r.defaultUpdateTimeout) +// conn := r.Meta().ResourceExplorer2Client +// updateTimeout := timeouts.Update(ctx, new.Timeouts, r.defaultUpdateTimeout) - if !new.Type.Equal(old.Type) { - input := &resourceexplorer2.UpdateIndexTypeInput{ - Arn: flex.StringFromFramework(ctx, new.ID), - Type: awstypes.IndexType(new.Type.ValueString()), - } +// if !new.Type.Equal(old.Type) { +// input := &resourceexplorer2.UpdateIndexTypeInput{ +// Arn: flex.StringFromFramework(ctx, new.ID), +// Type: awstypes.IndexType(new.Type.ValueString()), +// } - _, err := conn.UpdateIndexType(ctx, input) +// _, err := conn.UpdateIndexType(ctx, input) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s)", new.ID.ValueString()), err.Error()) +// if err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s)", new.ID.ValueString()), err.Error()) - return - } +// return +// } - if _, err := waitIndexUpdated(ctx, conn, updateTimeout); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) update", new.ID.ValueString()), err.Error()) +// if _, err := waitIndexUpdated(ctx, conn, updateTimeout); err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) update", new.ID.ValueString()), err.Error()) - return - } - } +// return +// } +// } - if !new.TagsAll.Equal(old.TagsAll) { - if err := UpdateTags(ctx, conn, new.ID.ValueString(), old.TagsAll, new.TagsAll); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s) tags", new.ID.ValueString()), err.Error()) +// if !new.TagsAll.Equal(old.TagsAll) { +// if err := UpdateTags(ctx, conn, new.ID.ValueString(), old.TagsAll, new.TagsAll); err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("updating Resource Explorer Index (%s) tags", new.ID.ValueString()), err.Error()) - return - } - } +// return +// } +// } - response.Diagnostics.Append(response.State.Set(ctx, &new)...) -} +// response.Diagnostics.Append(response.State.Set(ctx, &new)...) +// } -func (r *resourceIndex) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { - var data resourceIndexData +// func (r *resourceIndex) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { +// var data resourceIndexData - response.Diagnostics.Append(request.State.Get(ctx, &data)...) +// response.Diagnostics.Append(request.State.Get(ctx, &data)...) - if response.Diagnostics.HasError() { - return - } +// if response.Diagnostics.HasError() { +// return +// } - conn := r.Meta().ResourceExplorer2Client - deleteTimeout := timeouts.Delete(ctx, data.Timeouts, r.defaultDeleteTimeout) +// conn := r.Meta().ResourceExplorer2Client +// deleteTimeout := timeouts.Delete(ctx, data.Timeouts, r.defaultDeleteTimeout) - tflog.Debug(ctx, "deleting Resource Explorer Index", map[string]interface{}{ - "id": data.ID.ValueString(), - }) - _, err := conn.DeleteIndex(ctx, &resourceexplorer2.DeleteIndexInput{ - Arn: flex.StringFromFramework(ctx, data.ID), - }) +// tflog.Debug(ctx, "deleting Resource Explorer Index", map[string]interface{}{ +// "id": data.ID.ValueString(), +// }) +// _, err := conn.DeleteIndex(ctx, &resourceexplorer2.DeleteIndexInput{ +// Arn: flex.StringFromFramework(ctx, data.ID), +// }) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("deleting Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) +// if err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("deleting Resource Explorer Index (%s)", data.ID.ValueString()), err.Error()) - return - } +// return +// } - if _, err := waitIndexDeleted(ctx, conn, deleteTimeout); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) delete", data.ID.ValueString()), err.Error()) +// if _, err := waitIndexDeleted(ctx, conn, deleteTimeout); err != nil { +// response.Diagnostics.AddError(fmt.Sprintf("waiting for Resource Explorer Index (%s) delete", data.ID.ValueString()), err.Error()) - return - } -} +// return +// } +// } -func (r *resourceIndex) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) -} - -func (r *resourceIndex) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { - r.SetTagsAll(ctx, request, response) -} +// func (r *resourceIndex) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { +// resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) +// } + +// func (r *resourceIndex) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { +// r.SetTagsAll(ctx, request, response) +// } -type resourceIndexData struct { - ARN types.String `tfsdk:"arn"` - ID types.String `tfsdk:"id"` - Tags types.Map `tfsdk:"tags"` - TagsAll types.Map `tfsdk:"tags_all"` - Timeouts types.Object `tfsdk:"timeouts"` - Type types.String `tfsdk:"type"` -} +// type resourceIndexData struct { +// ARN types.String `tfsdk:"arn"` +// ID types.String `tfsdk:"id"` +// Tags types.Map `tfsdk:"tags"` +// TagsAll types.Map `tfsdk:"tags_all"` +// Timeouts types.Object `tfsdk:"timeouts"` +// Type types.String `tfsdk:"type"` +// } -func findIndex(ctx context.Context, conn *resourceexplorer2.Client) (*resourceexplorer2.GetIndexOutput, error) { - input := &resourceexplorer2.GetIndexInput{} +// func findIndex(ctx context.Context, conn *resourceexplorer2.Client) (*resourceexplorer2.GetIndexOutput, error) { +// input := &resourceexplorer2.GetIndexInput{} - output, err := conn.GetIndex(ctx, input) +// output, err := conn.GetIndex(ctx, input) - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return nil, &sdkresource.NotFoundError{ - LastError: err, - LastRequest: input, - } - } +// if errs.IsA[*awstypes.ResourceNotFoundException](err) { +// return nil, &sdkresource.NotFoundError{ +// LastError: err, +// LastRequest: input, +// } +// } - if err != nil { - return nil, err - } +// if err != nil { +// return nil, err +// } - if output == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if state := output.State; state == awstypes.IndexStateDeleted { - return nil, &sdkresource.NotFoundError{ - Message: string(state), - LastRequest: input, - } - } +// if output == nil { +// return nil, tfresource.NewEmptyResultError(input) +// } + +// if state := output.State; state == awstypes.IndexStateDeleted { +// return nil, &sdkresource.NotFoundError{ +// Message: string(state), +// LastRequest: input, +// } +// } - return output, nil -} +// return output, nil +// } -func statusIndex(ctx context.Context, conn *resourceexplorer2.Client) sdkresource.StateRefreshFunc { - return func() (interface{}, string, error) { - output, err := findIndex(ctx, conn) - - if tfresource.NotFound(err) { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - return output, string(output.State), nil - } -} - -func waitIndexCreated(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { - stateConf := &sdkresource.StateChangeConf{ - Pending: enum.Slice(awstypes.IndexStateCreating), - Target: enum.Slice(awstypes.IndexStateActive), - Refresh: statusIndex(ctx, conn), - Timeout: timeout, - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { - return output, err - } - - return nil, err -} - -func waitIndexUpdated(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { //nolint:unparam - stateConf := &sdkresource.StateChangeConf{ - Pending: enum.Slice(awstypes.IndexStateUpdating), - Target: enum.Slice(awstypes.IndexStateActive), - Refresh: statusIndex(ctx, conn), - Timeout: timeout, - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { - return output, err - } - - return nil, err -} - -func waitIndexDeleted(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { - stateConf := &sdkresource.StateChangeConf{ - Pending: enum.Slice(awstypes.IndexStateDeleting), - Target: []string{}, - Refresh: statusIndex(ctx, conn), - Timeout: timeout, - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { - return output, err - } - - return nil, err -} +// func statusIndex(ctx context.Context, conn *resourceexplorer2.Client) sdkresource.StateRefreshFunc { +// return func() (interface{}, string, error) { +// output, err := findIndex(ctx, conn) + +// if tfresource.NotFound(err) { +// return nil, "", nil +// } + +// if err != nil { +// return nil, "", err +// } + +// return output, string(output.State), nil +// } +// } + +// func waitIndexCreated(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { +// stateConf := &sdkresource.StateChangeConf{ +// Pending: enum.Slice(awstypes.IndexStateCreating), +// Target: enum.Slice(awstypes.IndexStateActive), +// Refresh: statusIndex(ctx, conn), +// Timeout: timeout, +// } + +// outputRaw, err := stateConf.WaitForStateContext(ctx) + +// if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { +// return output, err +// } + +// return nil, err +// } + +// func waitIndexUpdated(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { //nolint:unparam +// stateConf := &sdkresource.StateChangeConf{ +// Pending: enum.Slice(awstypes.IndexStateUpdating), +// Target: enum.Slice(awstypes.IndexStateActive), +// Refresh: statusIndex(ctx, conn), +// Timeout: timeout, +// } + +// outputRaw, err := stateConf.WaitForStateContext(ctx) + +// if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { +// return output, err +// } + +// return nil, err +// } + +// func waitIndexDeleted(ctx context.Context, conn *resourceexplorer2.Client, timeout time.Duration) (*resourceexplorer2.GetIndexOutput, error) { +// stateConf := &sdkresource.StateChangeConf{ +// Pending: enum.Slice(awstypes.IndexStateDeleting), +// Target: []string{}, +// Refresh: statusIndex(ctx, conn), +// Timeout: timeout, +// } + +// outputRaw, err := stateConf.WaitForStateContext(ctx) + +// if output, ok := outputRaw.(*resourceexplorer2.GetIndexOutput); ok { +// return output, err +// } + +// return nil, err +// } diff --git a/internal/service/resourceexplorer2/index_test.go b/internal/service/resourceexplorer2/index_test.go index 70bbcb34689b..cf42ea253fcf 100644 --- a/internal/service/resourceexplorer2/index_test.go +++ b/internal/service/resourceexplorer2/index_test.go @@ -1,215 +1,215 @@ package resourceexplorer2_test -import ( - "context" - "fmt" - "regexp" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - tfresourceexplorer2 "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" - "github.com/hashicorp/terraform-provider-aws/names" -) - -func testAccIndex_basic(t *testing.T) { - resourceName := "aws_resourceexplorer2_index.test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIndexConfig_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "resource-explorer-2", regexp.MustCompile(`index/+.`)), - resource.TestCheckResourceAttr(resourceName, "type", "LOCAL"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccIndex_disappears(t *testing.T) { - resourceName := "aws_resourceexplorer2_index.test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIndexConfig_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - acctest.CheckFrameworkResourceDisappears(acctest.Provider, tfresourceexplorer2.ResourceIndex, resourceName), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testAccIndex_tags(t *testing.T) { - resourceName := "aws_resourceexplorer2_index.test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIndexConfig_tags1("key1", "value1"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccIndexConfig_tags2("key1", "value1updated", "key2", "value2"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), - ), - }, - { - Config: testAccIndexConfig_tags1("key2", "value2"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), - ), - }, - }, - }) -} - -func testAccIndex_type(t *testing.T) { - resourceName := "aws_resourceexplorer2_index.test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckIndexDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIndexConfig_type("AGGREGATOR"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "type", "AGGREGATOR"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccIndexConfig_type("LOCAL"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIndexExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "type", "LOCAL"), - ), - }, - }, - }) -} - -func testAccCheckIndexDestroy(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ResourceExplorer2Client - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_resourceexplorer2_index" { - continue - } - - _, err := tfresourceexplorer2.FindIndex(context.Background(), conn) - - if tfresource.NotFound(err) { - continue - } - - if err != nil { - return err - } - - return fmt.Errorf("Resource Explorer Index %s still exists", rs.Primary.ID) - } - - return nil -} - -func testAccCheckIndexExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No Resource Explorer Index ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).ResourceExplorer2Client - - _, err := tfresourceexplorer2.FindIndex(context.Background(), conn) - - return err - } -} - -var testAccIndexConfig_basic = testAccIndexConfig_type("LOCAL") - -func testAccIndexConfig_tags1(tagKey1, tagValue1 string) string { - return fmt.Sprintf(` -resource "aws_resourceexplorer2_index" "test" { - type = "LOCAL" - - tags = { - %[1]q = %[2]q - } -} -`, tagKey1, tagValue1) -} - -func testAccIndexConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return fmt.Sprintf(` -resource "aws_resourceexplorer2_index" "test" { - type = "LOCAL" - - tags = { - %[1]q = %[2]q - %[3]q = %[4]q - } -} -`, tagKey1, tagValue1, tagKey2, tagValue2) -} - -func testAccIndexConfig_type(typ string) string { - return fmt.Sprintf(` -resource "aws_resourceexplorer2_index" "test" { - type = %[1]q -} -`, typ) -} +// import ( +// "context" +// "fmt" +// "regexp" +// "testing" + +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +// "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +// "github.com/hashicorp/terraform-provider-aws/internal/acctest" +// "github.com/hashicorp/terraform-provider-aws/internal/conns" +// tfresourceexplorer2 "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2" +// "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +// "github.com/hashicorp/terraform-provider-aws/names" +// ) + +// func testAccIndex_basic(t *testing.T) { +// resourceName := "aws_resourceexplorer2_index.test" + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, +// ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckIndexDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccIndexConfig_basic, +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "resource-explorer-2", regexp.MustCompile(`index/+.`)), +// resource.TestCheckResourceAttr(resourceName, "type", "LOCAL"), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// }, +// }, +// }) +// } + +// func testAccIndex_disappears(t *testing.T) { +// resourceName := "aws_resourceexplorer2_index.test" + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, +// ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckIndexDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccIndexConfig_basic, +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// acctest.CheckFrameworkResourceDisappears(acctest.Provider, tfresourceexplorer2.ResourceIndex, resourceName), +// ), +// ExpectNonEmptyPlan: true, +// }, +// }, +// }) +// } + +// func testAccIndex_tags(t *testing.T) { +// resourceName := "aws_resourceexplorer2_index.test" + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, +// ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckIndexDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccIndexConfig_tags1("key1", "value1"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), +// resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// }, +// { +// Config: testAccIndexConfig_tags2("key1", "value1updated", "key2", "value2"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), +// resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), +// resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), +// ), +// }, +// { +// Config: testAccIndexConfig_tags1("key2", "value2"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), +// resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), +// ), +// }, +// }, +// }) +// } + +// func testAccIndex_type(t *testing.T) { +// resourceName := "aws_resourceexplorer2_index.test" + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(names.ResourceExplorer2EndpointID, t) }, +// ErrorCheck: acctest.ErrorCheck(t, names.ResourceExplorer2EndpointID), +// ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, +// CheckDestroy: testAccCheckIndexDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccIndexConfig_type("AGGREGATOR"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// resource.TestCheckResourceAttr(resourceName, "type", "AGGREGATOR"), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// }, +// { +// Config: testAccIndexConfig_type("LOCAL"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIndexExists(resourceName), +// resource.TestCheckResourceAttr(resourceName, "type", "LOCAL"), +// ), +// }, +// }, +// }) +// } + +// func testAccCheckIndexDestroy(s *terraform.State) error { +// conn := acctest.Provider.Meta().(*conns.AWSClient).ResourceExplorer2Client + +// for _, rs := range s.RootModule().Resources { +// if rs.Type != "aws_resourceexplorer2_index" { +// continue +// } + +// _, err := tfresourceexplorer2.FindIndex(context.Background(), conn) + +// if tfresource.NotFound(err) { +// continue +// } + +// if err != nil { +// return err +// } + +// return fmt.Errorf("Resource Explorer Index %s still exists", rs.Primary.ID) +// } + +// return nil +// } + +// func testAccCheckIndexExists(n string) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// rs, ok := s.RootModule().Resources[n] +// if !ok { +// return fmt.Errorf("Not found: %s", n) +// } +// if rs.Primary.ID == "" { +// return fmt.Errorf("No Resource Explorer Index ID is set") +// } + +// conn := acctest.Provider.Meta().(*conns.AWSClient).ResourceExplorer2Client + +// _, err := tfresourceexplorer2.FindIndex(context.Background(), conn) + +// return err +// } +// } + +// var testAccIndexConfig_basic = testAccIndexConfig_type("LOCAL") + +// func testAccIndexConfig_tags1(tagKey1, tagValue1 string) string { +// return fmt.Sprintf(` +// resource "aws_resourceexplorer2_index" "test" { +// type = "LOCAL" + +// tags = { +// %[1]q = %[2]q +// } +// } +// `, tagKey1, tagValue1) +// } + +// func testAccIndexConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { +// return fmt.Sprintf(` +// resource "aws_resourceexplorer2_index" "test" { +// type = "LOCAL" + +// tags = { +// %[1]q = %[2]q +// %[3]q = %[4]q +// } +// } +// `, tagKey1, tagValue1, tagKey2, tagValue2) +// } + +// func testAccIndexConfig_type(typ string) string { +// return fmt.Sprintf(` +// resource "aws_resourceexplorer2_index" "test" { +// type = %[1]q +// } +// `, typ) +// } diff --git a/internal/service/resourceexplorer2/resourceexplorer2_test.go b/internal/service/resourceexplorer2/resourceexplorer2_test.go index fbd08cc17ee3..b4ab7de0de43 100644 --- a/internal/service/resourceexplorer2/resourceexplorer2_test.go +++ b/internal/service/resourceexplorer2/resourceexplorer2_test.go @@ -1,28 +1,28 @@ package resourceexplorer2_test -import ( - "testing" -) +// import ( +// "testing" +// ) -func TestAccResourceExplorer2_serial(t *testing.T) { - testCases := map[string]map[string]func(t *testing.T){ - "Index": { - "basic": testAccIndex_basic, - "disappears": testAccIndex_disappears, - "tags": testAccIndex_tags, - "type": testAccIndex_type, - }, - } +// func TestAccResourceExplorer2_serial(t *testing.T) { +// testCases := map[string]map[string]func(t *testing.T){ +// "Index": { +// "basic": testAccIndex_basic, +// "disappears": testAccIndex_disappears, +// "tags": testAccIndex_tags, +// "type": testAccIndex_type, +// }, +// } - for group, m := range testCases { - m := m - t.Run(group, func(t *testing.T) { - for name, tc := range m { - tc := tc - t.Run(name, func(t *testing.T) { - tc(t) - }) - } - }) - } -} +// for group, m := range testCases { +// m := m +// t.Run(group, func(t *testing.T) { +// for name, tc := range m { +// tc := tc +// t.Run(name, func(t *testing.T) { +// tc(t) +// }) +// } +// }) +// } +// }