diff --git a/gcp/resource_netapp_gcp_volume.go b/gcp/resource_netapp_gcp_volume.go index 9d7ba52..ebbca47 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) } @@ -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 @@ -915,7 +916,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..b74cbbc 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, storageClass 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 storageClass != "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)