Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Oct 25, 2023
1 parent 214b9d8 commit e3a5fcf
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 39 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 23.10.0
BUG FIXES:
* resource/aws_fsx: handling for a situation in which the status does not exist yet.
* resources/cifs_server: fix the read function on domain, dns_domain and netbios checking with case insensitive.
* resource/cifs_server: fix the read function on domain, dns_domain and netbios checking with case insensitive.
* resource/volume: add `export_policy_rule_super_user` and `export_policy_rule_access_control` options. Fix export policy update error.

## 23.8.2
BUG FIXES:
Expand Down
194 changes: 166 additions & 28 deletions cloudmanager/resource_netapp_cloudmanager_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceCVOVolume() *schema.Resource {
Optional: true,
},
"export_policy_ip": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -93,6 +93,15 @@ func resourceCVOVolume() *schema.Resource {
Type: schema.TypeString,
},
},
"export_policy_rule_access_control": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"readonly", "readwrite", "none"}, false),
},
"export_policy_rule_super_user": {
Type: schema.TypeBool,
Optional: true,
},
"iops": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -297,6 +306,75 @@ func resourceCVOVolumeCreate(d *schema.ResourceData, meta interface{}) error {
}
}
}
// exmaple of the export policy info in volume creation from the UI timeline. Be aware that it might be out of date as time changes.
// Note that for update, export policy info has different structure.
// "exportPolicyInfo": {
// "policyType": "custom",
// "rules": [
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "0.0.0.0"
// ],
// "index": 1
// }
// ]
// }
if d.HasChange("export_policy_name") || d.HasChange("export_policy_type") || d.HasChange("export_policy_ip") || d.HasChange("export_policy_nfs_version") || d.HasChange("export_policy_rule_access_control") || d.HasChange("export_policy_rule_super_user") {
var exportPolicyTypeOK, exportPolicyIPOK, exportPolicyNfsVersionOK, exportPolicyRuleAccessControlOK, exportPolicyRuleSuperUserOK bool
var nfsVersion, policyIps []string
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, len(v.([]interface{})))
for _, x := range v.([]interface{}) {
ips = append(ips, x.(string))
}
policyIps = ips
exportPolicyIPOK = true
}
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfs := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfs = append(nfs, x.(string))
}
nfsVersion = nfs
exportPolicyNfsVersionOK = true
}
if _, ok := d.GetOk("export_policy_rule_access_control"); ok {
exportPolicyRuleAccessControlOK = true
}
if _, ok := d.GetOkExists("export_policy_rule_super_user"); ok {
exportPolicyRuleSuperUserOK = true
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
exportPolicyTypeOK = true
}
if !exportPolicyTypeOK || !exportPolicyIPOK || !exportPolicyNfsVersionOK || !exportPolicyRuleAccessControlOK || !exportPolicyRuleSuperUserOK {
return fmt.Errorf("export_policy_type, export_policy_ip, export_policy_nfs_version, export_policy_rule_access_control and export_policy_rule_super_user are required for export policy")
}
var rules []ExportPolicyRule
rules = make([]ExportPolicyRule, len(policyIps))
for i, x := range policyIps {
rules[i] = ExportPolicyRule{}
eachRule := make([]string, 1)
eachRule[0] = x
rules[i].Ips = eachRule
rules[i].NfsVersion = nfsVersion
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
rules[i].Index = int32(i + 1)
}
volume.ExportPolicyInfo.Rules = rules
}

