Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DescribeClientVpnTargetNetworks #14380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion aws/internal/service/ec2/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ func ClientVpnNetworkAssociationStatus(conn *ec2.EC2, cvnaID string, cvepID stri
return func() (interface{}, string, error) {
result, err := conn.DescribeClientVpnTargetNetworks(&ec2.DescribeClientVpnTargetNetworksInput{
ClientVpnEndpointId: aws.String(cvepID),
AssociationIds: []*string{aws.String(cvnaID)},
Filters: []*ec2.Filter{
{
Name: aws.String("association-id"),
Values: []*string{aws.String(cvnaID)},
},
},
})

if tfec2.ErrCodeEquals(err, tfec2.ErrCodeClientVpnAssociationIdNotFound) || tfec2.ErrCodeEquals(err, tfec2.ErrCodeClientVpnEndpointIdNotFound) {
Expand Down
7 changes: 6 additions & 1 deletion aws/resource_aws_ec2_client_vpn_network_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ func resourceAwsEc2ClientVpnNetworkAssociationRead(d *schema.ResourceData, meta

result, err := conn.DescribeClientVpnTargetNetworks(&ec2.DescribeClientVpnTargetNetworksInput{
ClientVpnEndpointId: aws.String(d.Get("client_vpn_endpoint_id").(string)),
AssociationIds: []*string{aws.String(d.Id())},
Filters: []*ec2.Filter{
{
Name: aws.String("association-id"),
Values: []*string{aws.String(d.Id())},
},
},
})

if isAWSErr(err, tfec2.ErrCodeClientVpnAssociationIdNotFound, "") || isAWSErr(err, tfec2.ErrCodeClientVpnEndpointIdNotFound, "") {
Expand Down
62 changes: 48 additions & 14 deletions aws/resource_aws_ec2_client_vpn_network_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func testAccAwsEc2ClientVpnNetworkAssociation_basic(t *testing.T) {
var assoc ec2.TargetNetwork
var group ec2.SecurityGroup
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_network_association.test"
resourceNames := []string{"aws_ec2_client_vpn_network_association.test", "aws_ec2_client_vpn_network_association.test2"}
endpointResourceName := "aws_ec2_client_vpn_endpoint.test"
subnetResourceName := "aws_subnet.test"
subnetResourceNames := []string{"aws_subnet.test", "aws_subnet.test2"}
vpcResourceName := "aws_vpc.test"
defaultSecurityGroupResourceName := "aws_default_security_group.test"

Expand All @@ -111,22 +111,30 @@ func testAccAwsEc2ClientVpnNetworkAssociation_basic(t *testing.T) {
{
Config: testAccEc2ClientVpnNetworkAssociationConfigBasic(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnNetworkAssociationExists(resourceName, &assoc),
resource.TestMatchResourceAttr(resourceName, "association_id", regexp.MustCompile("^cvpn-assoc-[a-z0-9]+$")),
resource.TestCheckResourceAttrPair(resourceName, "id", resourceName, "association_id"),
resource.TestCheckResourceAttrPair(resourceName, "client_vpn_endpoint_id", endpointResourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "subnet_id", subnetResourceName, "id"),
testAccCheckAwsEc2ClientVpnNetworkAssociationExists(resourceNames[0], &assoc),
resource.TestMatchResourceAttr(resourceNames[0], "association_id", regexp.MustCompile("^cvpn-assoc-[a-z0-9]+$")),
resource.TestMatchResourceAttr(resourceNames[1], "association_id", regexp.MustCompile("^cvpn-assoc-[a-z0-9]+$")),
resource.TestCheckResourceAttrPair(resourceNames[0], "id", resourceNames[0], "association_id"),
resource.TestCheckResourceAttrPair(resourceNames[0], "client_vpn_endpoint_id", endpointResourceName, "id"),
resource.TestCheckResourceAttrPair(resourceNames[0], "subnet_id", subnetResourceNames[0], "id"),
resource.TestCheckResourceAttrPair(resourceNames[1], "subnet_id", subnetResourceNames[1], "id"),
testAccCheckAWSDefaultSecurityGroupExists(defaultSecurityGroupResourceName, &group),
resource.TestCheckResourceAttr(resourceName, "security_groups.#", "1"),
testAccCheckAwsEc2ClientVpnNetworkAssociationSecurityGroupID(resourceName, "security_groups.*", &group),
resource.TestCheckResourceAttrPair(resourceName, "vpc_id", vpcResourceName, "id"),
resource.TestCheckResourceAttr(resourceNames[0], "security_groups.#", "1"),
testAccCheckAwsEc2ClientVpnNetworkAssociationSecurityGroupID(resourceNames[0], "security_groups.*", &group),
resource.TestCheckResourceAttrPair(resourceNames[0], "vpc_id", vpcResourceName, "id"),
),
},
{
ResourceName: resourceName,
ResourceName: resourceNames[0],
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccAwsEc2ClientVpnNetworkAssociationImportStateIdFunc(resourceName),
ImportStateIdFunc: testAccAwsEc2ClientVpnNetworkAssociationImportStateIdFunc(resourceNames[0]),
},
{
ResourceName: resourceNames[1],
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccAwsEc2ClientVpnNetworkAssociationImportStateIdFunc(resourceNames[1]),
},
},
})
Expand Down Expand Up @@ -207,7 +215,12 @@ func testAccCheckAwsEc2ClientVpnNetworkAssociationDestroy(s *terraform.State) er

resp, _ := conn.DescribeClientVpnTargetNetworks(&ec2.DescribeClientVpnTargetNetworksInput{
ClientVpnEndpointId: aws.String(rs.Primary.Attributes["client_vpn_endpoint_id"]),
AssociationIds: []*string{aws.String(rs.Primary.ID)},
Filters: []*ec2.Filter{
{
Name: aws.String("association-id"),
Values: []*string{aws.String(rs.Primary.ID)},
},
},
})

for _, v := range resp.ClientVpnTargetNetworks {
Expand Down Expand Up @@ -235,7 +248,12 @@ func testAccCheckAwsEc2ClientVpnNetworkAssociationExists(name string, assoc *ec2

resp, err := conn.DescribeClientVpnTargetNetworks(&ec2.DescribeClientVpnTargetNetworksInput{
ClientVpnEndpointId: aws.String(rs.Primary.Attributes["client_vpn_endpoint_id"]),
AssociationIds: []*string{aws.String(rs.Primary.ID)},
Filters: []*ec2.Filter{
{
Name: aws.String("association-id"),
Values: []*string{aws.String(rs.Primary.ID)},
},
},
})

if err != nil {
Expand Down Expand Up @@ -280,6 +298,11 @@ resource "aws_ec2_client_vpn_network_association" "test" {
subnet_id = aws_subnet.test.id
}

resource "aws_ec2_client_vpn_network_association" "test2" {
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.test.id
subnet_id = aws_subnet.test2.id
}

resource "aws_ec2_client_vpn_endpoint" "test" {
description = "terraform-testacc-clientvpn-%[1]s"
server_certificate_arn = aws_acm_certificate.test.arn
Expand Down Expand Up @@ -412,6 +435,17 @@ resource "aws_subnet" "test" {
Name = "tf-acc-subnet-%[1]s"
}
}

resource "aws_subnet" "test2" {
availability_zone = data.aws_availability_zones.available.names[1]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, 1)
vpc_id = aws_vpc.test.id
map_public_ip_on_launch = true

tags = {
Name = "tf-acc-subnet-%[1]s"
}
}
`, rName)
}

Expand Down