Skip to content
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
3 changes: 3 additions & 0 deletions .changelog/17555.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
netapp: added `ontap_source` field to `google_netapp_backup` resource (beta)
```
116 changes: 116 additions & 0 deletions google-beta/services/netapp/resource_netapp_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ func ResourceNetappBackup() *schema.Resource {
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ontap_source": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Details of the ONTAP source volume and snapshot.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"storage_pool": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Name of the storage pool. This must be specified for creating backups for ONTAP mode volumes.
Format: 'projects/{{project}}/locations/{{location}}/storagePools/{{storage_pool_id}}'`,
},
"volume_uuid": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The UUID of the ONTAP source volume.`,
},
"snapshot_uuid": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The UUID of the ONTAP source snapshot.`,
},
},
},
},
"source_snapshot": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -293,6 +323,12 @@ func resourceNetappBackupCreate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("source_snapshot"); !tpgresource.IsEmptyValue(reflect.ValueOf(sourceSnapshotProp)) && (ok || !reflect.DeepEqual(v, sourceSnapshotProp)) {
obj["sourceSnapshot"] = sourceSnapshotProp
}
ontapSourceProp, err := expandNetappBackupOntapSource(d.Get("ontap_source"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ontap_source"); !tpgresource.IsEmptyValue(reflect.ValueOf(ontapSourceProp)) && (ok || !reflect.DeepEqual(v, ontapSourceProp)) {
obj["ontapSource"] = ontapSourceProp
}
effectiveLabelsProp, err := expandNetappBackupEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -742,6 +778,35 @@ func flattenNetappBackupSourceSnapshot(v interface{}, d *schema.ResourceData, co
return v
}

func flattenNetappBackupOntapSource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["storage_pool"] =
flattenNetappBackupOntapSourceStoragePool(original["storagePool"], d, config)
transformed["volume_uuid"] =
flattenNetappBackupOntapSourceVolumeUuid(original["volumeUuid"], d, config)
transformed["snapshot_uuid"] =
flattenNetappBackupOntapSourceSnapshotUuid(original["snapshotUuid"], d, config)
return []interface{}{transformed}
}
func flattenNetappBackupOntapSourceStoragePool(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNetappBackupOntapSourceVolumeUuid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNetappBackupOntapSourceSnapshotUuid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNetappBackupVolumeRegion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -781,6 +846,54 @@ func expandNetappBackupSourceSnapshot(v interface{}, d tpgresource.TerraformReso
return v, nil
}

func expandNetappBackupOntapSource(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
if v == nil {
return nil, nil
}
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedStoragePool, err := expandNetappBackupOntapSourceStoragePool(original["storage_pool"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedStoragePool); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["storagePool"] = transformedStoragePool
}

transformedVolumeUuid, err := expandNetappBackupOntapSourceVolumeUuid(original["volume_uuid"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedVolumeUuid); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["volumeUuid"] = transformedVolumeUuid
}

transformedSnapshotUuid, err := expandNetappBackupOntapSourceSnapshotUuid(original["snapshot_uuid"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSnapshotUuid); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["snapshotUuid"] = transformedSnapshotUuid
}

return transformed, nil
}

func expandNetappBackupOntapSourceStoragePool(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetappBackupOntapSourceVolumeUuid(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetappBackupOntapSourceSnapshotUuid(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetappBackupEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down Expand Up @@ -822,6 +935,9 @@ func ResourceNetappBackupFlatten(d *schema.ResourceData, meta interface{}, res m
if err = d.Set("source_snapshot", flattenNetappBackupSourceSnapshot(res["sourceSnapshot"], d, config)); err != nil {
return fmt.Errorf("Error reading Backup: %s", err)
}
if err = d.Set("ontap_source", flattenNetappBackupOntapSource(res["ontapSource"], d, config)); err != nil {
return fmt.Errorf("Error reading Backup: %s", err)
}
if err = d.Set("volume_region", flattenNetappBackupVolumeRegion(res["volumeRegion"], d, config)); err != nil {
return fmt.Errorf("Error reading Backup: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fields:
provider_only: true
- field: name
provider_only: true
- api_field: ontapSource.snapshotUuid
- api_field: ontapSource.storagePool
- api_field: ontapSource.volumeUuid
- api_field: sourceSnapshot
- api_field: sourceVolume
- api_field: state
Expand Down
20 changes: 20 additions & 0 deletions website/docs/r/netapp_backup.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ The following arguments are supported:
there will be a new snapshot taken to initiate the backup creation.
Format: `projects/{{projectId}}/locations/{{location}}/volumes/{{volumename}}/snapshots/{{snapshotname}}``

* `ontap_source` -
(Optional, [Beta](../guides/provider_versions.html.markdown))
Details of the ONTAP source volume and snapshot.
Structure is [documented below](#nested_ontap_source).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand All @@ -141,6 +146,21 @@ The following arguments are supported:
When set to "DELETE", deleting the resource is allowed.


<a name="nested_ontap_source"></a>The `ontap_source` block supports:

* `storage_pool` -
(Required)
Name of the storage pool. This must be specified for creating backups for ONTAP mode volumes.
Format: `projects/{{project}}/locations/{{location}}/storagePools/{{storage_pool_id}}`

* `volume_uuid` -
(Required)
The UUID of the ONTAP source volume.

* `snapshot_uuid` -
(Optional)
The UUID of the ONTAP source snapshot.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:
Expand Down
Loading