Skip to content

Commit 55465e9

Browse files
authored
Merge pull request #44971 from hashicorp/td-use-ri-in-tagging-tests
tag test generation: Sets import ID attribute from ARN Identity
2 parents 25a5fa2 + c806d0e commit 55465e9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

internal/generate/tagstests/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ type ResourceDatum struct {
402402
overrideIdentifierAttribute string
403403
OverrideResourceType string
404404
tests.CommonArgs
405+
isARNIdentity bool
406+
identityAttribute string
405407
}
406408

407409
func (d ResourceDatum) ProviderPackage() string {
@@ -578,6 +580,17 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
578580
case "NoImport":
579581
d.NoImport = true
580582

583+
case "ArnIdentity":
584+
d.isARNIdentity = true
585+
args := common.ParseArgs(m[3])
586+
if len(args.Positional) == 0 {
587+
d.identityAttribute = "arn"
588+
} else {
589+
d.identityAttribute = args.Positional[0]
590+
}
591+
592+
populateInherentRegionIdentity(&d, args)
593+
581594
case "Testing":
582595
args := common.ParseArgs(m[3])
583596

@@ -762,3 +775,19 @@ func count[T any](s iter.Seq[T], f func(T) bool) (c int) {
762775
}
763776
return c
764777
}
778+
779+
func populateInherentRegionIdentity(d *ResourceDatum, args common.Args) {
780+
var attrs []string
781+
if attr, ok := args.Keyword["identityDuplicateAttributes"]; ok {
782+
attrs = strings.Split(attr, ";")
783+
}
784+
if d.Implementation == tests.ImplementationSDK {
785+
attrs = append(attrs, "id")
786+
} else {
787+
if !slices.Contains(attrs, "id") {
788+
d.SetImportStateIDAttribute(d.identityAttribute)
789+
}
790+
}
791+
slices.Sort(attrs)
792+
attrs = slices.Compact(attrs)
793+
}

internal/service/redshift/integration.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
// @ArnIdentity
3434
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/redshift/types;awstypes;awstypes.Integration")
3535
// @Testing(preIdentityVersion="6.19.0")
36-
// @Testing(importStateIdAttribute="arn")
3736
func newIntegrationResource(context.Context) (resource.ResourceWithConfigure, error) {
3837
r := &integrationResource{}
3938

0 commit comments

Comments
 (0)