Skip to content

Commit

Permalink
Add storage_type to aws_fsx_lustre_file_system
Browse files Browse the repository at this point in the history
  • Loading branch information
mtpdt committed Sep 24, 2020
1 parent 3aec4b0 commit 67e07a6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
24 changes: 24 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource {
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntInSlice([]int{
12,
40,
50,
100,
200,
Expand All @@ -148,6 +150,19 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource {
Computed: true,
ValidateFunc: validation.IntBetween(0, 35),
},
"storage_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: fsx.StorageTypeSsd,
ValidateFunc: validation.StringInSlice(fsx.StorageType_Values(), false),
},
"drive_cache_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.DriveCacheType_Values(), false),
},
},
}
}
Expand All @@ -159,6 +174,7 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface
ClientRequestToken: aws.String(resource.UniqueId()),
FileSystemType: aws.String(fsx.FileSystemTypeLustre),
StorageCapacity: aws.Int64(int64(d.Get("storage_capacity").(int))),
StorageType: aws.String(d.Get("storage_type").(string)),
SubnetIds: expandStringList(d.Get("subnet_ids").([]interface{})),
LustreConfiguration: &fsx.CreateFileSystemLustreConfiguration{
DeploymentType: aws.String(d.Get("deployment_type").(string)),
Expand Down Expand Up @@ -202,6 +218,10 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface
input.LustreConfiguration.PerUnitStorageThroughput = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("drive_cache_type"); ok {
input.LustreConfiguration.DriveCacheType = aws.String(v.(string))
}

result, err := conn.CreateFileSystem(input)
if err != nil {
return fmt.Errorf("Error creating FSx Lustre filesystem: %w", err)
Expand Down Expand Up @@ -309,6 +329,10 @@ func resourceAwsFsxLustreFileSystemRead(d *schema.ResourceData, meta interface{}
d.Set("per_unit_storage_throughput", lustreConfig.PerUnitStorageThroughput)
}
d.Set("mount_name", filesystem.LustreConfiguration.MountName)
d.Set("storage_type", filesystem.StorageType)
if filesystem.LustreConfiguration.DriveCacheType != nil {
d.Set("drive_cache_type", filesystem.LustreConfiguration.DriveCacheType)
}

if filesystem.KmsKeyId != nil {
d.Set("kms_key_id", filesystem.KmsKeyId)
Expand Down
68 changes: 68 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) {
resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypeScratch1),
resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"),
resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd),
),
},
{
Expand Down Expand Up @@ -528,6 +529,60 @@ func TestAccAWSFsxLustreFileSystem_DeploymentTypeScratch2(t *testing.T) {
})
}

func TestAccAWSFsxLustreFileSystem_StorageTypeHddDriveCacheRead(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: testAccAwsFsxLustreFileSystemHddStorageType(fsx.DriveCacheTypeRead),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeHdd),
resource.TestCheckResourceAttr(resourceName, "drive_cache_type", fsx.DriveCacheTypeRead),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
},
})
}

func TestAccAWSFsxLustreFileSystem_StorageTypeHddDriveCacheNone(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: testAccAwsFsxLustreFileSystemHddStorageType(fsx.DriveCacheTypeNone),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeHdd),
resource.TestCheckResourceAttr(resourceName, "drive_cache_type", fsx.DriveCacheTypeNone),
),
},
{
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 @@ -866,3 +921,16 @@ resource "aws_fsx_lustre_file_system" "test" {
}
`
}

func testAccAwsFsxLustreFileSystemHddStorageType(drive_cache_type string) string {
return testAccAwsFsxLustreFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_lustre_file_system" "test" {
storage_capacity = 6000
subnet_ids = [aws_subnet.test1.id]
deployment_type = "PERSISTENT_1"
per_unit_storage_throughput = 12
storage_type = "HDD"
drive_cache_type = %[1]q
}
`, drive_cache_type)
}
4 changes: 3 additions & 1 deletion website/docs/r/fsx_lustre_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ The following arguments are supported:
* `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`.
* `kms_key_id` - (Optional) ARN for the KMS Key to encrypt the file system at rest, applicable for `PERSISTENT_1`. Defaults to an AWS managed KMS Key.
* `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).
* `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. Valid values for `SSD` storage_type are 50, 100, 200. Valid values for `HDD` storage_type are 12, 40.
* `automatic_backup_retention_days` - (Optional) The number of days to retain automatic backups. Setting this to 0 disables automatic backups. You can retain automatic backups for a maximum of 35 days. only valid for `PERSISTENT_1` deployment_type.
* `storage_type` - (Optional) - The filesystem storage type. Either `SSD` or `HDD`, defaults to `SSD`. `HDD` is only supported on `PERSISTENT_1` deployment types.
* `drive_cache_type` - (Optional) - The type of drive cache used by `PERSISTENT_1` filesystems that are provisioned with `HDD` storage_type. Required for `HDD` storage_type, set to either `READ` or `NONE`.

## Attributes Reference

Expand Down

0 comments on commit 67e07a6

Please sign in to comment.