Skip to content

Commit

Permalink
Add test sweepers for fsx filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
ryndaniels committed Aug 14, 2019
1 parent cc039ac commit f923aa6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
5 changes: 3 additions & 2 deletions aws/resource_aws_directory_service_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

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

Expand Down
55 changes: 55 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"regexp"
"testing"
"time"
Expand All @@ -13,6 +14,60 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func init() {
resource.AddTestSweepers("aws_fsx_lustre_file_system", &resource.Sweeper{
Name: "aws_fsx_lustre_file_system",
F: testSweepFSXLustreFileSystems,
})
}

func testSweepFSXLustreFileSystems(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).fsxconn
input := &fsx.DescribeFileSystemsInput{}

err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
for _, fs := range page.FileSystems {
if aws.StringValue(fs.FileSystemType) != fsx.FileSystemTypeLustre {
continue
}

input := &fsx.DeleteFileSystemInput{
FileSystemId: fs.FileSystemId,
}

log.Printf("[INFO] Deleting FSx lustre filesystem: %s", aws.StringValue(fs.FileSystemId))
_, err := conn.DeleteFileSystem(input)

if err != nil {
log.Printf("[ERROR] Error deleting FSx filesystem: %s", err)
continue
}

if err := waitForFsxFileSystemDeletion(conn, aws.StringValue(fs.FileSystemId), 30*time.Minute); err != nil {
log.Printf("[ERROR] Error waiting for filesystem (%s) to delete: %s", aws.StringValue(fs.FileSystemId), err)
}
}

return !lastPage
})

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

if err != nil {
return fmt.Errorf("error listing FSx Lustre Filesystems: %s", err)
}

return nil

}

func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_lustre_file_system.test"
Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_fsx_windows_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"regexp"
"testing"
"time"
Expand All @@ -12,6 +13,64 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func init() {
resource.AddTestSweepers("aws_fsx_windows_file_system", &resource.Sweeper{
Name: "aws_fsx_windows_file_system",
F: testSweepFSXWindowsFileSystems,
})
}

func testSweepFSXWindowsFileSystems(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).fsxconn
input := &fsx.DescribeFileSystemsInput{}

err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
for _, fs := range page.FileSystems {
if aws.StringValue(fs.FileSystemType) != fsx.FileSystemTypeWindows {
continue
}

input := &fsx.DeleteFileSystemInput{
ClientRequestToken: aws.String(resource.UniqueId()),
FileSystemId: fs.FileSystemId,
WindowsConfiguration: &fsx.DeleteFileSystemWindowsConfiguration{
SkipFinalBackup: aws.Bool(true),
},
}

log.Printf("[INFO] Deleting FSx windows filesystem: %s", aws.StringValue(fs.FileSystemId))
_, err := conn.DeleteFileSystem(input)

if err != nil {
log.Printf("[ERROR] Error deleting FSx filesystem: %s", err)
continue
}

if err := waitForFsxFileSystemDeletion(conn, aws.StringValue(fs.FileSystemId), 30*time.Minute); err != nil {
log.Printf("[ERROR] Error waiting for filesystem (%s) to delete: %s", aws.StringValue(fs.FileSystemId), err)
}
}

return !lastPage
})

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

if err != nil {
return fmt.Errorf("error listing FSx Windows Filesystems: %s", err)
}

return nil

}

func TestAccAWSFsxWindowsFileSystem_basic(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_windows_file_system.test"
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func init() {
"aws_elasticsearch_domain",
"aws_elb",
"aws_emr_cluster",
"aws_fsx_lustre_file_system",
"aws_fsx_windows_file_system",
"aws_lambda_function",
"aws_lb",
"aws_mq_broker",
Expand Down

0 comments on commit f923aa6

Please sign in to comment.