Skip to content

Commit db158fa

Browse files
authored
Merge pull request #216 from NetApp/integration/main
Sync Bitbucket and Github
2 parents 6af4d8e + 060c4dd commit db158fa

File tree

5 files changed

+278
-83
lines changed

5 files changed

+278
-83
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 25.3.0
2+
NEW FEATURES:
3+
* resource/volume supports import.
4+
5+
BUG FIXES:
6+
* resource/volume: Fixed an issue where `export_policy_rule_super_user` was incorrectly updated to `none` regardless of the specified value.
7+
* resource/volume: Fixed incorrect references to parameters in documentation.
8+
19
## 25.2.0
210
NEW FEATURES:
311
* resource/cvo supports Restricted mode for GCP.

cloudmanager/resource_netapp_cloudmanager_volume.go

Lines changed: 192 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func resourceCVOVolume() *schema.Resource {
1818
Exists: resourceCVOVolumeExists,
1919
Update: resourceCVOVolumeUpdate,
2020
Importer: &schema.ResourceImporter{
21-
State: schema.ImportStatePassthrough,
21+
State: resourceVolumeImport,
2222
},
2323
CustomizeDiff: resourceVolumeCustomizeDiff,
2424
Schema: map[string]*schema.Schema{
@@ -389,7 +389,7 @@ func resourceCVOVolumeCreate(d *schema.ResourceData, meta interface{}) error {
389389
eachRule[0] = x
390390
rules[i].Ips = eachRule
391391
rules[i].NfsVersion = nfsVersion
392-
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
392+
rules[i].SuperUser = d.Get("export_policy_rule_super_user").(bool)
393393
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
394394
rules[i].Index = int32(i + 1)
395395
}
@@ -544,91 +544,154 @@ func resourceCVOVolumeRead(d *schema.ResourceData, meta interface{}) error {
544544
}
545545
}
546546
volume.SvmName = svm
547-
res, err := client.getVolume(volume, clientID, isSaas, connectorIP)
548-
if err != nil {
549-
log.Print("Error reading volume")
550-
return err
547+
548+
importing := false
549+
if strings.Contains(d.Id(), ",") {
550+
importing = true
551551
}
552-
for _, volume := range res {
553-
if volume.ID == d.Id() {
554-
log.Printf("### Fetching volume: %#v", volume)
555-
if _, ok := d.GetOk("aggregate_name"); ok {
556-
d.Set("aggregate_name", volume.AggregateName)
557-
}
558-
if _, ok := d.GetOk("snapshot_policy_name"); ok {
559-
d.Set("snapshot_policy_name", volume.SnapshotPolicyName)
560-
}
561-
if _, ok := d.GetOk("enable_thin_provisioning"); ok {
562-
d.Set("enable_thin_provisioning", volume.EnableThinProvisioning)
563-
}
564-
// setting this two in create are not working right now.
565-
// if _, ok := d.GetOk("enable_deduplication"); ok {
566-
// d.Set("enable_deduplication", volume.EnableDeduplication)
567-
// }
568-
// if _, ok := d.GetOk("enable_compression"); ok {
569-
// d.Set("enable_compression", volume.EnableCompression)
570-
// }
571-
if _, ok := d.GetOk("export_policy_ip"); ok {
572-
d.Set("export_policy_ip", volume.ExportPolicyInfo.Ips)
573-
}
574-
if _, ok := d.GetOk("export_policy_nfs_version"); ok {
575-
d.Set("export_policy_nfs_version", volume.ExportPolicyInfo.NfsVersion)
576-
}
577-
if _, ok := d.GetOk("export_policy_type"); ok {
578-
d.Set("export_policy_type", volume.ExportPolicyInfo.PolicyType)
579-
}
580-
if v, ok := d.GetOk("provider_volume_type"); ok {
581-
d.Set("provider_volume_type", v.(string))
552+
553+
if d.Id() != "" && !importing {
554+
volume.ID = d.Id()
555+
volume, err := client.getVolumeByID(volume, clientID, isSaas, connectorIP)
556+
if err != nil {
557+
log.Print("Error reading volume")
558+
return err
559+
}
560+
log.Printf("### Fetching volume: %#v", volume)
561+
if _, ok := d.GetOk("aggregate_name"); ok {
562+
d.Set("aggregate_name", volume.AggregateName)
563+
}
564+
if _, ok := d.GetOk("snapshot_policy_name"); ok {
565+
d.Set("snapshot_policy_name", volume.SnapshotPolicyName)
566+
}
567+
if _, ok := d.GetOk("enable_thin_provisioning"); ok {
568+
d.Set("enable_thin_provisioning", volume.EnableThinProvisioning)
569+
}
570+
// setting this two in create are not working right now.
571+
// if _, ok := d.GetOk("enable_deduplication"); ok {
572+
// d.Set("enable_deduplication", volume.EnableDeduplication)
573+
// }
574+
// if _, ok := d.GetOk("enable_compression"); ok {
575+
// d.Set("enable_compression", volume.EnableCompression)
576+
// }
577+
if _, ok := d.GetOk("export_policy_ip"); ok {
578+
d.Set("export_policy_ip", volume.ExportPolicyInfo.Ips)
579+
}
580+
if _, ok := d.GetOk("export_policy_nfs_version"); ok {
581+
d.Set("export_policy_nfs_version", volume.ExportPolicyInfo.NfsVersion)
582+
}
583+
if _, ok := d.GetOk("export_policy_type"); ok {
584+
d.Set("export_policy_type", volume.ExportPolicyInfo.PolicyType)
585+
}
586+
if v, ok := d.GetOk("provider_volume_type"); ok {
587+
d.Set("provider_volume_type", v.(string))
588+
}
589+
if _, ok := d.GetOk("comment"); ok {
590+
d.Set("comment", volume.Comment)
591+
}
592+
if v, ok := d.GetOk("capacity_tier"); ok {
593+
if v.(string) != "none" {
594+
d.Set("capacity_tier", volume.CapacityTier)
595+
if v, ok = d.GetOk("tiering_policy"); ok {
596+
if v.(string) != "none" {
597+
d.Set("tiering_policy", volume.TieringPolicy)
598+
}
599+
}
582600
}
583-
if _, ok := d.GetOk("comment"); ok {
584-
d.Set("comment", volume.Comment)
601+
}
602+
if _, ok := d.GetOk("export_policy_name"); ok {
603+
d.Set("export_policy_name", volume.ExportPolicyInfo.Name)
604+
}
605+
if d.Get("unit") != "GB" {
606+
d.Set("size", convertSizeUnit(volume.Size.Size, volume.Size.Unit, d.Get("unit").(string)))
607+
d.Set("unit", d.Get("unit").(string))
608+
} else {
609+
d.Set("size", volume.Size.Size)
610+
d.Set("unit", volume.Size.Unit)
611+
}
612+
if d.Get("volume_protocol") == "cifs" {
613+
if _, ok := d.GetOk("share_name"); ok {
614+
if len(volume.ShareInfo) > 0 {
615+
d.Set("share_name", volume.ShareInfo[0].ShareName)
616+
}
585617
}
586-
if v, ok := d.GetOk("capacity_tier"); ok {
587-
if v.(string) != "none" {
588-
d.Set("capacity_tier", volume.CapacityTier)
589-
if v, ok = d.GetOk("tiering_policy"); ok {
590-
if v.(string) != "none" {
591-
d.Set("tiering_policy", volume.TieringPolicy)
592-
}
618+
if _, ok := d.GetOk("permission"); ok {
619+
if len(volume.ShareInfo) > 0 {
620+
if len(volume.ShareInfo[0].AccessControlList) > 0 {
621+
d.Set("permission", volume.ShareInfo[0].AccessControlList[0].Permission)
593622
}
594623
}
595624
}
596-
if _, ok := d.GetOk("export_policy_name"); ok {
597-
d.Set("export_policy_name", volume.ExportPolicyInfo.Name)
625+
if _, ok := d.GetOk("users"); ok {
626+
if len(volume.ShareInfo) > 0 {
627+
if len(volume.ShareInfo[0].AccessControlList) > 0 {
628+
d.Set("users", volume.ShareInfo[0].AccessControlList[0].Users)
629+
}
630+
}
598631
}
599-
if d.Get("unit") != "GB" {
600-
d.Set("size", convertSizeUnit(volume.Size.Size, volume.Size.Unit, d.Get("unit").(string)))
601-
d.Set("unit", d.Get("unit").(string))
602-
} else {
603-
d.Set("size", volume.Size.Size)
604-
d.Set("unit", volume.Size.Unit)
632+
}
633+
} else {
634+
res, err := client.getVolume(volume, clientID, isSaas, connectorIP)
635+
if err != nil {
636+
log.Print("Error reading volume")
637+
return err
638+
}
639+
volFound := false
640+
var volume volumeResponse
641+
for _, vol := range res {
642+
if vol.Name == d.Get("name") {
643+
volFound = true
644+
volume = vol
645+
break
605646
}
606-
if d.Get("volume_protocol") == "cifs" {
607-
if _, ok := d.GetOk("share_name"); ok {
608-
if len(volume.ShareInfo) > 0 {
609-
d.Set("share_name", volume.ShareInfo[0].ShareName)
610-
}
647+
}
648+
if !volFound {
649+
return fmt.Errorf("error reading volume: volume doesn't exist")
650+
}
651+
652+
log.Printf("### Fetching volume: %#v", volume)
653+
if d.Get("volume_protocol") == "cifs" {
654+
if _, ok := d.GetOk("share_name"); ok {
655+
if len(volume.ShareInfo) > 0 {
656+
d.Set("share_name", volume.ShareInfo[0].ShareName)
611657
}
612-
if _, ok := d.GetOk("permission"); ok {
613-
if len(volume.ShareInfo) > 0 {
614-
if len(volume.ShareInfo[0].AccessControlList) > 0 {
615-
d.Set("permission", volume.ShareInfo[0].AccessControlList[0].Permission)
616-
}
658+
}
659+
if _, ok := d.GetOk("permission"); ok {
660+
if len(volume.ShareInfo) > 0 {
661+
if len(volume.ShareInfo[0].AccessControlList) > 0 {
662+
d.Set("permission", volume.ShareInfo[0].AccessControlList[0].Permission)
617663
}
618664
}
619-
if _, ok := d.GetOk("users"); ok {
620-
if len(volume.ShareInfo) > 0 {
621-
if len(volume.ShareInfo[0].AccessControlList) > 0 {
622-
d.Set("users", volume.ShareInfo[0].AccessControlList[0].Users)
623-
}
665+
}
666+
if _, ok := d.GetOk("users"); ok {
667+
if len(volume.ShareInfo) > 0 {
668+
if len(volume.ShareInfo[0].AccessControlList) > 0 {
669+
d.Set("users", volume.ShareInfo[0].AccessControlList[0].Users)
624670
}
625671
}
626672
}
627-
return nil
628673
}
674+
675+
d.Set("aggregate_name", volume.AggregateName)
676+
d.Set("export_policy_nfs_version", volume.ExportPolicyInfo.NfsVersion)
677+
d.Set("export_policy_type", volume.ExportPolicyInfo.PolicyType)
678+
d.Set("provider_volume_type", volume.ProviderVolumeType)
679+
d.Set("comment", volume.Comment)
680+
d.Set("export_policy_name", volume.ExportPolicyInfo.Name)
681+
d.Set("size", volume.Size.Size)
682+
d.Set("unit", volume.Size.Unit)
683+
d.Set("working_environment_id", weInfo.PublicID)
684+
d.Set("name", volume.Name)
685+
d.Set("svm_name", volume.SvmName)
686+
d.Set("enable_deduplication", volume.EnableDeduplication)
687+
d.Set("enable_compression", volume.EnableCompression)
688+
d.Set("tiering_policy", volume.TieringPolicy)
689+
d.Set("snapshot_policy_name", volume.SnapshotPolicyName)
690+
d.Set("capacity_tier", volume.CapacityTier)
629691
}
630692

631-
return fmt.Errorf("error reading volume: volume doesn't exist")
693+
return nil
694+
632695
}
633696

634697
func resourceCVOVolumeDelete(d *schema.ResourceData, meta interface{}) error {
@@ -697,16 +760,39 @@ func resourceCVOVolumeExists(d *schema.ResourceData, meta interface{}) (bool, er
697760
volume.WorkingEnvironmentID = weInfo.PublicID
698761
volume.WorkingEnvironmentType = weInfo.WorkingEnvironmentType
699762

700-
res, err := client.getVolumeByID(volume, clientID, isSaas, connectorIP)
701-
if err != nil {
702-
log.Print("Error reading volume")
703-
return false, err
763+
importing := false
764+
if strings.Contains(d.Id(), ",") {
765+
importing = true
704766
}
705-
706-
if res.ID != d.Id() {
707-
d.SetId("")
708-
return false, nil
767+
if d.Id() != "" && !importing {
768+
res, err := client.getVolumeByID(volume, clientID, isSaas, connectorIP)
769+
if err != nil {
770+
log.Print("Error reading volume")
771+
return false, err
772+
}
773+
if res.ID != d.Id() {
774+
d.SetId("")
775+
return false, nil
776+
}
777+
} else {
778+
res, err := client.getVolume(volume, clientID, isSaas, connectorIP)
779+
if err != nil {
780+
log.Print("Error reading volume")
781+
return false, err
782+
}
783+
volFound := false
784+
for _, vol := range res {
785+
if vol.Name == d.Get("name") {
786+
volFound = true
787+
break
788+
}
789+
}
790+
if !volFound {
791+
d.SetId("")
792+
return false, nil
793+
}
709794
}
795+
710796
return true, nil
711797
}
712798

@@ -805,7 +891,7 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
805891
eachRule[0] = x
806892
rules[i].Ips = eachRule
807893
rules[i].NfsVersion = volume.ExportPolicyInfo.NfsVersion
808-
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
894+
rules[i].SuperUser = d.Get("export_policy_rule_super_user").(bool)
809895
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
810896
rules[i].Index = int32(i + 1)
811897
}
@@ -872,6 +958,33 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
872958
return resourceCVOVolumeRead(d, meta)
873959
}
874960

961+
func resourceVolumeImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
962+
parts := strings.Split(d.Id(), ",")
963+
if parts[0] != "Standard" && parts[0] != "Restricted" {
964+
return []*schema.ResourceData{}, fmt.Errorf("wrong option for deployment_mode: %s, options for deployment_mode are 'Standard' and 'Restricted'", parts[0])
965+
}
966+
967+
if parts[0] == "Standard" && len(parts) != 4 {
968+
return []*schema.ResourceData{}, fmt.Errorf("wrong format of resource: %s. Please input in the format 'deployment_mode,client_id,working_environment_name,name'", d.Id())
969+
}
970+
971+
if parts[0] == "Restricted" && len(parts) != 6 {
972+
return []*schema.ResourceData{}, fmt.Errorf("wrong format of resource: %s. Please input in the format 'deployment_mode,client_id,working_environment_name,name,tenant_id,connector_ip'", d.Id())
973+
}
974+
975+
d.Set("deployment_mode", parts[0])
976+
d.Set("client_id", parts[1])
977+
d.Set("working_environment_name", parts[2])
978+
d.Set("name", parts[3])
979+
if parts[0] == "Restricted" {
980+
d.Set("tenant_id", parts[4])
981+
d.Set("connector_ip", parts[5])
982+
}
983+
984+
return []*schema.ResourceData{d}, nil
985+
986+
}
987+
875988
func resourceVolumeCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
876989
// Check supported modification: Use volume name as an indication to know if this is a creation or modification
877990
if !(diff.HasChange("name")) {

cloudmanager/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type ExportPolicyRule struct {
8888
// Clients []string `structs:"clients"`
8989
// RoRule []string `structs:"ro_rule"`
9090
// RwRule []string `structs:"rw_rule"`
91-
Superuser bool `structs:"superuser"`
91+
SuperUser bool `structs:"superUser"`
9292
Index int32 `structs:"index,omitempty"`
9393
RuleAccessControl string `structs:"ruleAccessControl"`
9494
Ips []string `structs:"ips"`

website/docs/r/aws_fsx.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ resource "netapp-cloudmanager_aws_fsx" "aws-fsx" {
4444

4545
The following arguments are supported:
4646

47-
* `name` - (Required) The name of the Cloud Volumes ONTAP working environment.
47+
* `name` - (Required) The name of the working environment.
4848
* `aws_credentials_name` - (Required) The name of the AWS Credentials account name.
4949
* `region` - (Required) The region where the working environment will be created.
5050
* `primary_subnet_id` - (Required) For HA, the subnet ID of the first node.
5151
* `secondary_subnet_id` - (Required) For HA, the subnet ID of the second node.
52-
* `fsx_admin_password` - (Required) The admin password for Cloud Volumes ONTAP.
53-
* `tenant_id` - (Required) The NetApp account ID that the Connector will be associated with.
52+
* `fsx_admin_password` - (Required) The admin password for working environment.
53+
* `tenant_id` - (Required) The NetApp account ID that the working environment will be associated with.
5454
* `workspace_id` - (Required) The ID of the Cloud Manager workspace of working environment.
5555
* `kms_key_id` - (Optional) AWS encryption parameters. It is required if using aws encryption.
5656
* `minimum_ssd_iops` - (Optional) Provisioned SSD IOPS.

0 commit comments

Comments
 (0)