From 73d1bccc50cfdcb0dbd8f7dc31df89e327490763 Mon Sep 17 00:00:00 2001 From: awsaxeman <34073510+awsaxeman@users.noreply.github.com> Date: Tue, 4 Jan 2022 16:28:01 -0500 Subject: [PATCH] user_and_group_quotas to typeset --- internal/service/fsx/openzfs_file_system.go | 10 ++-- .../service/fsx/openzfs_file_system_test.go | 48 ++++++++++++------- internal/service/fsx/openzfs_volume.go | 6 +-- internal/service/fsx/openzfs_volume_test.go | 40 ++++++++++------ 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/internal/service/fsx/openzfs_file_system.go b/internal/service/fsx/openzfs_file_system.go index 9ee07650a7f..76af2e2b00c 100644 --- a/internal/service/fsx/openzfs_file_system.go +++ b/internal/service/fsx/openzfs_file_system.go @@ -156,7 +156,7 @@ func ResourceOpenzfsFileSystem() *schema.Resource { Computed: true, }, "user_and_group_quotas": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Computed: true, MaxItems: 100, @@ -601,8 +601,8 @@ func expandFsxOpenzfsRootVolumeConfiguration(cfg []interface{}) *fsx.OpenZFSCrea out.ReadOnly = aws.Bool(v) } - if v, ok := conf["user_and_group_quotas"].([]interface{}); ok { - out.UserAndGroupQuotas = expandFsxOpenzfsUserAndGroupQuotas(v) + if v, ok := conf["user_and_group_quotas"]; ok { + out.UserAndGroupQuotas = expandFsxOpenzfsUserAndGroupQuotas(v.(*schema.Set).List()) } if v, ok := conf["nfs_exports"].([]interface{}); ok { @@ -629,8 +629,8 @@ func expandFsxOpenzfsUpdateRootVolumeConfiguration(cfg []interface{}) *fsx.Updat out.ReadOnly = aws.Bool(v) } - if v, ok := conf["user_and_group_quotas"].([]interface{}); ok { - out.UserAndGroupQuotas = expandFsxOpenzfsUserAndGroupQuotas(v) + if v, ok := conf["user_and_group_quotas"]; ok { + out.UserAndGroupQuotas = expandFsxOpenzfsUserAndGroupQuotas(v.(*schema.Set).List()) } if v, ok := conf["nfs_exports"].([]interface{}); ok { diff --git a/internal/service/fsx/openzfs_file_system_test.go b/internal/service/fsx/openzfs_file_system_test.go index 9f8a600e806..ba8476d3c38 100644 --- a/internal/service/fsx/openzfs_file_system_test.go +++ b/internal/service/fsx/openzfs_file_system_test.go @@ -149,9 +149,11 @@ func TestAccFSxOpenzfsFileSystem_rootVolume(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.nfs_exports.0.client_configurations.0.options.1", "rw"), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.read_only", "false"), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.#", "1"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.id", "10"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.storage_capacity_quota_gib", "128"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.type", "USER"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "10", + "storage_capacity_quota_gib": "128", + "type": "USER", + }), ), }, { @@ -175,9 +177,11 @@ func TestAccFSxOpenzfsFileSystem_rootVolume(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.nfs_exports.0.client_configurations.0.options.1", "rw"), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.read_only", "true"), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.#", "1"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.id", "10"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.storage_capacity_quota_gib", "256"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.type", "USER"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "root_volume_configuration.0.user_and_group_quotas.*", map[string]string{ + "id": "10", + "storage_capacity_quota_gib": "256", + "type": "USER", + }), ), }, { @@ -201,18 +205,26 @@ func TestAccFSxOpenzfsFileSystem_rootVolume(t *testing.T) { }), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.read_only", "false"), resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.#", "4"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.id", "10"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.storage_capacity_quota_gib", "128"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.0.type", "USER"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.1.id", "20"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.1.storage_capacity_quota_gib", "1024"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.1.type", "GROUP"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.2.id", "5"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.2.storage_capacity_quota_gib", "1024"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.2.type", "GROUP"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.3.id", "100"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.3.storage_capacity_quota_gib", "128"), - resource.TestCheckResourceAttr(resourceName, "root_volume_configuration.0.user_and_group_quotas.3.type", "USER"), + 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", + }), ), }, }, diff --git a/internal/service/fsx/openzfs_volume.go b/internal/service/fsx/openzfs_volume.go index 7639d6c754b..b82359591d3 100644 --- a/internal/service/fsx/openzfs_volume.go +++ b/internal/service/fsx/openzfs_volume.go @@ -141,7 +141,7 @@ func ResourceOpenzfsVolume() *schema.Resource { ValidateFunc: validation.IntBetween(0, 2147483647), }, "user_and_group_quotas": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Computed: true, MaxItems: 100, @@ -222,7 +222,7 @@ func resourceOepnzfsVolumeCreate(d *schema.ResourceData, meta interface{}) error } if v, ok := d.GetOk("user_and_group_quotas"); ok { - input.OpenZFSConfiguration.UserAndGroupQuotas = expandFsxOpenzfsVolumeUserAndGroupQuotas(v.([]interface{})) + input.OpenZFSConfiguration.UserAndGroupQuotas = expandFsxOpenzfsVolumeUserAndGroupQuotas(v.(*schema.Set).List()) } if v, ok := d.GetOk("origin_snapshot"); ok { @@ -366,7 +366,7 @@ func resourceOpenzfsVolumeUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("user_and_group_quotas") { - input.OpenZFSConfiguration.UserAndGroupQuotas = expandFsxOpenzfsVolumeUserAndGroupQuotas(d.Get("user_and_group_quotas").([]interface{})) + input.OpenZFSConfiguration.UserAndGroupQuotas = expandFsxOpenzfsVolumeUserAndGroupQuotas(d.Get("user_and_group_quotas").(*schema.Set).List()) } _, err := conn.UpdateVolume(input) diff --git a/internal/service/fsx/openzfs_volume_test.go b/internal/service/fsx/openzfs_volume_test.go index ad106bb3e47..64902ecd345 100644 --- a/internal/service/fsx/openzfs_volume_test.go +++ b/internal/service/fsx/openzfs_volume_test.go @@ -384,9 +384,11 @@ func TestAccFSxOpenzfsVolume_userAndGroupQuotas(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFsxOpenzfsVolumeExists(resourceName, &volume1), resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.#", "1"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.id", "10"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.storage_capacity_quota_gib", "256"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.type", "USER"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user_and_group_quotas.*", map[string]string{ + "id": "10", + "storage_capacity_quota_gib": "256", + "type": "USER", + }), ), }, { @@ -400,18 +402,26 @@ func TestAccFSxOpenzfsVolume_userAndGroupQuotas(t *testing.T) { testAccCheckFsxOpenzfsVolumeExists(resourceName, &volume2), testAccCheckFsxOpenzfsVolumeNotRecreated(&volume1, &volume2), resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.#", "4"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.id", "10"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.storage_capacity_quota_gib", "128"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.0.type", "USER"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.1.id", "20"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.1.storage_capacity_quota_gib", "1024"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.1.type", "GROUP"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.2.id", "5"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.2.storage_capacity_quota_gib", "1024"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.2.type", "GROUP"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.3.id", "100"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.3.storage_capacity_quota_gib", "128"), - resource.TestCheckResourceAttr(resourceName, "user_and_group_quotas.3.type", "USER"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user_and_group_quotas.*", map[string]string{ + "id": "10", + "storage_capacity_quota_gib": "128", + "type": "USER", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user_and_group_quotas.*", map[string]string{ + "id": "20", + "storage_capacity_quota_gib": "1024", + "type": "GROUP", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user_and_group_quotas.*", map[string]string{ + "id": "5", + "storage_capacity_quota_gib": "1024", + "type": "GROUP", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user_and_group_quotas.*", map[string]string{ + "id": "100", + "storage_capacity_quota_gib": "128", + "type": "USER", + }), ), }, },