From 1b3fb7bfee30c7e38e5b7b53311ce1736c19fc29 Mon Sep 17 00:00:00 2001 From: Oliver Krause <3621164+okrause@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:18:20 +0100 Subject: [PATCH 1/3] Fixes for volume creation - Fix for issue #90 - Fix for issue #92 --- gcp/resource_netapp_gcp_volume.go | 22 +++++++++++----------- gcp/volume.go | 8 +++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gcp/resource_netapp_gcp_volume.go b/gcp/resource_netapp_gcp_volume.go index 9d7ba52..6a24215 100644 --- a/gcp/resource_netapp_gcp_volume.go +++ b/gcp/resource_netapp_gcp_volume.go @@ -431,10 +431,14 @@ func resourceGCPVolumeCreate(d *schema.ResourceData, meta interface{}) error { volType = "Volumes" } + if v, ok := d.GetOk("storage_class"); ok { + volume.StorageClass = v.(string) + } + if v, ok := d.GetOk("export_policy"); ok { policy := v.(*schema.Set) if policy.Len() > 0 { - resp, err := expandExportPolicy(policy) + resp, err := expandExportPolicy(policy, volume.StorageClass) if err != nil { return err } @@ -450,10 +454,6 @@ func resourceGCPVolumeCreate(d *schema.ResourceData, meta interface{}) error { volume.Zone = v.(string) } - if v, ok := d.GetOk("storage_class"); ok { - volume.StorageClass = v.(string) - } - if v, ok := d.GetOk("regional_ha"); ok { volume.RegionalHA = v.(bool) } @@ -718,6 +718,11 @@ func resourceGCPVolumeRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("region", res.Region); err != nil { return fmt.Errorf("Error reading volume region: %s", err) } + if _, ok := d.GetOk("storage_class"); ok { + if err := d.Set("storage_class", res.StorageClass); err != nil { + return fmt.Errorf("Error reading volume storage_class: %s", err) + } + } snapshotPolicy := flattenSnapshotPolicy(res.SnapshotPolicy) exportPolicy := flattenExportPolicy(res.ExportPolicy) if err := d.Set("snapshot_policy", snapshotPolicy); err != nil { @@ -742,11 +747,6 @@ func resourceGCPVolumeRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error reading volume zone: %s", err) } } - if _, ok := d.GetOk("storage_class"); ok { - if err := d.Set("storage_class", res.StorageClass); err != nil { - return fmt.Errorf("Error reading volume storage_class: %s", err) - } - } if err := d.Set("snapshot_directory", res.SnapshotDirectory); err != nil { return fmt.Errorf("Error reading volume snapshot_directory: %s", err) } @@ -915,7 +915,7 @@ func resourceGCPVolumeUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("export_policy") { policy := d.Get("export_policy").(*schema.Set) - resp, err := expandExportPolicy(policy) + resp, err := expandExportPolicy(policy, volume.StorageClass) if err != nil { return err } diff --git a/gcp/volume.go b/gcp/volume.go index 90afffa..52f0942 100644 --- a/gcp/volume.go +++ b/gcp/volume.go @@ -130,7 +130,7 @@ type apiResponseCodeMessage struct { type simpleExportPolicyRule struct { Access string `structs:"access"` AllowedClients string `structs:"allowedClients"` - HasRootAccess string `structs:"hasRootAccess"` + HasRootAccess string `structs:"hasRootAccess,omitempty"` Kerberos5ReadOnly checked `structs:"kerberos5ReadOnly"` Kerberos5ReadWrite checked `structs:"kerberos5ReadWrite"` Kerberos5iReadOnly checked `structs:"kerberos5iReadOnly"` @@ -657,7 +657,7 @@ func flattenExportPolicy(v exportPolicy) interface{} { } // expandExportPolicy converts set to exportPolicy struct -func expandExportPolicy(set *schema.Set) (exportPolicy, error) { +func expandExportPolicy(set *schema.Set, storage_class string) (exportPolicy, error) { exportPolicyObj := exportPolicy{} for _, v := range set.List() { @@ -669,7 +669,9 @@ func expandExportPolicy(set *schema.Set) (exportPolicy, error) { ruleConfig := x.(map[string]interface{}) exportPolicyRule.Access = ruleConfig["access"].(string) exportPolicyRule.AllowedClients = ruleConfig["allowed_clients"].(string) - exportPolicyRule.HasRootAccess = ruleConfig["has_root_access"].(string) + if storage_class != "software" { + exportPolicyRule.HasRootAccess = ruleConfig["has_root_access"].(string) + } exportPolicyRule.Kerberos5ReadOnly.Checked = ruleConfig["kerberos5_readonly"].(bool) exportPolicyRule.Kerberos5ReadWrite.Checked = ruleConfig["kerberos5_readwrite"].(bool) exportPolicyRule.Kerberos5iReadOnly.Checked = ruleConfig["kerberos5i_readonly"].(bool) From ca42b1f654e8744510d92d38dc373d2332076fab Mon Sep 17 00:00:00 2001 From: Oliver Krause <3621164+okrause@users.noreply.github.com> Date: Wed, 20 Mar 2024 10:14:39 +0100 Subject: [PATCH 2/3] Fix updates for CVS-Software volumes --- gcp/resource_netapp_gcp_volume.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gcp/resource_netapp_gcp_volume.go b/gcp/resource_netapp_gcp_volume.go index 6a24215..ebbca47 100644 --- a/gcp/resource_netapp_gcp_volume.go +++ b/gcp/resource_netapp_gcp_volume.go @@ -892,6 +892,7 @@ func resourceGCPVolumeUpdate(d *schema.ResourceData, meta interface{}) error { // size is always required. volume.Size = d.Get("size").(int) * GiBToBytes volume.SnapshotDirectory = d.Get("snapshot_directory").(bool) + volume.StorageClass = d.Get("storage_class").(string) if d.HasChange("name") { makechange = 1 From dff38d2d62fef9ca59891cc2404d0297b22c9ac3 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 3 Apr 2024 14:20:09 -0700 Subject: [PATCH 3/3] Update volume.go --- gcp/volume.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcp/volume.go b/gcp/volume.go index 52f0942..b74cbbc 100644 --- a/gcp/volume.go +++ b/gcp/volume.go @@ -657,7 +657,7 @@ func flattenExportPolicy(v exportPolicy) interface{} { } // expandExportPolicy converts set to exportPolicy struct -func expandExportPolicy(set *schema.Set, storage_class string) (exportPolicy, error) { +func expandExportPolicy(set *schema.Set, storageClass string) (exportPolicy, error) { exportPolicyObj := exportPolicy{} for _, v := range set.List() { @@ -669,7 +669,7 @@ func expandExportPolicy(set *schema.Set, storage_class string) (exportPolicy, er ruleConfig := x.(map[string]interface{}) exportPolicyRule.Access = ruleConfig["access"].(string) exportPolicyRule.AllowedClients = ruleConfig["allowed_clients"].(string) - if storage_class != "software" { + if storageClass != "software" { exportPolicyRule.HasRootAccess = ruleConfig["has_root_access"].(string) } exportPolicyRule.Kerberos5ReadOnly.Checked = ruleConfig["kerberos5_readonly"].(bool)