Skip to content

Commit 6b5e5ec

Browse files
authored
Merge pull request #29294 from hashicorp/b-aws_ec2_client_vpn_endpoint.authentication_options-TypeSet
r/aws_ec2_client_vpn_endpoint: Change `authentication_options` to `TypeSet`
2 parents 8991a74 + 6d8f381 commit 6b5e5ec

File tree

3 files changed

+30
-51
lines changed

3 files changed

+30
-51
lines changed

.changelog/29294.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_ec2_client_vpn_endpoint: Change `authentication_options` from `TypeList` to `TypeSet` as order is not significant
3+
```

internal/service/ec2/vpnclient_endpoint.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ResourceClientVPNEndpoint() *schema.Resource {
3838
Computed: true,
3939
},
4040
"authentication_options": {
41-
Type: schema.TypeList,
41+
Type: schema.TypeSet,
4242
Required: true,
4343
ForceNew: true,
4444
MaxItems: 2,
@@ -236,8 +236,8 @@ func resourceClientVPNEndpointCreate(ctx context.Context, d *schema.ResourceData
236236
VpnPort: aws.Int64(int64(d.Get("vpn_port").(int))),
237237
}
238238

239-
if v, ok := d.GetOk("authentication_options"); ok && len(v.([]interface{})) > 0 {
240-
input.AuthenticationOptions = expandClientVPNAuthenticationRequests(v.([]interface{}))
239+
if v, ok := d.GetOk("authentication_options"); ok && v.(*schema.Set).Len() > 0 {
240+
input.AuthenticationOptions = expandClientVPNAuthenticationRequests(v.(*schema.Set).List())
241241
}
242242

243243
if v, ok := d.GetOk("client_connect_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {

internal/service/ec2/vpnclient_endpoint_test.go

+24-48
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ func testAccClientVPNEndpoint_basic(t *testing.T) {
108108
testAccCheckClientVPNEndpointExists(ctx, resourceName, &v),
109109
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`client-vpn-endpoint/cvpn-endpoint-.+`)),
110110
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
111-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "certificate-authentication"),
112-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.active_directory_id", ""),
113-
resource.TestCheckResourceAttrSet(resourceName, "authentication_options.0.root_certificate_chain_arn"),
114-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.saml_provider_arn", ""),
115-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.self_service_saml_provider_arn", ""),
111+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
112+
"type": "certificate-authentication",
113+
}),
116114
resource.TestCheckResourceAttr(resourceName, "client_cidr_block", "10.0.0.0/16"),
117115
resource.TestCheckResourceAttr(resourceName, "client_connect_options.#", "1"),
118116
resource.TestCheckResourceAttr(resourceName, "client_connect_options.0.enabled", "false"),
@@ -132,7 +130,8 @@ func testAccClientVPNEndpoint_basic(t *testing.T) {
132130
resource.TestCheckResourceAttr(resourceName, "session_timeout_hours", "24"),
133131
resource.TestCheckResourceAttr(resourceName, "split_tunnel", "false"),
134132
resource.TestCheckResourceAttr(resourceName, "status", ec2.ClientVpnEndpointStatusCodePendingAssociate),
135-
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
133+
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
134+
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
136135
resource.TestCheckResourceAttr(resourceName, "transport_protocol", "udp"),
137136
resource.TestCheckResourceAttr(resourceName, "vpc_id", ""),
138137
resource.TestCheckResourceAttr(resourceName, "vpn_port", "443"),
@@ -221,7 +220,6 @@ func testAccClientVPNEndpoint_msADAuth(t *testing.T) {
221220
var v ec2.ClientVpnEndpoint
222221
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
223222
resourceName := "aws_ec2_client_vpn_endpoint.test"
224-
dsDirectoryResourceName := "aws_directory_service_directory.test"
225223
domainName := acctest.RandomDomainName()
226224

227225
if testing.Short() {
@@ -239,8 +237,9 @@ func testAccClientVPNEndpoint_msADAuth(t *testing.T) {
239237
Check: resource.ComposeTestCheckFunc(
240238
testAccCheckClientVPNEndpointExists(ctx, resourceName, &v),
241239
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
242-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "directory-service-authentication"),
243-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.active_directory_id", dsDirectoryResourceName, "id"),
240+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
241+
"type": "directory-service-authentication",
242+
}),
244243
),
245244
},
246245
{
@@ -257,8 +256,6 @@ func testAccClientVPNEndpoint_msADAuthAndMutualAuth(t *testing.T) {
257256
var v ec2.ClientVpnEndpoint
258257
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
259258
resourceName := "aws_ec2_client_vpn_endpoint.test"
260-
dsDirectoryResourceName := "aws_directory_service_directory.test"
261-
serverCertificateResourceName := "aws_acm_certificate.test"
262259
domainName := acctest.RandomDomainName()
263260

264261
if testing.Short() {
@@ -276,10 +273,12 @@ func testAccClientVPNEndpoint_msADAuthAndMutualAuth(t *testing.T) {
276273
Check: resource.ComposeTestCheckFunc(
277274
testAccCheckClientVPNEndpointExists(ctx, resourceName, &v),
278275
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "2"),
279-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "directory-service-authentication"),
280-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.active_directory_id", dsDirectoryResourceName, "id"),
281-
resource.TestCheckResourceAttr(resourceName, "authentication_options.1.type", "certificate-authentication"),
282-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.root_certificate_chain_arn", serverCertificateResourceName, "arn"),
276+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
277+
"type": "directory-service-authentication",
278+
}),
279+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
280+
"type": "certificate-authentication",
281+
}),
283282
),
284283
},
285284
{
@@ -297,7 +296,6 @@ func testAccClientVPNEndpoint_federatedAuth(t *testing.T) {
297296
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
298297
idpEntityID := fmt.Sprintf("https://%s", acctest.RandomDomainName())
299298
resourceName := "aws_ec2_client_vpn_endpoint.test"
300-
samlProviderResourceName := "aws_iam_saml_provider.test"
301299

302300
resource.ParallelTest(t, resource.TestCase{
303301
PreCheck: func() { acctest.PreCheck(t); testAccPreCheckClientVPNSyncronize(t) },
@@ -310,8 +308,9 @@ func testAccClientVPNEndpoint_federatedAuth(t *testing.T) {
310308
Check: resource.ComposeTestCheckFunc(
311309
testAccCheckClientVPNEndpointExists(ctx, resourceName, &v),
312310
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
313-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "federated-authentication"),
314-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.saml_provider_arn", samlProviderResourceName, "arn"),
311+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
312+
"type": "federated-authentication",
313+
}),
315314
),
316315
},
317316
{
@@ -329,8 +328,6 @@ func testAccClientVPNEndpoint_federatedAuthWithSelfServiceProvider(t *testing.T)
329328
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
330329
idpEntityID := fmt.Sprintf("https://%s", acctest.RandomDomainName())
331330
resourceName := "aws_ec2_client_vpn_endpoint.test"
332-
samlProvider1ResourceName := "aws_iam_saml_provider.test1"
333-
samlProvider2ResourceName := "aws_iam_saml_provider.test2"
334331

335332
resource.ParallelTest(t, resource.TestCase{
336333
PreCheck: func() { acctest.PreCheck(t); testAccPreCheckClientVPNSyncronize(t) },
@@ -343,9 +340,9 @@ func testAccClientVPNEndpoint_federatedAuthWithSelfServiceProvider(t *testing.T)
343340
Check: resource.ComposeTestCheckFunc(
344341
testAccCheckClientVPNEndpointExists(ctx, resourceName, &v),
345342
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
346-
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "federated-authentication"),
347-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.saml_provider_arn", samlProvider1ResourceName, "arn"),
348-
resource.TestCheckResourceAttrPair(resourceName, "authentication_options.0.self_service_saml_provider_arn", samlProvider2ResourceName, "arn"),
343+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "authentication_options.*", map[string]string{
344+
"type": "federated-authentication",
345+
}),
349346
),
350347
},
351348
{
@@ -789,9 +786,7 @@ resource "aws_acm_certificate" %[1]q {
789786
}
790787

791788
func testAccClientVPNEndpointConfig_msADBase(rName, domain string) string {
792-
return acctest.ConfigCompose(
793-
acctest.ConfigAvailableAZsNoOptIn(),
794-
fmt.Sprintf(`
789+
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(`
795790
resource "aws_directory_service_directory" "test" {
796791
name = %[2]q
797792
password = "SuperSecretPassw0rd"
@@ -802,25 +797,6 @@ resource "aws_directory_service_directory" "test" {
802797
subnet_ids = aws_subnet.test[*].id
803798
}
804799
}
805-
806-
resource "aws_vpc" "test" {
807-
cidr_block = "10.0.0.0/16"
808-
809-
tags = {
810-
Name = %[1]q
811-
}
812-
}
813-
814-
resource "aws_subnet" "test" {
815-
count = 2
816-
availability_zone = data.aws_availability_zones.available.names[count.index]
817-
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)
818-
vpc_id = aws_vpc.test.id
819-
820-
tags = {
821-
Name = %[1]q
822-
}
823-
}
824800
`, rName, domain))
825801
}
826802

