Skip to content

Commit

Permalink
[ANF] Standard Network Feature (#17043)
Browse files Browse the repository at this point in the history
* Adding support for network features and LRO

* Updated ANF SDK version, adding resource_group prevent deletion to be off

* Adding tags to avoid issues on MSFT testing environment

* Adding newer ANF SDK

* fixing gencheck

* Fixing linting issues

* Fixing vendor folder again

* Executing go mod tidy

* go mod vendor execution

* removing data source property set

* Changing CRR pair region

* Hardcoding regions to avoid CRR issues due to region peering sensitivity

Co-authored-by: root <[email protected]>
  • Loading branch information
paulomarquesc and root authored Jun 2, 2022
1 parent 315ade0 commit 9caeeb9
Show file tree
Hide file tree
Showing 39 changed files with 3,020 additions and 362 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/hashicorp/go-azure-helpers v0.33.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/go-version v1.4.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/magodo/terraform-provider-azurerm-example-gen v0.0.0-20220407025246-3a3ee0ab24a8
github.com/manicminer/hamilton v0.44.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2I
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hc-install v0.3.1 h1:VIjllE6KyAI1A244G8kTaHXy+TL5/XYzvrtFi8po/Yk=
Expand Down
2 changes: 1 addition & 1 deletion 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/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/services/netapp/netapp_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down
2 changes: 1 addition & 1 deletion 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/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ data "azurerm_netapp_snapshot_policy" "test" {
name = azurerm_netapp_snapshot_policy.test.name
resource_group_name = azurerm_netapp_snapshot_policy.test.resource_group_name
account_name = azurerm_netapp_snapshot_policy.test.account_name
enabled = azurerm_netapp_snapshot_policy.test.enabled
}
`, NetAppSnapshotPolicyResource{}.basic(data))
}
15 changes: 12 additions & 3 deletions internal/services/netapp/netapp_snapshot_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -298,10 +298,15 @@ func resourceNetAppSnapshotPolicyUpdate(d *pluginsdk.ResourceData, meta interfac
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if _, err := client.Update(ctx, parameters, resourceGroup, accountName, name); err != nil {
future, err := client.Update(ctx, parameters, resourceGroup, accountName, name)
if err != nil {
return fmt.Errorf("updating NetApp SnapshotPolicy %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation/update of %q (Resource Group %q): %+v", name, resourceGroup, err)
}

return resourceNetAppSnapshotPolicyRead(d, meta)
}

Expand Down Expand Up @@ -361,11 +366,15 @@ func resourceNetAppSnapshotPolicyDelete(d *pluginsdk.ResourceData, meta interfac
}

// Deleting snapshot policy and waiting for it fo fully complete the operation
if _, err = client.Delete(ctx, id.ResourceGroup, id.NetAppAccountName, id.Name); err != nil {
future, err := client.Delete(ctx, id.ResourceGroup, id.NetAppAccountName, id.Name)
if err != nil {
return fmt.Errorf("deleting NetApp Snapshot Policy %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

log.Printf("[DEBUG] Waiting for NetApp SnapshotPolicy Provisioning Service %q (Resource Group %q) to be deleted", id.Name, id.ResourceGroup)
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for deletion of %q: %+v", id, err)
}
if err := waitForSnapshotPolicyDeletion(ctx, client, *id, d.Timeout(pluginsdk.TimeoutDelete)); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion 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/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
6 changes: 6 additions & 0 deletions internal/services/netapp/netapp_volume_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func dataSourceNetAppVolume() *pluginsdk.Resource {
Computed: true,
},

"network_features": {
Type: pluginsdk.TypeString,
Computed: true,
},

"storage_quota_in_gb": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand Down Expand Up @@ -140,6 +145,7 @@ func dataSourceNetAppVolumeRead(d *pluginsdk.ResourceData, meta interface{}) err
d.Set("volume_path", props.CreationToken)
d.Set("service_level", props.ServiceLevel)
d.Set("subnet_id", props.SubnetID)
d.Set("network_features", props.NetworkFeatures)

protocolTypes := make([]string, 0)
if prtclTypes := props.ProtocolTypes; prtclTypes != nil {
Expand Down
10 changes: 10 additions & 0 deletions internal/services/netapp/netapp_volume_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAccDataSourceNetAppVolume_basic(t *testing.T) {
check.That(data.ResourceName).Key("volume_path").Exists(),
check.That(data.ResourceName).Key("service_level").Exists(),
check.That(data.ResourceName).Key("subnet_id").Exists(),
check.That(data.ResourceName).Key("network_features").HasValue("Basic"),
check.That(data.ResourceName).Key("storage_quota_in_gb").Exists(),
check.That(data.ResourceName).Key("protocols.0").Exists(),
check.That(data.ResourceName).Key("mount_ip_addresses.#").HasValue("1"),
Expand All @@ -33,6 +34,15 @@ func (NetAppVolumeDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
provider "azurerm" {
alias = "all"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_netapp_volume" "test" {
resource_group_name = azurerm_netapp_volume.test.resource_group_name
account_name = azurerm_netapp_volume.test.account_name
Expand Down
51 changes: 39 additions & 12 deletions internal/services/netapp/netapp_volume_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/go-azure-helpers/resourcemanager/location"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2021-10-01/netapp"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down Expand Up @@ -101,6 +101,17 @@ func resourceNetAppVolume() *pluginsdk.Resource {
ValidateFunc: netAppValidate.SnapshotID,
},

"network_features": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(netapp.NetworkFeaturesBasic),
string(netapp.NetworkFeaturesStandard),
}, false),
},

"protocols": {
Type: pluginsdk.TypeSet,
ForceNew: true,
Expand Down Expand Up @@ -289,6 +300,12 @@ func resourceNetAppVolumeCreate(d *pluginsdk.ResourceData, meta interface{}) err
volumePath := d.Get("volume_path").(string)
serviceLevel := d.Get("service_level").(string)
subnetID := d.Get("subnet_id").(string)

networkFeatures := d.Get("network_features").(string)
if networkFeatures == "" {
networkFeatures = string(netapp.NetworkFeaturesBasic)
}

protocols := d.Get("protocols").(*pluginsdk.Set).List()
if len(protocols) == 0 {
protocols = append(protocols, "NFSv3")
Expand Down Expand Up @@ -398,15 +415,16 @@ func resourceNetAppVolumeCreate(d *pluginsdk.ResourceData, meta interface{}) err
parameters := netapp.Volume{
Location: utils.String(location),
VolumeProperties: &netapp.VolumeProperties{
CreationToken: utils.String(volumePath),
ServiceLevel: netapp.ServiceLevel(serviceLevel),
SubnetID: utils.String(subnetID),
ProtocolTypes: utils.ExpandStringSlice(protocols),
SecurityStyle: netapp.SecurityStyle(securityStyle),
UsageThreshold: utils.Int64(storageQuotaInGB),
ExportPolicy: exportPolicyRule,
VolumeType: utils.String(volumeType),
SnapshotID: utils.String(snapshotID),
CreationToken: utils.String(volumePath),
ServiceLevel: netapp.ServiceLevel(serviceLevel),
SubnetID: utils.String(subnetID),
NetworkFeatures: netapp.NetworkFeatures(networkFeatures),
ProtocolTypes: utils.ExpandStringSlice(protocols),
SecurityStyle: netapp.SecurityStyle(securityStyle),
UsageThreshold: utils.Int64(storageQuotaInGB),
ExportPolicy: exportPolicyRule,
VolumeType: utils.String(volumeType),
SnapshotID: utils.String(snapshotID),
DataProtection: &netapp.VolumePropertiesDataProtection{
Replication: dataProtectionReplication.Replication,
Snapshot: dataProtectionSnapshotPolicy.Snapshot,
Expand Down Expand Up @@ -574,6 +592,7 @@ func resourceNetAppVolumeRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("volume_path", props.CreationToken)
d.Set("service_level", props.ServiceLevel)
d.Set("subnet_id", props.SubnetID)
d.Set("network_features", props.NetworkFeatures)
d.Set("protocols", props.ProtocolTypes)
d.Set("security_style", props.SecurityStyle)
d.Set("snapshot_directory_visible", props.SnapshotDirectoryVisible)
Expand Down Expand Up @@ -656,22 +675,30 @@ func resourceNetAppVolumeDelete(d *pluginsdk.ResourceData, meta interface{}) err
}

// Deleting replication and waiting for it to fully complete the operation
if _, err = client.DeleteReplication(ctx, replicaVolumeId.ResourceGroup, replicaVolumeId.NetAppAccountName, replicaVolumeId.CapacityPoolName, replicaVolumeId.Name); err != nil {
future, err := client.DeleteReplication(ctx, replicaVolumeId.ResourceGroup, replicaVolumeId.NetAppAccountName, replicaVolumeId.CapacityPoolName, replicaVolumeId.Name)
if err != nil {
return fmt.Errorf("deleting replicate %s: %+v", *replicaVolumeId, err)
}

log.Printf("[DEBUG] Waiting for the replica of %s to be deleted", replicaVolumeId)
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for the replica %s to be deleted: %+v", *replicaVolumeId, err)
}
if err := waitForReplicationDeletion(ctx, client, *replicaVolumeId); err != nil {
return fmt.Errorf("waiting for the replica %s to be deleted: %+v", *replicaVolumeId, err)
}
}

// Deleting volume and waiting for it fo fully complete the operation
if _, err = client.Delete(ctx, id.ResourceGroup, id.NetAppAccountName, id.CapacityPoolName, id.Name); err != nil {
future, err := client.Delete(ctx, id.ResourceGroup, id.NetAppAccountName, id.CapacityPoolName, id.Name, utils.Bool(true))
if err != nil {
return fmt.Errorf("deleting %s: %+v", *id, err)
}

log.Printf("[DEBUG] Waiting for %s to be deleted", *id)
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for deletion of %q: %+v", id, err)
}
if err := waitForVolumeDeletion(ctx, client, *id); err != nil {
return fmt.Errorf("waiting for deletion of %s: %+v", *id, err)
}
Expand Down
Loading

0 comments on commit 9caeeb9

Please sign in to comment.