Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added nil check for nfs exports #22480

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/22480.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
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
```
31 changes: 19 additions & 12 deletions internal/service/fsx/openzfs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -774,9 +775,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 {
Expand All @@ -790,10 +793,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 {
Expand All @@ -807,11 +812,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 {
Expand Down
71 changes: 71 additions & 0 deletions internal/service/fsx/openzfs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
),
},
},
})
}
Expand Down Expand Up @@ -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))
}
30 changes: 18 additions & 12 deletions internal/service/fsx/openzfs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down