Skip to content

Commit

Permalink
azurerm_netapp_volume - support the data_protection_replication blo…
Browse files Browse the repository at this point in the history
…ck (#10610)

Co-authored-by: kt <[email protected]>
This PR implements support for Cross-Region Replication (CRR) feature of ANF Volumes.

Worth it to call out that since CRR is extremely sensitive on resources being complete, we extended usage of stateCOnf.WaitForState for all steps of volume creation/deletion.
  • Loading branch information
paulomarquesc authored Feb 23, 2021
1 parent 461557b commit c24fb0e
Show file tree
Hide file tree
Showing 31 changed files with 6,639 additions and 1,681 deletions.
2 changes: 1 addition & 1 deletion azurerm/internal/services/netapp/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2020-09-01/netapp"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2020-09-01/netapp"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/netapp/netapp_pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2020-09-01/netapp"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
47 changes: 20 additions & 27 deletions azurerm/internal/services/netapp/netapp_snapshot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2020-09-01/netapp"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -71,7 +71,16 @@ func resourceNetAppSnapshot() *schema.Resource {
ValidateFunc: ValidateNetAppVolumeName,
},

"tags": tags.Schema(),
// TODO: remove this in a next breaking changes release since tags are
// not supported anymore on Snapshots (todo 3.0)
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Deprecated: "This property as been deprecated as the API no longer supports tags and will be removed in version 3.0 of the provider.",
},
},
}
}
Expand Down Expand Up @@ -101,9 +110,12 @@ func resourceNetAppSnapshotCreate(d *schema.ResourceData, meta interface{}) erro

location := azure.NormalizeLocation(d.Get("location").(string))

if tags.Expand(d.Get("tags").(map[string]interface{})) != nil {
log.Printf("[WARN] Tags are not supported on snaphots anymore, ignoring values.")
}

parameters := netapp.Snapshot{
Location: utils.String(location),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

future, err := client.Create(ctx, parameters, resourceGroup, accountName, poolName, volumeName, name)
Expand Down Expand Up @@ -155,33 +167,14 @@ func resourceNetAppSnapshotRead(d *schema.ResourceData, meta interface{}) error
d.Set("location", azure.NormalizeLocation(*location))
}

return tags.FlattenAndSet(d, resp.Tags)
return nil
}

func resourceNetAppSnapshotUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).NetApp.SnapshotClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.SnapshotID(d.Id())
if err != nil {
return err
}

parameters := netapp.SnapshotPatch{
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if _, err = client.Update(ctx, parameters, id.ResourceGroup, id.NetAppAccountName, id.CapacityPoolName, id.VolumeName, id.Name); err != nil {
return fmt.Errorf("Error updating NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

resp, err := client.Get(ctx, id.ResourceGroup, id.NetAppAccountName, id.CapacityPoolName, id.VolumeName, id.Name)
if err != nil {
return fmt.Errorf("Error retrieving NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Cannot read NetApp Snapshot %q (Resource Group %q) ID", id.Name, id.ResourceGroup)
// Snapshot resource in Azure changed its type to proxied resource, therefore
// tags are not supported anymore, ignoring any tags.
if tags.Expand(d.Get("tags").(map[string]interface{})) == nil {
log.Printf("[WARN] Tags are not supported on snaphots anymore, no update will happen in a snapshot at this time.")
}

return resourceNetAppSnapshotRead(d, meta)
Expand Down
33 changes: 33 additions & 0 deletions azurerm/internal/services/netapp/netapp_volume_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ func dataSourceNetAppVolume() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"data_protection_replication": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_type": {
Type: schema.TypeString,
Computed: true,
},

"remote_volume_location": azure.SchemaLocationForDataSource(),

"remote_volume_resource_id": {
Type: schema.TypeString,
Computed: true,
},

"replication_schedule": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -107,9 +132,11 @@ func dataSourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error
d.Set("resource_group_name", resourceGroup)
d.Set("account_name", accountName)
d.Set("pool_name", poolName)

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

if props := resp.VolumeProperties; props != nil {
d.Set("volume_path", props.CreationToken)
d.Set("service_level", props.ServiceLevel)
Expand All @@ -127,6 +154,12 @@ func dataSourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("mount_ip_addresses", flattenNetAppVolumeMountIPAddresses(props.MountTargets)); err != nil {
return fmt.Errorf("setting `mount_ip_addresses`: %+v", err)
}

if props.DataProtection.Replication != nil {
if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil {
return fmt.Errorf("setting `data_protection_replication`: %+v", err)
}
}
}

return nil
Expand Down
Loading

0 comments on commit c24fb0e

Please sign in to comment.