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

Fixes for volume creation #93

Merged
merged 3 commits into from
Apr 3, 2024
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
23 changes: 12 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 @@ -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
Expand All @@ -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
}
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, storageClass 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 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)
Expand Down