Skip to content

Commit

Permalink
Merge pull request #8155 from terraform-providers/t-aws_ec2_client_vp…
Browse files Browse the repository at this point in the history
…n_endpoint-sweeper

tests/resource/aws_ec2_client_vpn_endpoint: Add sweeper
  • Loading branch information
bflad authored Apr 5, 2019
2 parents 7986664 + d555137 commit 0d148e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions aws/resource_aws_ec2_client_vpn_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -11,6 +12,66 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func init() {
resource.AddTestSweepers("aws_ec2_client_vpn_endpoint", &resource.Sweeper{
Name: "aws_ec2_client_vpn_endpoint",
F: testSweepEc2ClientVpnEndpoints,
Dependencies: []string{
"aws_directory_service_directory",
},
})
}

func testSweepEc2ClientVpnEndpoints(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

conn := client.(*AWSClient).ec2conn
input := &ec2.DescribeClientVpnEndpointsInput{}

for {
output, err := conn.DescribeClientVpnEndpoints(input)

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Client VPN Endpoint sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error retrieving Client VPN Endpoints: %s", err)
}

for _, clientVpnEndpoint := range output.ClientVpnEndpoints {
if clientVpnEndpoint.Status != nil && aws.StringValue(clientVpnEndpoint.Status.Code) == ec2.ClientVpnEndpointStatusCodeDeleted {
continue
}

id := aws.StringValue(clientVpnEndpoint.ClientVpnEndpointId)
input := &ec2.DeleteClientVpnEndpointInput{
ClientVpnEndpointId: clientVpnEndpoint.ClientVpnEndpointId,
}

log.Printf("[INFO] Deleting Client VPN Endpoint: %s", id)
_, err := conn.DeleteClientVpnEndpoint(input)

if err != nil {
return fmt.Errorf("error deleting Client VPN Endpoint (%s): %s", id, err)
}
}

if aws.StringValue(output.NextToken) == "" {
break
}

input.NextToken = output.NextToken
}

return nil
}

func TestAccAwsEc2ClientVpnEndpoint_basic(t *testing.T) {
rStr := acctest.RandString(5)

Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func init() {
"aws_beanstalk_environment",
"aws_db_instance",
"aws_directory_service_directory",
"aws_ec2_client_vpn_endpoint",
"aws_ec2_transit_gateway_vpc_attachment",
"aws_eks_cluster",
"aws_elasticache_cluster",
Expand Down

0 comments on commit 0d148e5

Please sign in to comment.