response, err := client.quoteVolume(quote, clientID)
if err != nil {
log.Printf("Error quoting volume")
Expand All @@ -313,29 +391,9 @@ func resourceCVOVolumeCreate(d *schema.ResourceData, meta interface{}) error {
volume.Size.Size = d.Get("size").(float64)
volume.Size.Unit = d.Get("unit").(string)
volumeProtocol := d.Get("volume_protocol").(string)
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("comment"); ok {
volume.Comment = v.(string)
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
ips = append(ips, x.(string))
}
volume.ExportPolicyInfo.Ips = ips
}
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfs := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfs = append(nfs, x.(string))
}
volume.ExportPolicyInfo.NfsVersion = nfs
}
if v, ok := d.GetOk("iops"); ok {
volume.Iops = v.(int)
}
Expand Down Expand Up @@ -614,14 +672,94 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
volume := volumeRequest{}
var svm string
volume.Name = d.Get("name").(string)
volume.ExportPolicyInfo.PolicyType = d.Get("export_policy_type").(string)
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
ips = append(ips, x.(string))
if d.HasChange("export_policy_ip") || d.HasChange("export_policy_nfs_version") || d.HasChange("export_policy_rule_super_user") || d.HasChange("export_policy_rule_access_control") {
var exportPolicyTypeOK, exportPolicyIPOK, exportPolicyNfsVersionOK, exportPolicyRuleAccessControlOK, exportPolicyRuleSuperUserOK bool
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfsVersions := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfsVersions = append(nfsVersions, x.(string))
}
volume.ExportPolicyInfo.NfsVersion = nfsVersions
exportPolicyNfsVersionOK = true
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
exportPolicyTypeOK = true
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, len(v.([]interface{})))
for _, x := range v.([]interface{}) {
ips = append(ips, x.(string))
}
volume.ExportPolicyInfo.Ips = ips
exportPolicyIPOK = true
}
if _, ok := d.GetOkExists("export_policy_rule_super_user"); ok {
exportPolicyRuleSuperUserOK = true
}
volume.ExportPolicyInfo.Ips = ips
if _, ok := d.GetOk("export_policy_rule_access_control"); ok {
exportPolicyRuleAccessControlOK = true
}
// example of export poliy info for update.
// "exportPolicyInfo": {
// "ips": [
// "0.0.0.0",
// "0.0.0.1"
// ],
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "policyType": "custom",
// "rules": [
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "10.0.0.0"
// ],
// "index": 1
// },
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "10.0.0.1"
// ],
// "index": 2
// }
// ]
// }
if !exportPolicyTypeOK || !exportPolicyIPOK || !exportPolicyNfsVersionOK || !exportPolicyRuleAccessControlOK || !exportPolicyRuleSuperUserOK {
return fmt.Errorf("export_policy_type, export_policy_ip, export_policy_nfs_version, export_policy_rule_access_control and export_policy_rule_super_user are required for export policy")
}
var rules []ExportPolicyRule
rules = make([]ExportPolicyRule, len(volume.ExportPolicyInfo.Ips))
for i, x := range volume.ExportPolicyInfo.Ips {
rules[i] = ExportPolicyRule{}
eachRule := make([]string, 1)
eachRule[0] = x
rules[i].Ips = eachRule
rules[i].NfsVersion = volume.ExportPolicyInfo.NfsVersion
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
rules[i].Index = int32(i + 1)
}
volume.ExportPolicyInfo.Rules = rules

}

