@@ -3,6 +3,7 @@ package ec2_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "regexp"
6
7
"testing"
7
8
8
9
"github.com/aws/aws-sdk-go/service/ec2"
@@ -17,8 +18,9 @@ import (
17
18
18
19
func TestAccVPCEndpointServiceAllowedPrincipal_basic (t * testing.T ) {
19
20
ctx := acctest .Context (t )
21
+ rName := sdkacctest .RandomWithPrefix ("tfacctest" )
22
+
20
23
resourceName := "aws_vpc_endpoint_service_allowed_principal.test"
21
- rName := sdkacctest .RandomWithPrefix ("tfacctest" ) // 32 character limit
22
24
23
25
resource .ParallelTest (t , resource.TestCase {
24
26
PreCheck : func () { acctest .PreCheck (ctx , t ) },
@@ -28,8 +30,109 @@ func TestAccVPCEndpointServiceAllowedPrincipal_basic(t *testing.T) {
28
30
Steps : []resource.TestStep {
29
31
{
30
32
Config : testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName ),
31
- Check : resource .ComposeTestCheckFunc (
33
+ Check : resource .ComposeAggregateTestCheckFunc (
32
34
testAccCheckVPCEndpointServiceAllowedPrincipalExists (ctx , resourceName ),
35
+ resource .TestMatchResourceAttr (resourceName , "id" , regexp .MustCompile (`^vpce-svc-perm-\w{17}$` )),
36
+ resource .TestCheckResourceAttrPair (resourceName , "vpc_endpoint_service_id" , "aws_vpc_endpoint_service.test" , "id" ),
37
+ resource .TestCheckResourceAttrPair (resourceName , "principal_arn" , "data.aws_iam_session_context.current" , "issuer_arn" ),
38
+ ),
39
+ },
40
+ },
41
+ })
42
+ }
43
+
44
+ func TestAccVPCEndpointServiceAllowedPrincipal_tags (t * testing.T ) {
45
+ ctx := acctest .Context (t )
46
+ rName := sdkacctest .RandomWithPrefix ("tfacctest" )
47
+
48
+ resourceName := "aws_vpc_endpoint_service_allowed_principal.test"
49
+ tagResourceName := "aws_ec2_tag.test"
50
+
51
+ resource .ParallelTest (t , resource.TestCase {
52
+ PreCheck : func () { acctest .PreCheck (ctx , t ) },
53
+ ErrorCheck : acctest .ErrorCheck (t , ec2 .EndpointsID ),
54
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
55
+ CheckDestroy : testAccCheckVPCEndpointServiceAllowedPrincipalDestroy (ctx ),
56
+ Steps : []resource.TestStep {
57
+ {
58
+ Config : testAccVPCEndpointServiceAllowedPrincipalConfig_tag (rName ),
59
+ Check : resource .ComposeAggregateTestCheckFunc (
60
+ testAccCheckVPCEndpointServiceAllowedPrincipalExists (ctx , resourceName ),
61
+ resource .TestCheckResourceAttrPair (tagResourceName , "resource_id" , resourceName , "id" ),
62
+ resource .TestCheckResourceAttr (tagResourceName , "key" , "Name" ),
63
+ resource .TestCheckResourceAttr (tagResourceName , "value" , rName ),
64
+ ),
65
+ },
66
+ },
67
+ })
68
+ }
69
+
70
+ func TestAccVPCEndpointServiceAllowedPrincipal_migrateID (t * testing.T ) {
71
+ ctx := acctest .Context (t )
72
+ rName := sdkacctest .RandomWithPrefix ("tfacctest" )
73
+
74
+ resourceName := "aws_vpc_endpoint_service_allowed_principal.test"
75
+
76
+ resource .ParallelTest (t , resource.TestCase {
77
+ PreCheck : func () { acctest .PreCheck (ctx , t ) },
78
+ ErrorCheck : acctest .ErrorCheck (t , ec2 .EndpointsID ),
79
+ CheckDestroy : testAccCheckVPCEndpointServiceAllowedPrincipalDestroy (ctx ),
80
+ Steps : []resource.TestStep {
81
+ {
82
+ ExternalProviders : map [string ]resource.ExternalProvider {
83
+ "aws" : {
84
+ Source : "hashicorp/aws" ,
85
+ VersionConstraint : "4.63.0" ,
86
+ },
87
+ },
88
+ Config : testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName ),
89
+ Check : resource .ComposeAggregateTestCheckFunc (
90
+ testAccCheckVPCEndpointServiceAllowedPrincipalExists (ctx , resourceName ),
91
+ ),
92
+ },
93
+ {
94
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
95
+ Config : testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName ),
96
+ PlanOnly : true ,
97
+ },
98
+ },
99
+ })
100
+ }
101
+
102
+ // Verify that the resource returns an ID usable for creating an `aws_ec2_tag`
103
+ func TestAccVPCEndpointServiceAllowedPrincipal_migrateAndTag (t * testing.T ) {
104
+ ctx := acctest .Context (t )
105
+ rName := sdkacctest .RandomWithPrefix ("tfacctest" )
106
+
107
+ resourceName := "aws_vpc_endpoint_service_allowed_principal.test"
108
+ tagResourceName := "aws_ec2_tag.test"
109
+
110
+ resource .ParallelTest (t , resource.TestCase {
111
+ PreCheck : func () { acctest .PreCheck (ctx , t ) },
112
+ ErrorCheck : acctest .ErrorCheck (t , ec2 .EndpointsID ),
113
+ CheckDestroy : testAccCheckVPCEndpointServiceAllowedPrincipalDestroy (ctx ),
114
+ Steps : []resource.TestStep {
115
+ {
116
+ ExternalProviders : map [string ]resource.ExternalProvider {
117
+ "aws" : {
118
+ Source : "hashicorp/aws" ,
119
+ VersionConstraint : "4.63.0" ,
120
+ },
121
+ },
122
+ Config : testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName ),
123
+ Check : resource .ComposeAggregateTestCheckFunc (
124
+ testAccCheckVPCEndpointServiceAllowedPrincipalExists (ctx , resourceName ),
125
+ ),
126
+ },
127
+ {
128
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
129
+ Config : testAccVPCEndpointServiceAllowedPrincipalConfig_tag (rName ),
130
+ Check : resource .ComposeAggregateTestCheckFunc (
131
+ testAccCheckVPCEndpointServiceAllowedPrincipalExists (ctx , resourceName ),
132
+ resource .TestMatchResourceAttr (resourceName , "id" , regexp .MustCompile (`^vpce-svc-perm-\w{17}$` )),
133
+ resource .TestCheckResourceAttrPair (tagResourceName , "resource_id" , resourceName , "id" ),
134
+ resource .TestCheckResourceAttr (tagResourceName , "key" , "Name" ),
135
+ resource .TestCheckResourceAttr (tagResourceName , "value" , rName ),
33
136
),
34
137
},
35
138
},
@@ -45,7 +148,7 @@ func testAccCheckVPCEndpointServiceAllowedPrincipalDestroy(ctx context.Context)
45
148
continue
46
149
}
47
150
48
- err := tfec2 .FindVPCEndpointServicePermissionExists (ctx , conn , rs .Primary .Attributes ["vpc_endpoint_service_id" ], rs .Primary .Attributes ["principal_arn" ])
151
+ _ , err := tfec2 .FindVPCEndpointServicePermission (ctx , conn , rs .Primary .Attributes ["vpc_endpoint_service_id" ], rs .Primary .Attributes ["principal_arn" ])
49
152
50
153
if tfresource .NotFound (err ) {
51
154
continue
@@ -75,12 +178,15 @@ func testAccCheckVPCEndpointServiceAllowedPrincipalExists(ctx context.Context, n
75
178
76
179
conn := acctest .Provider .Meta ().(* conns.AWSClient ).EC2Conn ()
77
180
78
- return tfec2 .FindVPCEndpointServicePermissionExists (ctx , conn , rs .Primary .Attributes ["vpc_endpoint_service_id" ], rs .Primary .Attributes ["principal_arn" ])
181
+ _ , err := tfec2 .FindVPCEndpointServicePermission (ctx , conn , rs .Primary .Attributes ["vpc_endpoint_service_id" ], rs .Primary .Attributes ["principal_arn" ])
182
+
183
+ return err
79
184
}
80
185
}
81
186
82
187
func testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName string ) string {
83
- return acctest .ConfigCompose (testAccVPCEndpointServiceConfig_networkLoadBalancerBase (rName , 1 ), fmt .Sprintf (`
188
+ return acctest .ConfigCompose (
189
+ testAccVPCEndpointServiceConfig_networkLoadBalancerBase (rName , 1 ), `
84
190
data "aws_caller_identity" "current" {}
85
191
86
192
data "aws_iam_session_context" "current" {
@@ -90,16 +196,25 @@ data "aws_iam_session_context" "current" {
90
196
resource "aws_vpc_endpoint_service" "test" {
91
197
acceptance_required = false
92
198
network_load_balancer_arns = aws_lb.test[*].arn
93
-
94
- tags = {
95
- Name = %[1]q
96
- }
97
199
}
98
200
99
201
resource "aws_vpc_endpoint_service_allowed_principal" "test" {
100
202
vpc_endpoint_service_id = aws_vpc_endpoint_service.test.id
101
203
102
204
principal_arn = data.aws_iam_session_context.current.issuer_arn
103
205
}
206
+ ` )
207
+ }
208
+
209
+ func testAccVPCEndpointServiceAllowedPrincipalConfig_tag (rName string ) string {
210
+ return acctest .ConfigCompose (
211
+ testAccVPCEndpointServiceAllowedPrincipalConfig_basic (rName ),
212
+ fmt .Sprintf (`
213
+ resource "aws_ec2_tag" "test" {
214
+ resource_id = aws_vpc_endpoint_service_allowed_principal.test.id
215
+
216
+ key = "Name"
217
+ value = %[1]q
218
+ }
104
219
` , rName ))
105
220
}
0 commit comments