Skip to content

Commit

Permalink
Merge pull request #19568 from DrFaust92/r/fsx_lustre_capacity
Browse files Browse the repository at this point in the history
r/fsx_lustre_filesystem - allow updating `storage_capacity`
  • Loading branch information
ewbankkit committed Jun 2, 2021
2 parents c4b4e16 + 4e9ff0f commit deccb39
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/19568.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_fsx_lustre_filesystem: Allow updating `storage_capacity`.
```
27 changes: 25 additions & 2 deletions aws/resource_aws_fsx_lustre_file_system.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package aws

import (
"context"
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/fsx"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -89,7 +91,6 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource {
"storage_capacity": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1200),
},
"subnet_ids": {
Expand Down Expand Up @@ -183,8 +184,25 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource {
},
},

CustomizeDiff: SetTagsDiff,
CustomizeDiff: customdiff.Sequence(
SetTagsDiff,
resourceFsxLustreFileSystemSchemaCustomizeDiff,
),
}
}

func resourceFsxLustreFileSystemSchemaCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
// we want to force a new resource if the new storage capacity is less than the old one
if d.HasChange("storage_capacity") {
o, n := d.GetChange("storage_capacity")
if n.(int) < o.(int) || d.Get("deployment_type").(string) == fsx.LustreDeploymentTypeScratch1 {
if err := d.ForceNew("storage_capacity"); err != nil {
return err
}
}
}

return nil
}

func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -310,6 +328,11 @@ func resourceAwsFsxLustreFileSystemUpdate(d *schema.ResourceData, meta interface
requestUpdate = true
}

if d.HasChange("storage_capacity") {
input.StorageCapacity = aws.Int64(int64(d.Get("storage_capacity").(int)))
requestUpdate = true
}

if requestUpdate {
_, err := conn.UpdateFileSystem(input)
if err != nil {
Expand Down
53 changes: 53 additions & 0 deletions aws/resource_aws_fsx_lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,49 @@ func TestAccAWSFsxLustreFileSystem_StorageCapacity(t *testing.T) {
})
}

func TestAccAWSFsxLustreFileSystem_StorageCapacityUpdate(t *testing.T) {
var filesystem1, filesystem2, filesystem3 fsx.FileSystem
resourceName := "aws_fsx_lustre_file_system.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckFsxLustreFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxLustreFileSystemConfigStorageCapacityScratch2(7200),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem1),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "7200"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
{
Config: testAccAwsFsxLustreFileSystemConfigStorageCapacityScratch2(1200),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem2),
testAccCheckFsxLustreFileSystemRecreated(&filesystem1, &filesystem2),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "1200"),
),
},
{
Config: testAccAwsFsxLustreFileSystemConfigStorageCapacityScratch2(7200),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem3),
testAccCheckFsxLustreFileSystemNotRecreated(&filesystem2, &filesystem3),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "7200"),
),
},
},
})
}

func TestAccAWSFsxLustreFileSystem_Tags(t *testing.T) {
var filesystem1, filesystem2, filesystem3 fsx.FileSystem
resourceName := "aws_fsx_lustre_file_system.test"
Expand Down Expand Up @@ -926,6 +969,16 @@ resource "aws_fsx_lustre_file_system" "test" {
`, storageCapacity))
}

func testAccAwsFsxLustreFileSystemConfigStorageCapacityScratch2(storageCapacity int) string {
return composeConfig(testAccAwsFsxLustreFileSystemConfigBase(), fmt.Sprintf(`
resource "aws_fsx_lustre_file_system" "test" {
storage_capacity = %[1]d
subnet_ids = [aws_subnet.test1.id]
deployment_type = "SCRATCH_2"
}
`, storageCapacity))
}

func testAccAwsFsxLustreFileSystemConfigSubnetIds1() string {
return composeConfig(testAccAwsFsxLustreFileSystemConfigBase(), `
resource "aws_fsx_lustre_file_system" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/fsx_lustre_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resource "aws_fsx_lustre_file_system" "example" {

The following arguments are supported:

* `storage_capacity` - (Required) The storage capacity (GiB) of the file system. Minimum of `1200`. Storage capacity is provisioned in increments of 3,600 GiB.
* `storage_capacity` - (Required) The storage capacity (GiB) of the file system. Minimum of `1200`. See more details at [Allowed values for Fsx storage capacity](https://docs.aws.amazon.com/fsx/latest/APIReference/API_CreateFileSystem.html#FSx-CreateFileSystem-request-StorageCapacity). Update is allowed only for `SCRATCH_2` and `PERSISTENT_1` deployment types, See more details at [Fsx Storage Capacity Update](https://docs.aws.amazon.com/fsx/latest/APIReference/API_UpdateFileSystem.html#FSx-UpdateFileSystem-request-StorageCapacity).
* `subnet_ids` - (Required) A list of IDs for the subnets that the file system will be accessible from. File systems currently support only one subnet. The file server is also launched in that subnet's Availability Zone.
* `export_path` - (Optional) S3 URI (with optional prefix) where the root of your Amazon FSx file system is exported. Can only be specified with `import_path` argument and the path must use the same Amazon S3 bucket as specified in `import_path`. Set equal to `import_path` to overwrite files on export. Defaults to `s3://{IMPORT BUCKET}/FSxLustre{CREATION TIMESTAMP}`.
* `import_path` - (Optional) S3 URI (with optional prefix) that you're using as the data repository for your FSx for Lustre file system. For example, `s3://example-bucket/optional-prefix/`.
Expand Down

0 comments on commit deccb39

Please sign in to comment.