Skip to content

Commit

Permalink
Add deployment type to aws_fsx_lustre_file_system
Browse files Browse the repository at this point in the history
  • Loading branch information
mtpdt committed Jul 24, 2020
1 parent d9f833b commit 4ba8382
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
41 changes: 41 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource {
validation.StringMatch(regexp.MustCompile(`^[1-7]:([01]\d|2[0-3]):?([0-5]\d)$`), "must be in the format d:HH:MM"),
),
},
"deployment_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: fsx.LustreDeploymentTypeScratch1,
ValidateFunc: validation.StringInSlice([]string{
fsx.LustreDeploymentTypeScratch1,
fsx.LustreDeploymentTypeScratch2,
fsx.LustreDeploymentTypePersistent1,
}, false),
},
"per_unit_storage_throughput": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntInSlice([]int{
50,
100,
200,
}),
},
},
}
}
Expand Down Expand Up @@ -162,6 +183,22 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface
input.LustreConfiguration.WeeklyMaintenanceStartTime = aws.String(v.(string))
}

if v, ok := d.GetOk("deployment_type"); ok {
if input.LustreConfiguration == nil {
input.LustreConfiguration = &fsx.CreateFileSystemLustreConfiguration{}
}

input.LustreConfiguration.DeploymentType = aws.String(v.(string))
}

if v, ok := d.GetOk("per_unit_storage_throughput"); ok {
if input.LustreConfiguration == nil {
input.LustreConfiguration = &fsx.CreateFileSystemLustreConfiguration{}
}

input.LustreConfiguration.PerUnitStorageThroughput = aws.Int64(int64(v.(int)))
}

result, err := conn.CreateFileSystem(input)
if err != nil {
return fmt.Errorf("Error creating FSx filesystem: %s", err)
Expand Down Expand Up @@ -251,6 +288,10 @@ func resourceAwsFsxLustreFileSystemRead(d *schema.ResourceData, meta interface{}
d.Set("export_path", filesystem.LustreConfiguration.DataRepositoryConfiguration.ExportPath)
d.Set("import_path", filesystem.LustreConfiguration.DataRepositoryConfiguration.ImportPath)
d.Set("imported_file_chunk_size", filesystem.LustreConfiguration.DataRepositoryConfiguration.ImportedFileChunkSize)
d.Set("deployment_type", filesystem.LustreConfiguration.DeploymentType)
if filesystem.LustreConfiguration.PerUnitStorageThroughput != nil {
d.Set("per_unit_storage_throughput", filesystem.LustreConfiguration.PerUnitStorageThroughput)
}

if err := d.Set("network_interface_ids", aws.StringValueSlice(filesystem.NetworkInterfaceIds)); err != nil {
return fmt.Errorf("error setting network_interface_ids: %s", err)
Expand Down
80 changes: 80 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestMatchResourceAttr(resourceName, "vpc_id", regexp.MustCompile(`^vpc-.+`)),
resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypeScratch1),
),
},
{
Expand All @@ -102,6 +103,10 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
{
Config: testAccAwsFsxLustreFileSystemDeploymentType(fsx.LustreDeploymentTypeScratch1),
PlanOnly: true,
},
},
})
}
Expand Down Expand Up @@ -382,6 +387,60 @@ func TestAccAWSFsxLustreFileSystem_WeeklyMaintenanceStartTime(t *testing.T) {
})
}

func TestAccAWSFsxLustreFileSystem_DeploymentTypePersistent1(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_lustre_file_system.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFsxLustreFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxLustreFileSystemPersistentDeploymentType(50),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem),
// per_unit_storage_throughput is only available with deployment_type=PERSISTENT_1, so we test both here.
resource.TestCheckResourceAttr(resourceName, "per_unit_storage_throughput", "50"),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypePersistent1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
},
})
}

func TestAccAWSFsxLustreFileSystem_DeploymentTypeScratch2(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_lustre_file_system.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFsxLustreFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxLustreFileSystemDeploymentType(fsx.LustreDeploymentTypeScratch2),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypeScratch2),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
},
})
}

func testAccCheckFsxLustreFileSystemExists(resourceName string, fs *fsx.FileSystem) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -671,3 +730,24 @@ resource "aws_fsx_lustre_file_system" "test" {
}
`, weeklyMaintenanceStartTime)
}

func testAccAwsFsxLustreFileSystemDeploymentType(deploymentType string) string {
return testAccAwsFsxLustreFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_lustre_file_system" "test" {
storage_capacity = 1200
subnet_ids = ["${aws_subnet.test1.id}"]
deployment_type = %[1]q
}
`, deploymentType)
}

func testAccAwsFsxLustreFileSystemPersistentDeploymentType(perUnitStorageThroughput int) string {
return testAccAwsFsxLustreFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_lustre_file_system" "test" {
storage_capacity = 1200
subnet_ids = ["${aws_subnet.test1.id}"]
deployment_type = "PERSISTENT_1"
per_unit_storage_throughput = %[1]d
}
`, perUnitStorageThroughput)
}
2 changes: 2 additions & 0 deletions website/docs/r/fsx_lustre_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following arguments are supported:
* `security_group_ids` - (Optional) A list of IDs for the security groups that apply to the specified network interfaces created for file system access. These security groups will apply to all network interfaces.
* `tags` - (Optional) A map of tags to assign to the file system.
* `weekly_maintenance_start_time` - (Optional) The preferred start time (in `d:HH:MM` format) to perform weekly maintenance, in the UTC time zone.
* `deployment_type` - (Optional) - The filesystem deployment type. One of: `SCRATCH_1`, `SCRATCH_2`, `PERSISTENT_1`.
* `per_unit_storage_throughput` - (Optional) - Describes the amount of read and write throughput for each 1 tebibyte of storage, in MB/s/TiB, required for the `PERSISTENT_1` deployment_type. For valid values, see the [AWS documentation](https://docs.aws.amazon.com/fsx/latest/APIReference/API_CreateFileSystemLustreConfiguration.html).

## Attributes Reference

Expand Down

0 comments on commit 4ba8382

Please sign in to comment.