@@ -1048,7 +1024,7 @@ func testAccClientVPNEndpointConfig_microsoftAD(t *testing.T, rName, domain stri
10481024
fmt.Sprintf(`
10491025
resource "aws_ec2_client_vpn_endpoint" "test" {
10501026
server_certificate_arn = aws_acm_certificate.test.arn
1051-
client_cidr_block = "10.0.0.0/16"
1027+
client_cidr_block = "10.1.0.0/20"
10521028
10531029
authentication_options {
10541030
type = "directory-service-authentication"
@@ -1073,7 +1049,7 @@ func testAccClientVPNEndpointConfig_mutualAuthAndMicrosoftAD(t *testing.T, rName
10731049
fmt.Sprintf(`
10741050
resource "aws_ec2_client_vpn_endpoint" "test" {
10751051
server_certificate_arn = aws_acm_certificate.test.arn
1076-
client_cidr_block = "10.0.0.0/16"
1052+
client_cidr_block = "10.1.0.0/20"
10771053
10781054
authentication_options {
10791055
type = "directory-service-authentication"
@@ -1303,7 +1279,7 @@ locals {
13031279
13041280
resource "aws_ec2_client_vpn_endpoint" "test" {
13051281
server_certificate_arn = aws_acm_certificate.test.arn
1306-
client_cidr_block = "10.0.0.0/16"
1282+
client_cidr_block = "10.1.0.0/22"
13071283
13081284
authentication_options {
13091285
type = "certificate-authentication"

0 commit comments

Comments
 (0)