Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_netapp_volume - support the data_protection_replication block #10610

Merged
merged 30 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
84d3ac8
api version bump up
paulomarquesc Jan 27, 2021
8ca3c76
removing tags support from code, snapshots do not support it anymore
paulomarquesc Jan 27, 2021
5ce5f2d
Removed tag from snapshot documentation since it is not supported any…
paulomarquesc Jan 27, 2021
450fab0
WIP: CRR support implementation
paulomarquesc Jan 30, 2021
eb6c409
WIP: CRR implementation - CRR is now being deployed and volume deleti…
paulomarquesc Feb 3, 2021
03ecb3e
CRR code implementation concluded
paulomarquesc Feb 5, 2021
9b902f6
removal of testing line
paulomarquesc Feb 5, 2021
2b67292
Removal of "src" option for endpoint_type since it is automatically d…
paulomarquesc Feb 10, 2021
997efb7
Updating volume documentation with CRR block
paulomarquesc Feb 10, 2021
143794c
Updates to documentation
paulomarquesc Feb 16, 2021
bc6c0c4
Merge branch 'master' into pmarques/crr_support
paulomarquesc Feb 16, 2021
deb1f5c
Updating vendor folder with latest NetApp GO SDK version
paulomarquesc Feb 16, 2021
98930a4
Adding note about preview and opt-in process.
paulomarquesc Feb 16, 2021
126403d
Fixing Katie's comments and linting issues
paulomarquesc Feb 17, 2021
28aad98
Lower case when flattening endpoint_type
paulomarquesc Feb 17, 2021
34faa4e
Update azurerm/internal/services/netapp/netapp_snapshot_resource.go
paulomarquesc Feb 18, 2021
d259954
Update azurerm/internal/services/netapp/netapp_volume_resource.go
paulomarquesc Feb 18, 2021
66e1e59
Update azurerm/internal/services/netapp/netapp_volume_resource.go
paulomarquesc Feb 18, 2021
f231fbc
Second round of comment fixes
paulomarquesc Feb 18, 2021
e007074
snapshot tag deprecation
paulomarquesc Feb 19, 2021
a84df78
Full CRR example and reference.
paulomarquesc Feb 19, 2021
73356ba
Renaming replication_schedule to replication_frequency
paulomarquesc Feb 19, 2021
a696c28
using terrafmt tool to fix linting issues
paulomarquesc Feb 19, 2021
50357b7
Revert "Updating vendor folder with latest NetApp GO SDK version"
paulomarquesc Feb 19, 2021
b521668
Executing "go mod vendor" to fix vendor folder issues
paulomarquesc Feb 19, 2021
6c9c31b
Applying replication_frequency renaming here as well
paulomarquesc Feb 19, 2021
1da6833
Making northeurope hardcoded for acceptance tests due to comply with …
paulomarquesc Feb 22, 2021
793bb5a
Update azurerm/internal/services/netapp/netapp_snapshot_resource.go
katbyte Feb 23, 2021
d1e882b
Update azurerm/internal/services/netapp/netapp_snapshot_resource.go
katbyte Feb 23, 2021
a408020
Update azurerm/internal/services/netapp/netapp_snapshot_resource.go
katbyte Feb 23, 2021
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
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
44 changes: 18 additions & 26 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,6 +71,8 @@ func resourceNetAppSnapshot() *schema.Resource {
ValidateFunc: ValidateNetAppVolumeName,
},

// TODO: remove this in a next breaking changes release since tags are
// not supported anymore on Snapshots
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -101,9 +103,14 @@ func resourceNetAppSnapshotCreate(d *schema.ResourceData, meta interface{}) erro

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

// Snapshot resource in Azure changed its type to proxied resource, therefore
// tags are not supported anymore, ignoring any tags.
katbyte marked this conversation as resolved.
Show resolved Hide resolved
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 +162,18 @@ func resourceNetAppSnapshotRead(d *schema.ResourceData, meta interface{}) error
d.Set("location", azure.NormalizeLocation(*location))
}

return tags.FlattenAndSet(d, resp.Tags)
// Snapshot resource in Azure changed its type to proxied resource, therefore
// tags are not supported anymore, returning nil now.
// For reference, this method return line was `return tags.FlattenAndSet(d, resp.Tags)`

return nil
katbyte marked this conversation as resolved.
Show resolved Hide resolved
}

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
34 changes: 34 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,32 @@ func dataSourceNetAppVolume() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"data_protection_replication": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_type": {
Type: schema.TypeString,
Required: true,
},

"remote_volume_location": azure.SchemaLocationForDataSource(),

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

"replication_schedule": {
Type: schema.TypeString,
Required: true,
},
},
},
},
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
},
}
}
Expand Down Expand Up @@ -107,9 +133,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 +155,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