Skip to content

Commit

Permalink
Fixes for volume creation
Browse files Browse the repository at this point in the history
- Fix for issue NetApp#90
- Fix for issue NetApp#92
  • Loading branch information
okrause committed Mar 19, 2024
1 parent 96d8486 commit 1b3fb7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 11 additions & 11 deletions gcp/resource_netapp_gcp_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions gcp/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit 1b3fb7b

Please sign in to comment.