From e8697fe312bb42ff9e950e0ae0e56338f2c7e455 Mon Sep 17 00:00:00 2001 From: awsaxeman <34073510+awsaxeman@users.noreply.github.com> Date: Fri, 7 Jan 2022 17:24:17 -0500 Subject: [PATCH 1/4] added nil check for nfs exports --- internal/service/fsx/openzfs_file_system.go | 30 ++++---- .../service/fsx/openzfs_file_system_test.go | 71 +++++++++++++++++++ internal/service/fsx/openzfs_volume.go | 30 ++++---- 3 files changed, 107 insertions(+), 24 deletions(-) diff --git a/internal/service/fsx/openzfs_file_system.go b/internal/service/fsx/openzfs_file_system.go index 76af2e2b00c..ef3df85428e 100644 --- a/internal/service/fsx/openzfs_file_system.go +++ b/internal/service/fsx/openzfs_file_system.go @@ -774,9 +774,11 @@ func flattenFsxOpenzfsFileNfsExports(rs []*fsx.OpenZFSNfsExport) []map[string]in exports := make([]map[string]interface{}, 0) for _, export := range rs { - cfg := make(map[string]interface{}) - cfg["client_configurations"] = flattenFsxOpenzfsClientConfigurations(export.ClientConfigurations) - exports = append(exports, cfg) + if export != nil { + cfg := make(map[string]interface{}) + cfg["client_configurations"] = flattenFsxOpenzfsClientConfigurations(export.ClientConfigurations) + exports = append(exports, cfg) + } } if len(exports) > 0 { @@ -790,10 +792,12 @@ func flattenFsxOpenzfsClientConfigurations(rs []*fsx.OpenZFSClientConfiguration) configurations := make([]map[string]interface{}, 0) for _, configuration := range rs { - cfg := make(map[string]interface{}) - cfg["clients"] = aws.StringValue(configuration.Clients) - cfg["options"] = flex.FlattenStringList(configuration.Options) - configurations = append(configurations, cfg) + if configuration != nil { + cfg := make(map[string]interface{}) + cfg["clients"] = aws.StringValue(configuration.Clients) + cfg["options"] = flex.FlattenStringList(configuration.Options) + configurations = append(configurations, cfg) + } } if len(configurations) > 0 { @@ -807,11 +811,13 @@ func flattenFsxOpenzfsFileUserAndGroupQuotas(rs []*fsx.OpenZFSUserOrGroupQuota) quotas := make([]map[string]interface{}, 0) for _, quota := range rs { - cfg := make(map[string]interface{}) - cfg["id"] = aws.Int64Value(quota.Id) - cfg["storage_capacity_quota_gib"] = aws.Int64Value(quota.StorageCapacityQuotaGiB) - cfg["type"] = aws.StringValue(quota.Type) - quotas = append(quotas, cfg) + if quota != nil { + cfg := make(map[string]interface{}) + cfg["id"] = aws.Int64Value(quota.Id) + cfg["storage_capacity_quota_gib"] = aws.Int64Value(quota.StorageCapacityQuotaGiB) + cfg["type"] = aws.StringValue(quota.Type) + quotas = append(quotas, cfg) + } } if len(quotas) > 0 { diff --git a/internal/service/fsx/openzfs_file_system_test.go b/internal/service/fsx/openzfs_file_system_test.go index 82041800b28..8cf718902b6 100644 --- a/internal/service/fsx/openzfs_file_system_test.go +++ b/internal/service/fsx/openzfs_file_system_test.go @@ -237,6 +237,37 @@ func TestAccFSxOpenzfsFileSystem_rootVolume(t *testing.T) { }), ), }, + { + Config: testAccOpenzfsFileSystemRootVolume4Config(rName, "NONE", "false", 128, 1024), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxOpenzfsFileSystemExists(resourceName, &filesystem1), + resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.data_compression_type", "NONE"), + resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.nfs_exports.#", "0"), + resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.read_only", "false"), + resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.#", "4"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "10", + "storage_capacity_quota_gib": "128", + "type": "USER", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "20", + "storage_capacity_quota_gib": "1024", + "type": "GROUP", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "5", + "storage_capacity_quota_gib": "1024", + "type": "GROUP", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "100", + "storage_capacity_quota_gib": "128", + "type": "USER", + }), + ), + }, }, }) } @@ -1059,3 +1090,43 @@ resource "aws_fsx_openzfs_file_system" "test" { } `, rName, dataCompression, readOnly, userQuota, groupQuota)) } + +func testAccOpenzfsFileSystemRootVolume4Config(rName, dataCompression, readOnly string, userQuota, groupQuota int) string { + return acctest.ConfigCompose(testAccOpenzfsFileSystemBaseConfig(rName), fmt.Sprintf(` +resource "aws_fsx_openzfs_file_system" "test" { + storage_capacity = 64 + subnet_ids = [aws_subnet.test1.id] + deployment_type = "SINGLE_AZ_1" + throughput_capacity = 64 + root_volume_configuration { + copy_tags_to_snapshots = true + data_compression_type = %[2]q + + user_and_group_quotas { + id = 10 + storage_capacity_quota_gib = %[4]d + type = "USER" + } + user_and_group_quotas { + id = 20 + storage_capacity_quota_gib = %[5]d + type = "GROUP" + } + user_and_group_quotas { + id = 5 + storage_capacity_quota_gib = %[5]d + type = "GROUP" + } + user_and_group_quotas { + id = 100 + storage_capacity_quota_gib = %[4]d + type = "USER" + } + } + + tags = { + Name = %[1]q + } +} +`, rName, dataCompression, readOnly, userQuota, groupQuota)) +} diff --git a/internal/service/fsx/openzfs_volume.go b/internal/service/fsx/openzfs_volume.go index b82359591d3..b759d55478f 100644 --- a/internal/service/fsx/openzfs_volume.go +++ b/internal/service/fsx/openzfs_volume.go @@ -520,9 +520,11 @@ func flattenFsxOpenzfsVolumeNfsExports(rs []*fsx.OpenZFSNfsExport) []map[string] exports := make([]map[string]interface{}, 0) for _, export := range rs { - cfg := make(map[string]interface{}) - cfg["client_configurations"] = flattenFsxOpenzfsVolumeClientConfigurations(export.ClientConfigurations) - exports = append(exports, cfg) + if export != nil { + cfg := make(map[string]interface{}) + cfg["client_configurations"] = flattenFsxOpenzfsVolumeClientConfigurations(export.ClientConfigurations) + exports = append(exports, cfg) + } } if len(exports) > 0 { @@ -536,10 +538,12 @@ func flattenFsxOpenzfsVolumeClientConfigurations(rs []*fsx.OpenZFSClientConfigur configurations := make([]map[string]interface{}, 0) for _, configuration := range rs { - cfg := make(map[string]interface{}) - cfg["clients"] = aws.StringValue(configuration.Clients) - cfg["options"] = flex.FlattenStringList(configuration.Options) - configurations = append(configurations, cfg) + if configuration != nil { + cfg := make(map[string]interface{}) + cfg["clients"] = aws.StringValue(configuration.Clients) + cfg["options"] = flex.FlattenStringList(configuration.Options) + configurations = append(configurations, cfg) + } } if len(configurations) > 0 { @@ -553,11 +557,13 @@ func flattenFsxOpenzfsVolumeUserAndGroupQuotas(rs []*fsx.OpenZFSUserOrGroupQuota quotas := make([]map[string]interface{}, 0) for _, quota := range rs { - cfg := make(map[string]interface{}) - cfg["id"] = aws.Int64Value(quota.Id) - cfg["storage_capacity_quota_gib"] = aws.Int64Value(quota.StorageCapacityQuotaGiB) - cfg["type"] = aws.StringValue(quota.Type) - quotas = append(quotas, cfg) + if quota != nil { + cfg := make(map[string]interface{}) + cfg["id"] = aws.Int64Value(quota.Id) + cfg["storage_capacity_quota_gib"] = aws.Int64Value(quota.StorageCapacityQuotaGiB) + cfg["type"] = aws.StringValue(quota.Type) + quotas = append(quotas, cfg) + } } if len(quotas) > 0 { From 36628decd8dea6c54e3f766ac8d319ff581f904f Mon Sep 17 00:00:00 2001 From: awsaxeman <34073510+awsaxeman@users.noreply.github.com> Date: Fri, 7 Jan 2022 19:07:58 -0500 Subject: [PATCH 2/4] changlog --- .changelog/22480.txt | 3 ++ internal/service/fsx/openzfs_file_system.go | 1 + .../service/fsx/openzfs_file_system_test.go | 40 +++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 .changelog/22480.txt diff --git a/.changelog/22480.txt b/.changelog/22480.txt new file mode 100644 index 00000000000..8e96afa7bbb --- /dev/null +++ b/.changelog/22480.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_fsx_openzfs_file_system: Fix issue with Null NFS Export when root volume configuraiton specified. +``` \ No newline at end of file diff --git a/internal/service/fsx/openzfs_file_system.go b/internal/service/fsx/openzfs_file_system.go index ef3df85428e..07dc22eba4e 100644 --- a/internal/service/fsx/openzfs_file_system.go +++ b/internal/service/fsx/openzfs_file_system.go @@ -108,6 +108,7 @@ func ResourceOpenzfsFileSystem() *schema.Resource { "copy_tags_to_snapshots": { Type: schema.TypeBool, Optional: true, + ForceNew: true, }, "data_compression_type": { Type: schema.TypeString, diff --git a/internal/service/fsx/openzfs_file_system_test.go b/internal/service/fsx/openzfs_file_system_test.go index 8cf718902b6..3752ecdd665 100644 --- a/internal/service/fsx/openzfs_file_system_test.go +++ b/internal/service/fsx/openzfs_file_system_test.go @@ -1102,26 +1102,26 @@ resource "aws_fsx_openzfs_file_system" "test" { copy_tags_to_snapshots = true data_compression_type = %[2]q - user_and_group_quotas { - id = 10 - storage_capacity_quota_gib = %[4]d - type = "USER" - } - user_and_group_quotas { - id = 20 - storage_capacity_quota_gib = %[5]d - type = "GROUP" - } - user_and_group_quotas { - id = 5 - storage_capacity_quota_gib = %[5]d - type = "GROUP" - } - user_and_group_quotas { - id = 100 - storage_capacity_quota_gib = %[4]d - type = "USER" - } + user_and_group_quotas { + id = 10 + storage_capacity_quota_gib = %[4]d + type = "USER" + } + user_and_group_quotas { + id = 20 + storage_capacity_quota_gib = %[5]d + type = "GROUP" + } + user_and_group_quotas { + id = 5 + storage_capacity_quota_gib = %[5]d + type = "GROUP" + } + user_and_group_quotas { + id = 100 + storage_capacity_quota_gib = %[4]d + type = "USER" + } } tags = { From 7e70618f9bcda2cee1d93207139a3b0a873a0fcd Mon Sep 17 00:00:00 2001 From: awsaxeman <34073510+awsaxeman@users.noreply.github.com> Date: Sun, 9 Jan 2022 18:07:59 -0500 Subject: [PATCH 3/4] changlog --- .changelog/22480.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/22480.txt b/.changelog/22480.txt index 8e96afa7bbb..0b0c4d75b48 100644 --- a/.changelog/22480.txt +++ b/.changelog/22480.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_fsx_openzfs_file_system: Fix issue with Null NFS Export when root volume configuraiton specified. +resource/aws_fsx_openzfs_file_system: Fix issue with Null NFS Export when root volume configuration specified. ``` \ No newline at end of file From e7b74536ff4e47eb086a2b8938d29fb2083e1807 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 10 Jan 2022 13:42:38 -0500 Subject: [PATCH 4/4] Tweak CHANGELOG entries --- .changelog/22480.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.changelog/22480.txt b/.changelog/22480.txt index 0b0c4d75b48..e3e197fc78b 100644 --- a/.changelog/22480.txt +++ b/.changelog/22480.txt @@ -1,3 +1,7 @@ ```release-note:bug -resource/aws_fsx_openzfs_file_system: Fix issue with Null NFS Export when root volume configuration specified. -``` \ No newline at end of file +resource/aws_fsx_openzfs_file_system: Fix crash with nil `root_volume_configuration.nfs_exports` value +``` + +```release-note:bug +resource/aws_fsx_openzfs_file_system: Change `root_volume_configuration.copy_tags_to_snapshots` to ForceNew +```