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

tests/resource/aws_ec2_client_vpn_endpoint: Add sweeper #8155

Merged
merged 2 commits into from
Apr 5, 2019
Merged
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
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