Skip to content

Commit 1a00f6b

Browse files
committed
Updates aws_sqs_queue
1 parent 20d95bc commit 1a00f6b

File tree

2 files changed

+10
-77
lines changed

2 files changed

+10
-77
lines changed

internal/service/sqs/queue.go

Lines changed: 8 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
3232
"github.com/hashicorp/terraform-provider-aws/internal/flex"
3333
tfmaps "github.com/hashicorp/terraform-provider-aws/internal/maps"
34-
"github.com/hashicorp/terraform-provider-aws/internal/provider/sdkv2/importer"
3534
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
3635
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3736
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
@@ -196,7 +195,7 @@ var (
196195
// @SDKResource("aws_sqs_queue", name="Queue")
197196
// @Tags(identifierAttribute="id")
198197
// @IdentityVersion(1)
199-
// @CustomInherentRegionIdentity("url")
198+
// @CustomInherentRegionIdentity("url", "parseQueueURL")
200199
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/sqs/types;awstypes;map[awstypes.QueueAttributeName]string")
201200
// @Testing(preIdentityVersion="v6.9.0")
202201
// @Testing(idAttrDuplicates="url")
@@ -218,18 +217,6 @@ func resourceQueue() *schema.Resource {
218217
Update: schema.DefaultTimeout(3 * time.Minute),
219218
Delete: schema.DefaultTimeout(3 * time.Minute),
220219
},
221-
222-
Importer: &schema.ResourceImporter{
223-
StateContext: func(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
224-
identitySpec := importer.IdentitySpec(ctx)
225-
226-
if err := importQueueURL(ctx, d, identitySpec); err != nil {
227-
return nil, err
228-
}
229-
230-
return []*schema.ResourceData{d}, nil
231-
},
232-
},
233220
}
234221
}
235222

@@ -648,68 +635,14 @@ func waitQueueDeleted(ctx context.Context, conn *sqs.Client, url string, timeout
648635
return err
649636
}
650637

651-
func importQueueURL(_ context.Context, rd *schema.ResourceData, identitySpec inttypes.Identity) error {
652-
attr := identitySpec.Attributes[0]
638+
func parseQueueURL(u string) (result inttypes.BaseIdentity, err error) {
653639
re := regexache.MustCompile(`^https://sqs\.([a-z0-9-]+)\.[^/]+/([0-9]{12})/.+`)
654-
655-
if rd.Id() != "" {
656-
match := re.FindStringSubmatch(rd.Id())
657-
if match == nil {
658-
return fmt.Errorf("could not parse import ID %q as SQS URL", rd.Id())
659-
}
660-
661-
urlRegion := match[1]
662-
663-
rd.Set(attr.ResourceAttributeName(), rd.Id())
664-
for _, attr := range identitySpec.IdentityDuplicateAttrs {
665-
setAttribute(rd, attr, rd.Id())
666-
}
667-
668-
if region, ok := rd.GetOk(names.AttrRegion); ok {
669-
if region != urlRegion {
670-
return fmt.Errorf("the region passed for import %q does not match the region %q in the URL %q", region, urlRegion, rd.Id())
671-
}
672-
} else {
673-
rd.Set(names.AttrRegion, urlRegion)
674-
}
675-
676-
return nil
677-
}
678-
679-
identity, err := rd.Identity()
680-
if err != nil {
681-
return err
682-
}
683-
684-
urlRaw, ok := identity.GetOk(attr.Name())
685-
if !ok {
686-
return fmt.Errorf("identity attribute %q is required", attr.Name())
687-
}
688-
689-
urlVal, ok := urlRaw.(string)
690-
if !ok {
691-
return fmt.Errorf("identity attribute %q: expected string, got %T", attr.Name(), urlRaw)
692-
}
693-
694-
match := re.FindStringSubmatch(urlVal)
640+
match := re.FindStringSubmatch(u)
695641
if match == nil {
696-
return fmt.Errorf("identity attribute %q: could not parse %q as SQS URL", attr.Name(), urlVal)
697-
}
698-
699-
rd.Set(names.AttrRegion, match[1])
700-
701-
rd.Set(attr.ResourceAttributeName(), urlVal)
702-
for _, attr := range identitySpec.IdentityDuplicateAttrs {
703-
setAttribute(rd, attr, urlVal)
704-
}
705-
706-
return nil
707-
}
708-
709-
func setAttribute(rd *schema.ResourceData, name string, value string) {
710-
if name == "id" {
711-
rd.SetId(value)
712-
return
642+
return inttypes.BaseIdentity{}, fmt.Errorf("could not parse %q as SQS URL", u)
713643
}
714-
rd.Set(name, value)
644+
return inttypes.BaseIdentity{
645+
AccountID: match[2],
646+
Region: match[1],
647+
}, nil
715648
}

internal/service/sqs/service_package_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)