From 152cfefa89da09755c568278555fb23a4e05442a Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 19 Sep 2020 14:07:24 +0300 Subject: [PATCH 1/6] add support for `auto_import_policy` --- aws/resource_aws_fsx_lustre_file_system.go | 30 +++++++++---- ...esource_aws_fsx_lustre_file_system_test.go | 44 +++++++++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index a864da8a285..bb8c377efc8 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -115,15 +115,11 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource { ), }, "deployment_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: fsx.LustreDeploymentTypeScratch1, - ValidateFunc: validation.StringInSlice([]string{ - fsx.LustreDeploymentTypeScratch1, - fsx.LustreDeploymentTypeScratch2, - fsx.LustreDeploymentTypePersistent1, - }, false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: fsx.LustreDeploymentTypeScratch1, + ValidateFunc: validation.StringInSlice(fsx.LustreDeploymentType_Values(), false), }, "kms_key_id": { Type: schema.TypeString, @@ -172,6 +168,12 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice(fsx.DriveCacheType_Values(), false), }, + "auto_import_policy": { + Type: schema.TypeString, + Optional: true, + Default: fsx.AutoImportPolicyTypeNone, + ValidateFunc: validation.StringInSlice(fsx.LustreDeploymentType_Values(), false), + }, }, } } @@ -235,6 +237,10 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface input.LustreConfiguration.DriveCacheType = aws.String(v.(string)) } + if v, ok := d.GetOk("auto_import_policy"); ok { + input.LustreConfiguration.AutoImportPolicy = aws.String(v.(string)) + } + result, err := conn.CreateFileSystem(input) if err != nil { return fmt.Errorf("Error creating FSx Lustre filesystem: %w", err) @@ -284,6 +290,11 @@ func resourceAwsFsxLustreFileSystemUpdate(d *schema.ResourceData, meta interface requestUpdate = true } + if d.HasChange("auto_import_policy") { + input.LustreConfiguration.AutoImportPolicy = aws.String(d.Get("auto_import_policy").(string)) + requestUpdate = true + } + if requestUpdate { _, err := conn.UpdateFileSystem(input) if err != nil { @@ -341,6 +352,7 @@ func resourceAwsFsxLustreFileSystemRead(d *schema.ResourceData, meta interface{} d.Set("dns_name", filesystem.DNSName) d.Set("export_path", lustreConfig.DataRepositoryConfiguration.ExportPath) d.Set("import_path", lustreConfig.DataRepositoryConfiguration.ImportPath) + d.Set("auto_import_policy", lustreConfig.DataRepositoryConfiguration.AutoImportPolicy) d.Set("imported_file_chunk_size", lustreConfig.DataRepositoryConfiguration.ImportedFileChunkSize) d.Set("deployment_type", lustreConfig.DeploymentType) if lustreConfig.PerUnitStorageThroughput != nil { diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index 18b0297702f..70792a74503 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -98,6 +98,7 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypeScratch1), resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"), resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd), + resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NONE"), ), }, { @@ -617,6 +618,39 @@ func TestAccAWSFsxLustreFileSystem_StorageTypeHddDriveCacheNone(t *testing.T) { }) } +func TestAccAWSFsxLustreFileSystem_autoImportPolicy(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: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig("NEW"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem), + resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NEW"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"security_group_ids"}, + }, + { + Config: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig("NEW_CHANGED"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem), + resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NEW_CHANGED"), + ), + }, + }, + }) +} + func testAccCheckFsxLustreFileSystemExists(resourceName string, fs *fsx.FileSystem) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -981,3 +1015,13 @@ resource "aws_fsx_lustre_file_system" "test" { } `, drive_cache_type) } + +func testAccAwsFsxLustreFileSystemAutoImportPolicyConfig(policy string) string { + return testAccAwsFsxLustreFileSystemConfigBase() + fmt.Sprintf(` +resource "aws_fsx_lustre_file_system" "test" { + storage_capacity = 1200 + subnet_ids = [aws_subnet.test1.id] + auto_import_policy = %[1]q +} +`, policy) +} From c4dc0e7aa225d6f9fa22f182e95f38446425ae6f Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 19 Sep 2020 15:58:22 +0300 Subject: [PATCH 2/6] add computed, remove default value. fix tests --- aws/resource_aws_fsx_lustre_file_system.go | 4 ++-- ...esource_aws_fsx_lustre_file_system_test.go | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index bb8c377efc8..87576f8d457 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -171,8 +171,8 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource { "auto_import_policy": { Type: schema.TypeString, Optional: true, - Default: fsx.AutoImportPolicyTypeNone, - ValidateFunc: validation.StringInSlice(fsx.LustreDeploymentType_Values(), false), + Computed: true, + ValidateFunc: validation.StringInSlice(fsx.AutoImportPolicyType_Values(), false), }, }, } diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index 70792a74503..d5242ace54c 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -151,6 +151,7 @@ func TestAccAWSFsxLustreFileSystem_ExportPath(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem1), resource.TestCheckResourceAttr(resourceName, "export_path", fmt.Sprintf("s3://%s", rName)), + resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NONE"), ), }, { @@ -165,6 +166,7 @@ func TestAccAWSFsxLustreFileSystem_ExportPath(t *testing.T) { testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem2), testAccCheckFsxLustreFileSystemRecreated(&filesystem1, &filesystem2), resource.TestCheckResourceAttr(resourceName, "export_path", fmt.Sprintf("s3://%s/prefix/", rName)), + resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NONE"), ), }, }, @@ -621,6 +623,7 @@ func TestAccAWSFsxLustreFileSystem_StorageTypeHddDriveCacheNone(t *testing.T) { func TestAccAWSFsxLustreFileSystem_autoImportPolicy(t *testing.T) { var filesystem fsx.FileSystem resourceName := "aws_fsx_lustre_file_system.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -628,7 +631,7 @@ func TestAccAWSFsxLustreFileSystem_autoImportPolicy(t *testing.T) { CheckDestroy: testAccCheckFsxLustreFileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig("NEW"), + Config: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig(rName, "", "NEW"), Check: resource.ComposeTestCheckFunc( testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem), resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NEW"), @@ -641,7 +644,7 @@ func TestAccAWSFsxLustreFileSystem_autoImportPolicy(t *testing.T) { ImportStateVerifyIgnore: []string{"security_group_ids"}, }, { - Config: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig("NEW_CHANGED"), + Config: testAccAwsFsxLustreFileSystemAutoImportPolicyConfig(rName, "", "NEW_CHANGED"), Check: resource.ComposeTestCheckFunc( testAccCheckFsxLustreFileSystemExists(resourceName, &filesystem), resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NEW_CHANGED"), @@ -1016,12 +1019,19 @@ resource "aws_fsx_lustre_file_system" "test" { `, drive_cache_type) } -func testAccAwsFsxLustreFileSystemAutoImportPolicyConfig(policy string) string { +func testAccAwsFsxLustreFileSystemAutoImportPolicyConfig(rName, exportPrefix, policy string) string { return testAccAwsFsxLustreFileSystemConfigBase() + fmt.Sprintf(` +resource "aws_s3_bucket" "test" { + acl = "private" + bucket = %[1]q +} + resource "aws_fsx_lustre_file_system" "test" { + export_path = "s3://${aws_s3_bucket.test.bucket}%[2]s" + import_path = "s3://${aws_s3_bucket.test.bucket}" + auto_import_policy = %[3]q storage_capacity = 1200 subnet_ids = [aws_subnet.test1.id] - auto_import_policy = %[1]q } -`, policy) +`, rName, exportPrefix, policy) } From f1a00dca65a451ba3aa62f2dbacc81f5e56c44b2 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 19 Sep 2020 16:00:33 +0300 Subject: [PATCH 3/6] docs --- website/docs/r/fsx_lustre_file_system.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/fsx_lustre_file_system.html.markdown b/website/docs/r/fsx_lustre_file_system.html.markdown index 18d18a81e3d..754d26a5a32 100644 --- a/website/docs/r/fsx_lustre_file_system.html.markdown +++ b/website/docs/r/fsx_lustre_file_system.html.markdown @@ -39,6 +39,7 @@ The following arguments are supported: * `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`. * `daily_automatic_backup_start_time` - (Optional) A recurring daily time, in the format HH:MM. HH is the zero-padded hour of the day (0-23), and MM is the zero-padded minute of the hour. For example, 05:00 specifies 5 AM daily. only valid for `PERSISTENT_1` deployment_type. Requires `automatic_backup_retention_days` to be set. +* `auto_import_policy` - (Optional) How Amazon FSx keeps your file and directory listings up to date as you add or modify objects in your linked S3 bucket. see [Auto Import Data Repo](https://docs.aws.amazon.com/fsx/latest/LustreGuide/autoimport-data-repo.html) for more details. ## Attributes Reference From d51cee6d63b84adb883499edd531666dfa59392f Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Mon, 21 Sep 2020 19:06:12 +0300 Subject: [PATCH 4/6] add requiredwith for import path --- aws/resource_aws_fsx_lustre_file_system.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index 87576f8d457..3adcd3dc065 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -56,6 +56,7 @@ func resourceAwsFsxLustreFileSystem() *schema.Resource { validation.StringLenBetween(3, 900), validation.StringMatch(regexp.MustCompile(`^s3://`), "must begin with s3://"), ), + RequiredWith: []string{"auto_import_policy"}, }, "imported_file_chunk_size": { Type: schema.TypeInt, From e1effbb9799b79dcf0d34fe386a0ea6fcfb5448c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 1 Oct 2020 02:24:08 +0300 Subject: [PATCH 5/6] add precheck --- aws/resource_aws_fsx_lustre_file_system_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index d5242ace54c..a8d2fa3f482 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -626,7 +626,7 @@ func TestAccAWSFsxLustreFileSystem_autoImportPolicy(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck("fsx", t) }, Providers: testAccProviders, CheckDestroy: testAccCheckFsxLustreFileSystemDestroy, Steps: []resource.TestStep{ From fae0167661c0a3c3759725c891f4164f47226a5c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 1 Oct 2020 20:14:12 +0300 Subject: [PATCH 6/6] remove test --- aws/resource_aws_fsx_lustre_file_system_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index a8d2fa3f482..6e9f6c3000f 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -98,7 +98,6 @@ func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypeScratch1), resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"), resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd), - resource.TestCheckResourceAttr(resourceName, "auto_import_policy", "NONE"), ), }, {