Skip to content

Commit

Permalink
Merge pull request hashicorp#22234 from awsaxeman/f-aws-fsx_openzfs_f…
Browse files Browse the repository at this point in the history
…ile_system

add Amazon FSx for OpenZFS resources
  • Loading branch information
ewbankkit authored Jan 5, 2022
2 parents 4fd5e13 + 34b4a86 commit 7b58ccc
Show file tree
Hide file tree
Showing 18 changed files with 4,343 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .changelog/22234.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-resource
aws_fsx_openzfs_file_system
```

```release-note:new-resource
aws_fsx_openzfs_volume
```

```release-note:new-resource
aws_fsx_openzfs_snapshot
```
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,9 @@ func Provider() *schema.Provider {
"aws_fsx_ontap_file_system": fsx.ResourceOntapFileSystem(),
"aws_fsx_ontap_storage_virtual_machine": fsx.ResourceOntapStorageVirtualMachine(),
"aws_fsx_ontap_volume": fsx.ResourceOntapVolume(),
"aws_fsx_openzfs_file_system": fsx.ResourceOpenzfsFileSystem(),
"aws_fsx_openzfs_volume": fsx.ResourceOpenzfsVolume(),
"aws_fsx_openzfs_snapshot": fsx.ResourceOpenzfsSnapshot(),
"aws_fsx_windows_file_system": fsx.ResourceWindowsFileSystem(),

"aws_gamelift_alias": gamelift.ResourceAlias(),
Expand Down
1 change: 1 addition & 0 deletions internal/service/ec2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func init() {
"aws_emr_studio",
"aws_fsx_lustre_file_system",
"aws_fsx_ontap_file_system",
"aws_fsx_openzfs_file_system",
"aws_fsx_windows_file_system",
"aws_lambda_function",
"aws_lb",
Expand Down
57 changes: 57 additions & 0 deletions internal/service/fsx/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ func TestAccFSxBackup_ontapBasic(t *testing.T) {
})
}

func TestAccFSxBackup_openzfsBasic(t *testing.T) {
var backup fsx.Backup
resourceName := "aws_fsx_backup.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(fsx.EndpointsID, t) },
ErrorCheck: acctest.ErrorCheck(t, fsx.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFsxBackupDestroy,
Steps: []resource.TestStep{
{
Config: testAccBackupOpenzfsBasicConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxBackupExists(resourceName, &backup),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "fsx", regexp.MustCompile(`backup/.+`)),
acctest.CheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccFSxBackup_windowsBasic(t *testing.T) {
var backup fsx.Backup
resourceName := "aws_fsx_backup.test"
Expand Down Expand Up @@ -333,6 +362,22 @@ resource "aws_fsx_ontap_volume" "test" {
`, rName, vName))
}

func testAccBackupOpenzfsBaseConfig(rName string) string {
return acctest.ConfigCompose(testAccBackupBaseConfig(), fmt.Sprintf(`
resource "aws_fsx_openzfs_file_system" "test" {
storage_capacity = 64
subnet_ids = [aws_subnet.test1.id]
deployment_type = "SINGLE_AZ_1"
throughput_capacity = 64
tags = {
Name = %[1]q
}
}
`, rName))
}

func testAccBackupWindowsBaseConfig(rName string) string {
return acctest.ConfigCompose(testAccBackupBaseConfig(), fmt.Sprintf(`
resource "aws_directory_service_directory" "test" {
Expand Down Expand Up @@ -386,6 +431,18 @@ resource "aws_fsx_backup" "test" {
`, rName))
}

func testAccBackupOpenzfsBasicConfig(rName string) string {
return acctest.ConfigCompose(testAccBackupOpenzfsBaseConfig(rName), fmt.Sprintf(`
resource "aws_fsx_backup" "test" {
file_system_id = aws_fsx_openzfs_file_system.test.id
tags = {
Name = %[1]q
}
}
`, rName))
}

func testAccBackupWindowsBasicConfig(rName string) string {
return acctest.ConfigCompose(testAccBackupWindowsBaseConfig(rName), fmt.Sprintf(`
resource "aws_fsx_backup" "test" {
Expand Down
25 changes: 25 additions & 0 deletions internal/service/fsx/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,28 @@ func FindVolumeByID(conn *fsx.FSx, id string) (*fsx.Volume, error) {

return volumes[0], nil
}

func FindSnapshotByID(conn *fsx.FSx, id string) (*fsx.Snapshot, error) {
input := &fsx.DescribeSnapshotsInput{
SnapshotIds: aws.StringSlice([]string{id}),
}

output, err := conn.DescribeSnapshots(input)

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeVolumeNotFound) || tfawserr.ErrCodeEquals(err, fsx.ErrCodeSnapshotNotFound) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.Snapshots) == 0 || output.Snapshots[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Snapshots[0], nil
}
Loading

0 comments on commit 7b58ccc

Please sign in to comment.