@@ -9,17 +9,20 @@ import (
9
9
10
10
"github.com/aws/aws-sdk-go-v2/aws/arn"
11
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12
+ inttypes "github.com/hashicorp/terraform-provider-aws/internal/types"
12
13
"github.com/hashicorp/terraform-provider-aws/names"
13
14
)
14
15
15
- func RegionalARN (_ context.Context , rd * schema.ResourceData , attrName string , duplicateAttrs []string ) error {
16
+ func RegionalARN (_ context.Context , rd * schema.ResourceData , identitySpec inttypes.Identity ) error {
17
+ attr := identitySpec .Attributes [0 ]
18
+
16
19
if rd .Id () != "" {
17
20
arnARN , err := arn .Parse (rd .Id ())
18
21
if err != nil {
19
22
return fmt .Errorf ("could not parse import ID %q as ARN: %s" , rd .Id (), err )
20
23
}
21
- rd .Set (attrName , rd .Id ())
22
- for _ , attr := range duplicateAttrs {
24
+ rd .Set (attr . ResourceAttributeName () , rd .Id ())
25
+ for _ , attr := range identitySpec . IdentityDuplicateAttrs {
23
26
setAttribute (rd , attr , rd .Id ())
24
27
}
25
28
@@ -39,25 +42,25 @@ func RegionalARN(_ context.Context, rd *schema.ResourceData, attrName string, du
39
42
return err
40
43
}
41
44
42
- arnRaw , ok := identity .GetOk (attrName )
45
+ arnRaw , ok := identity .GetOk (attr . Name () )
43
46
if ! ok {
44
- return fmt .Errorf ("identity attribute %q is required" , attrName )
47
+ return fmt .Errorf ("identity attribute %q is required" , attr . Name () )
45
48
}
46
49
47
50
arnVal , ok := arnRaw .(string )
48
51
if ! ok {
49
- return fmt .Errorf ("identity attribute %q: expected string, got %T" , attrName , arnRaw )
52
+ return fmt .Errorf ("identity attribute %q: expected string, got %T" , attr . Name () , arnRaw )
50
53
}
51
54
52
55
arnARN , err := arn .Parse (arnVal )
53
56
if err != nil {
54
- return fmt .Errorf ("identity attribute %q: could not parse %q as ARN: %s" , attrName , arnVal , err )
57
+ return fmt .Errorf ("identity attribute %q: could not parse %q as ARN: %s" , attr . Name () , arnVal , err )
55
58
}
56
59
57
60
rd .Set (names .AttrRegion , arnARN .Region )
58
61
59
- rd .Set (attrName , arnVal )
60
- for _ , attr := range duplicateAttrs {
62
+ rd .Set (attr . ResourceAttributeName () , arnVal )
63
+ for _ , attr := range identitySpec . IdentityDuplicateAttrs {
61
64
setAttribute (rd , attr , arnVal )
62
65
}
63
66
@@ -84,14 +87,16 @@ func RegionalARNValue(_ context.Context, rd *schema.ResourceData, attrName strin
84
87
return nil
85
88
}
86
89
87
- func GlobalARN (_ context.Context , rd * schema.ResourceData , attrName string , duplicateAttrs []string ) error {
90
+ func GlobalARN (_ context.Context , rd * schema.ResourceData , identitySpec inttypes.Identity ) error {
91
+ attr := identitySpec .Attributes [0 ]
92
+
88
93
if rd .Id () != "" {
89
94
_ , err := arn .Parse (rd .Id ())
90
95
if err != nil {
91
96
return fmt .Errorf ("could not parse import ID %q as ARN: %s" , rd .Id (), err )
92
97
}
93
- rd .Set (attrName , rd .Id ())
94
- for _ , attr := range duplicateAttrs {
98
+ rd .Set (attr . ResourceAttributeName () , rd .Id ())
99
+ for _ , attr := range identitySpec . IdentityDuplicateAttrs {
95
100
setAttribute (rd , attr , rd .Id ())
96
101
}
97
102
@@ -103,23 +108,23 @@ func GlobalARN(_ context.Context, rd *schema.ResourceData, attrName string, dupl
103
108
return err
104
109
}
105
110
106
- arnRaw , ok := identity .GetOk (attrName )
111
+ arnRaw , ok := identity .GetOk (attr . Name () )
107
112
if ! ok {
108
- return fmt .Errorf ("identity attribute %q is required" , attrName )
113
+ return fmt .Errorf ("identity attribute %q is required" , attr . Name () )
109
114
}
110
115
111
116
arnVal , ok := arnRaw .(string )
112
117
if ! ok {
113
- return fmt .Errorf ("identity attribute %q: expected string, got %T" , attrName , arnRaw )
118
+ return fmt .Errorf ("identity attribute %q: expected string, got %T" , attr . Name () , arnRaw )
114
119
}
115
120
116
121
_ , err = arn .Parse (arnVal )
117
122
if err != nil {
118
- return fmt .Errorf ("identity attribute %q: could not parse %q as ARN: %s" , attrName , arnVal , err )
123
+ return fmt .Errorf ("identity attribute %q: could not parse %q as ARN: %s" , attr . Name () , arnVal , err )
119
124
}
120
125
121
- rd .Set (attrName , arnVal )
122
- for _ , attr := range duplicateAttrs {
126
+ rd .Set (attr . ResourceAttributeName () , arnVal )
127
+ for _ , attr := range identitySpec . IdentityDuplicateAttrs {
123
128
setAttribute (rd , attr , arnVal )
124
129
}
125
130
0 commit comments