if v, ok := d.GetOk("svm_name"); ok {
svm = v.(string)
}
Expand Down Expand Up @@ -676,7 +814,7 @@ func resourceVolumeCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error
// Check supported modification: Use volume name as an indication to know if this is a creation or modification
if !(diff.HasChange("name")) {
changeableParams := []string{"volume_protocol", "export_policy_type", "export_policy_ip", "export_policy_name", "export_policy_nfs_version",
"share_name", "permission", "users", "tiering_policy", "snapshot_policy_name"}
"share_name", "permission", "users", "tiering_policy", "snapshot_policy_name", "export_policy_rule_access_control", "export_policy_rule_super_user"}
changedKeys := diff.GetChangedKeysPrefix("")
for _, key := range changedKeys {
found := false
Expand Down
41 changes: 32 additions & 9 deletions cloudmanager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type volumeRequest struct {
EnableThinProvisioning bool `structs:"enableThinProvisioning"`
EnableCompression bool `structs:"enableCompression"`
EnableDeduplication bool `structs:"enableDeduplication"`
ExportPolicyInfo exportPolicyInfo `structs:"exportPolicyInfo,omitempty"`
ExportPolicyInfo ExportPolicyInfo `structs:"exportPolicyInfo,omitempty"`
ID string `structs:"uuid"`
NewAggregate bool `structs:"newAggregate"`
CapacityTier string `structs:"capacityTier,omitempty"`
Expand Down Expand Up @@ -53,7 +53,7 @@ type volumeResponse struct {
EnableThinProvisioning bool `json:"thinProvisioning"`
EnableCompression bool `json:"compression"`
EnableDeduplication bool `json:"deduplication"`
ExportPolicyInfo exportPolicyInfoResponse `json:"exportPolicyInfo"`
ExportPolicyInfo ExportPolicyInfoResponse `json:"exportPolicyInfo"`
ID string `json:"uuid"`
CapacityTier string `json:"capacityTier,omitempty"`
TieringPolicy string `json:"tieringPolicy,omitempty"`
Expand All @@ -64,12 +64,35 @@ type volumeResponse struct {
Comment string `json:"comment"`
}

type exportPolicyInfo struct {
Name string `structs:"name,omitempty"`
PolicyType string `structs:"policyType,omitempty"`
Ips []string `structs:"ips,omitempty"`
NfsVersion []string `structs:"nfsVersion,omitempty"`
// Rules exportPolicyRule `structs:"rules,omitempty"`
// ExportPolicyInfo describes the export policy section.
type ExportPolicyInfo struct {
Name string `structs:"name,omitempty"`
PolicyType string `structs:"policyType,omitempty"`
Ips []string `structs:"ips,omitempty"`
NfsVersion []string `structs:"nfsVersion,omitempty"`
Rules []ExportPolicyRule `structs:"rules,omitempty"`
}

// ExportPolicyInfoResponse describes the export policy section in API response.
type ExportPolicyInfoResponse struct {
Name string `json:"name"`
PolicyType string `json:"policyType"`
Ips []string `json:"ips"`
NfsVersion []string `json:"nfsVersion"`
Rules []ExportPolicyRule `json:"rules"`
}

// ExportPolicyRule describes the export policy rule section.
type ExportPolicyRule struct {
// Protocols []string `structs:"protocols"`
// Clients []string `structs:"clients"`
// RoRule []string `structs:"ro_rule"`
// RwRule []string `structs:"rw_rule"`
Superuser bool `structs:"superuser"`
Index int32 `structs:"index,omitempty"`
RuleAccessControl string `structs:"ruleAccessControl"`
Ips []string `structs:"ips"`
NfsVersion []string `structs:"nfsVersion,omitempty"`
}

type exportPolicyInfoResponse struct {
Expand Down Expand Up @@ -103,7 +126,7 @@ type quoteRequest struct {
EnableCompression bool `structs:"enableCompression"`
EnableDeduplication bool `structs:"enableDeduplication"`
ReplicationFlow bool `structs:"replicationFlow"`
ExportPolicyInfo exportPolicyInfo `structs:"exportPolicyInfo,omitempty"`
ExportPolicyInfo ExportPolicyInfo `structs:"exportPolicyInfo,omitempty"`
SnapshotPolicyName string `structs:"snapshotPolicyName"`
Name string `structs:"name"`
CapacityTier string `structs:"capacityTier,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion website/docs/r/volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ resource "netapp-cloudmanager_volume" "cvo-volume-nfs" {
export_policy_type = "custom"
export_policy_ip = ["0.0.0.0/0"]
export_policy_nfs_version = ["nfs4"]
export_policy_rule_access_control = "readwrite"
export_policy_rule_super_user = true
snapshot_policy_name = "sp1"
snapshot_policy {
schedule {
Expand Down Expand Up @@ -121,8 +123,11 @@ The following arguments are supported:
* `capacity_tier` - (Optional) The volume's capacity tier for tiering cold data to object storage: ['S3', 'Blob', 'cloudStorage']. The default values for each cloud provider are as follows: Amazon => 'S3', Azure => 'Blob', GCP => 'cloudStorage'. If none, the capacity tier won't be set on volume creation.
* `export_policy_name` - (Optional) The export policy name. (NFS protocol parameters)
* `export__policy_type` - (Optional) The export policy type. (NFS protocol parameters)
* `export_policy_ip` - (Optional) Custom export policy list of IPs. (NFS protocol parameters)
* `export_policy_ip` - (Optional) Custom export policy list of IPs. Order matters. (NFS protocol parameters)
* `export_policy_nfs_version` - (Optional) Export policy protocol. (NFS protocol parameters)
* `export_policy_rule_access_control` (Optional) Choice of 'readonly', 'readwrite', 'none'. (NFS protocol parameters)
* `export_policy_rule_super_user` - (Optional) Boolean option to sepecify super user or not. (NFS protocol parameters)
`export__policy_type`, `export_policy_ip`, `export_policy_nfs_version`, `export_policy_nfs_version` and `export_policy_rule_super_user` are required together for export policy.
* `snapshot_policy_name` - (Optional) Snapshot policy name. The default is 'default'. (NFS protocol parameters)
* `iops` - (Optional) Provisioned IOPS. Needed only when 'provider_volume_type' is 'io1' or 'gp3'
* `throughput` - (Optional) Required only when 'provider_volume_type' is 'gp3'.
Expand Down

0 comments on commit e3a5fcf

Please sign in to comment.