Skip to content

Commit

Permalink
user_and_group_quotas to typeset
Browse files Browse the repository at this point in the history
  • Loading branch information
awsaxeman committed Jan 4, 2022
1 parent 00f8cad commit 73d1bcc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
10 changes: 5 additions & 5 deletions internal/service/fsx/openzfs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
48 changes: 30 additions & 18 deletions internal/service/fsx/openzfs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
),
},
{
Expand All @@ -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",
}),
),
},
{
Expand All @@ -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",
}),
),
},
},
Expand Down
6 changes: 3 additions & 3 deletions internal/service/fsx/openzfs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 25 additions & 15 deletions internal/service/fsx/openzfs_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
),
},
{
Expand All @@ -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",
}),
),
},
},
Expand Down

0 comments on commit 73d1bcc

Please sign in to comment.