Skip to content

Commit 72b5ae5

Browse files
committed
Add delete_destination_volume option to snapmirror resource
- Add new optional parameter delete_destination_volume (default: false) - When enabled, automatically deletes destination volume after snapmirror deletion - Reuses existing volume deletion logic for consistency - Update documentation and examples - Maintains backward compatibility This enhancement allows users to automatically clean up destination volumes when destroying snapmirror relationships, preventing orphaned resources while maintaining backward compatibility with existing configurations.
1 parent db158fa commit 72b5ae5

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

cloudmanager/resource_netapp_cloudmanager_snapmirror.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func resourceCVOSnapMirror() *schema.Resource {
110110
Optional: true,
111111
ForceNew: true,
112112
},
113+
"delete_destination_volume": {
114+
Type: schema.TypeBool,
115+
Optional: true,
116+
Default: false,
117+
Description: "Set to true to delete the destination volume when the snapmirror relationship is destroyed",
118+
},
113119
},
114120
}
115121
}
@@ -272,6 +278,26 @@ func resourceCVOSnapMirrorDelete(d *schema.ResourceData, meta interface{}) error
272278
log.Print("Error deleting SnapMirror")
273279
return err
274280
}
281+
282+
// If delete_destination_volume is enabled, also delete the destination volume
283+
if d.Get("delete_destination_volume").(bool) {
284+
log.Printf("Deleting destination volume: %s", snapMirror.ReplicationVolume.DestinationVolumeName)
285+
286+
// Prepare volume request for deletion using the same logic as volume resource
287+
volume := volumeRequest{}
288+
volume.WorkingEnvironmentID = destWEInfo.PublicID
289+
volume.WorkingEnvironmentType = destWEInfo.WorkingEnvironmentType
290+
volume.SvmName = snapMirror.ReplicationVolume.DestinationSvmName
291+
volume.Name = snapMirror.ReplicationVolume.DestinationVolumeName
292+
293+
err = client.deleteVolume(volume, clientID, isSaas, connectorIP)
294+
if err != nil {
295+
log.Printf("Error deleting destination volume: %s", snapMirror.ReplicationVolume.DestinationVolumeName)
296+
return err
297+
}
298+
log.Printf("Successfully deleted destination volume: %s", snapMirror.ReplicationVolume.DestinationVolumeName)
299+
}
300+
275301
return nil
276302
}
277303

examples/snapmirror/resources.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ resource "netapp-cloudmanager_snapmirror" "cl-snapmirror" {
6868
schedule = "5min"
6969
source_volume_name = netapp-cloudmanager_volume.cvo-volume2.name
7070
source_working_environment_id = netapp-cloudmanager_cvo_aws.cvo-aws-2.id
71+
delete_destination_volume = true # Enable automatic deletion of destination volume when snapmirror is destroyed
7172
}

website/docs/r/snapmirror.html.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ resource "netapp-cloudmanager_snapmirror" "cl-snapmirror" {
3131
}
3232
```
3333

34+
**Create netapp-cloudmanager_snapmirror with automatic destination volume deletion:**
35+
36+
```
37+
resource "netapp-cloudmanager_snapmirror" "cl-snapmirror-with-volume-deletion" {
38+
provider = netapp-cloudmanager
39+
source_working_environment_id = "xxxxxxxx"
40+
destination_working_environment_id = "xxxxxxxx"
41+
source_volume_name = "source"
42+
source_svm_name = "svm_source"
43+
destination_volume_name = "source_copy"
44+
destination_svm_name = "svm_dest"
45+
policy = "MirrorAllSnapshots"
46+
schedule = "5min"
47+
destination_aggregate_name = "aggr1"
48+
max_transfer_rate = "102400"
49+
delete_destination_volume = true
50+
client_id = "xxxxxxxxxxx"
51+
}
52+
```
53+
3454
## Argument Reference
3555

3656
The following arguments are supported:
@@ -53,6 +73,7 @@ The following arguments are supported:
5373
* `destination_aggregate_name` - (Optional) The aggregate in which the volume will be created. If not provided, Cloud Manager chooses the best aggregate for you.
5474
* `provider_volume_type` - (Optional) The underlying cloud provider volume type. For AWS: ['gp3', 'gp2', 'io1', 'st1', 'sc1']. For Azure: ['Premium_LRS','Standard_LRS','StandardSSD_LRS']. For GCP: ['pd-balanced', 'pd-ssd','pd-standard']
5575
* `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.
76+
* `delete_destination_volume` - (Optional) Set to true to delete the destination volume when the snapmirror relationship is destroyed. The default is false.
5677

5778
## Attributes Reference
5879

0 commit comments

Comments
 (0)