From 4ba8382aedea952fad8c387da68c9c0c910f36d3 Mon Sep 17 00:00:00 2001 From: Matthew Tse <66440247+mtpdt@users.noreply.github.com> Date: Fri, 5 Jun 2020 13:42:07 -0400 Subject: [PATCH] Add deployment type to aws_fsx_lustre_file_system --- aws/resource_aws_fsx_lustre_file_system.go | 41 ++++++++++ ...esource_aws_fsx_lustre_file_system_test.go | 80 +++++++++++++++++++ .../r/fsx_lustre_file_system.html.markdown | 2 + 3 files changed, 123 insertions(+) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index 619b24dd1ba..afef9aeda7e 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -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, + }), + }, }, } } @@ -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) @@ -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) diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index a14159d75ff..0a4c318b276 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -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), ), }, { @@ -102,6 +103,10 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"security_group_ids"}, }, + { + Config: testAccAwsFsxLustreFileSystemDeploymentType(fsx.LustreDeploymentTypeScratch1), + PlanOnly: true, + }, }, }) } @@ -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] @@ -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) +} diff --git a/website/docs/r/fsx_lustre_file_system.html.markdown b/website/docs/r/fsx_lustre_file_system.html.markdown index e8f7f83e8e1..ddbc7255743 100644 --- a/website/docs/r/fsx_lustre_file_system.html.markdown +++ b/website/docs/r/fsx_lustre_file_system.html.markdown @@ -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