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

New resource: azurerm_netapp_backup_vault and azurerm_netapp_backup_policy #27188

Merged
merged 36 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e2f4d8b
WIP: staring backup work
paulomarquesc Jul 1, 2024
6d7cd48
WIP
paulomarquesc Jul 2, 2024
589c578
netapp_backup_vault resource and data source implementation
paulomarquesc Jul 3, 2024
da5374c
Final changes for backup policy feature
paulomarquesc Aug 22, 2024
5f8b852
adding feature block to allow volume deletion on test and bug fix for…
paulomarquesc Aug 23, 2024
2995a3e
Fixing issue with snapshot_directory_visible and addikng alias to acc…
paulomarquesc Aug 24, 2024
459f2e0
Fixing variable name
paulomarquesc Aug 24, 2024
55620b4
Adding updated module files
paulomarquesc Aug 24, 2024
de66980
vendor updates
paulomarquesc Aug 24, 2024
05e5c4a
Merge branch 'main' into pmarques/anf_backup
paulomarquesc Aug 24, 2024
165793d
Removing unnecessary Get
paulomarquesc Aug 24, 2024
21f4326
Fixing checks issues
paulomarquesc Aug 24, 2024
28a4f0b
Fixing linting issue
paulomarquesc Aug 24, 2024
6a8cdb3
Fixing website linting issues
paulomarquesc Aug 24, 2024
af360d9
fixes related to PR 27188 comments
paulomarquesc Oct 17, 2024
7c3e312
Merge branch 'main' into pmarques/anf_backup
paulomarquesc Oct 17, 2024
a940940
fixing vendor issues
paulomarquesc Oct 17, 2024
0b162d8
Adding _maintainers folder
paulomarquesc Oct 17, 2024
51bfd98
New round of PR comments fixes
paulomarquesc Oct 18, 2024
42b5d34
fixing test
paulomarquesc Oct 18, 2024
c8e2b33
rolling back id validations
paulomarquesc Oct 18, 2024
68235ff
Fixing format issues
paulomarquesc Oct 21, 2024
00e9aa1
Updated _maintainers folder
paulomarquesc Oct 30, 2024
2692b17
Merge branch 'main' into pmarques/anf_backup
paulomarquesc Nov 8, 2024
adda2cb
Updating with new features block framework
paulomarquesc Nov 11, 2024
182cf5e
Merge branch 'main' into pmarques/anf_backup
paulomarquesc Nov 12, 2024
3754d56
fixing modules.txt issue
paulomarquesc Nov 12, 2024
9213e05
Applying suggestions from another PR review round
paulomarquesc Nov 13, 2024
52c43fb
removing extra line
paulomarquesc Nov 13, 2024
6350592
Fixing golint issues
paulomarquesc Nov 13, 2024
7ed46e7
Fixing newfound issues
paulomarquesc Nov 14, 2024
92d67b4
Removing comment
paulomarquesc Nov 14, 2024
1b42331
Removing another comment
paulomarquesc Nov 14, 2024
16beb07
Updating null check and moving README.md to root of service
paulomarquesc Nov 14, 2024
54ed614
Update README.md
mbfrahry Nov 14, 2024
de73bf9
Fixing formatting issues
paulomarquesc Nov 14, 2024
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
5 changes: 5 additions & 0 deletions examples/netapp/nfsv3_volume_with_backup_policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Example: Azure NetApp Files Volume with Backup Policy enabled

This example shows how to create an Azure NetApp volume with Backup policy enabled.

For more information, please refer to [Understand Azure NetApp Files backup](https://learn.microsoft.com/en-us/azure/azure-netapp-files/backup-introduction).
100 changes: 100 additions & 0 deletions examples/netapp/nfsv3_volume_with_backup_policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
provider "azurerm" {
features {
netapp {
prevent_volume_destruction = false
delete_backups_on_backup_vault_destroy = true
}
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
}
}

resource "azurerm_resource_group" "example" {
name = "${var.prefix}-resources"
location = var.location
}

resource "azurerm_virtual_network" "example" {
name = "${var.prefix}-virtualnetwork"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
address_space = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example" {
name = "${var.prefix}-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]

delegation {
name = "testdelegation"

service_delegation {
name = "Microsoft.Netapp/volumes"
actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"]
}
}
}

resource "azurerm_netapp_account" "example" {
name = "${var.prefix}-netappaccount"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_netapp_backup_vault" "example" {
name = "${var.prefix}-netappbackupvault"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_name = azurerm_netapp_account.example.name
}

resource "azurerm_netapp_backup_policy" "example" {
name = "${var.prefix}-netappbackuppolicy"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_name = azurerm_netapp_account.example.name
daily_backups_to_keep = 2
weekly_backups_to_keep = 2
monthly_backups_to_keep = 2
enabled = true
}

resource "azurerm_netapp_pool" "example" {
name = "${var.prefix}-netapppool"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
account_name = azurerm_netapp_account.example.name
service_level = "Standard"
size_in_tb = 4
}

resource "azurerm_netapp_volume" "example" {
lifecycle {
prevent_destroy = true
}

name = "${var.prefix}-netappvolume"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
account_name = azurerm_netapp_account.example.name
pool_name = azurerm_netapp_pool.example.name
volume_path = "${var.prefix}-netappvolume"
service_level = "Standard"
protocols = ["NFSv3"]
network_features = "Basic"
subnet_id = azurerm_subnet.example.id
storage_quota_in_gb = 100

data_protection_backup_policy {
backup_vault_id = azurerm_netapp_backup_vault.example.id
backup_policy_id = azurerm_netapp_backup_policy.example.id
policy_enabled = true
}

export_policy_rule {
rule_index = 1
allowed_clients = ["0.0.0.0/0"]
protocols_enabled = ["NFSv3"]
unix_read_write = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "location" {
description = "The Azure location where all resources in this example should be created."
}

variable "prefix" {
description = "The prefix used for all resources used by this example"
}
4 changes: 4 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,9 @@ func Default() UserFeatures {
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
},
NetApp: NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: true,
},
}
}
6 changes: 6 additions & 0 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type UserFeatures struct {
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
MachineLearning MachineLearningFeatures
RecoveryService RecoveryServiceFeatures
NetApp NetAppFeatures
}

type CognitiveAccountFeatures struct {
Expand Down Expand Up @@ -109,3 +110,8 @@ type RecoveryServiceFeatures struct {
VMBackupStopProtectionAndRetainDataOnDestroy bool
PurgeProtectedItemsFromVaultOnDestroy bool
}

type NetAppFeatures struct {
DeleteBackupsOnBackupVaultDestroy bool
PreventVolumeDestruction bool
}
35 changes: 35 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,28 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},
},

"netapp": {
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"delete_backups_on_backup_vault_destroy": {
Description: "When enabled, backups will be deleted when the `azurerm_netapp_backup_vault` resource is destroyed",
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"prevent_volume_destruction": {
Description: "When enabled, the volume will not be destroyed, safeguarding from severe data loss",
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},
}

// this is a temporary hack to enable us to gradually add provider blocks to test configurations
Expand Down Expand Up @@ -648,5 +670,18 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["netapp"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
netappRaw := items[0].(map[string]interface{})
if v, ok := netappRaw["delete_backups_on_backup_vault_destroy"]; ok {
featuresMap.NetApp.DeleteBackupsOnBackupVaultDestroy = v.(bool)
}
if v, ok := netappRaw["prevent_volume_destruction"]; ok {
featuresMap.NetApp.PreventVolumeDestruction = v.(bool)
}
}
}

return featuresMap
}
113 changes: 113 additions & 0 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestExpandFeatures(t *testing.T) {
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
},
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: true,
},
},
},
{
Expand Down Expand Up @@ -201,6 +205,12 @@ func TestExpandFeatures(t *testing.T) {
"purge_protected_items_from_vault_on_destroy": true,
},
},
"netapp": []interface{}{
map[string]interface{}{
"delete_backups_on_backup_vault_destroy": true,
"prevent_volume_destruction": true,
},
},
},
},
Expected: features.UserFeatures{
Expand Down Expand Up @@ -274,6 +284,10 @@ func TestExpandFeatures(t *testing.T) {
VMBackupStopProtectionAndRetainDataOnDestroy: true,
PurgeProtectedItemsFromVaultOnDestroy: true,
},
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: true,
PreventVolumeDestruction: true,
},
},
},
{
Expand Down Expand Up @@ -384,6 +398,12 @@ func TestExpandFeatures(t *testing.T) {
"purge_protected_items_from_vault_on_destroy": false,
},
},
"netapp": []interface{}{
map[string]interface{}{
"delete_backups_on_backup_vault_destroy": false,
"prevent_volume_destruction": false,
},
},
},
},
Expected: features.UserFeatures{
Expand Down Expand Up @@ -457,6 +477,10 @@ func TestExpandFeatures(t *testing.T) {
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
},
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: false,
},
},
},
}
Expand Down Expand Up @@ -1745,3 +1769,92 @@ func TestExpandFeaturesRecoveryService(t *testing.T) {
}
}
}

func TestExpandFeaturesNetApp(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"netapp": []interface{}{},
},
},
Expected: features.UserFeatures{
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: true,
},
},
},
{
Name: "NetApp Features Enabled",
Input: []interface{}{
map[string]interface{}{
"netapp": []interface{}{
map[string]interface{}{
"delete_backups_on_backup_vault_destroy": true,
"prevent_volume_destruction": true,
},
},
},
},
Expected: features.UserFeatures{
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: true,
},
},
},
{
Name: "NetApp Features Disabled",
Input: []interface{}{
map[string]interface{}{
"netapp": []interface{}{
map[string]interface{}{
"delete_backups_on_backup_vault_destroy": false,
"prevent_volume_destruction": false,
},
},
},
},
Expected: features.UserFeatures{
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: false,
PreventVolumeDestruction: false,
},
},
},
{
Name: "NetApp Features Reverse Default Values",
Input: []interface{}{
map[string]interface{}{
"netapp": []interface{}{
map[string]interface{}{
"delete_backups_on_backup_vault_destroy": true,
"prevent_volume_destruction": false,
},
},
},
},
Expected: features.UserFeatures{
NetApp: features.NetAppFeatures{
DeleteBackupsOnBackupVaultDestroy: true,
PreventVolumeDestruction: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.Subscription, testCase.Expected.Subscription) {
t.Fatalf("Expected %+v but got %+v", result.Subscription, testCase.Expected.Subscription)
}
}
}
23 changes: 23 additions & 0 deletions internal/provider/framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ func (p *ProviderConfig) Load(ctx context.Context, data *ProviderModel, tfVersio
f.RecoveryService.VMBackupStopProtectionAndRetainDataOnDestroy = false
f.RecoveryService.PurgeProtectedItemsFromVaultOnDestroy = false
}

if !features.NetApp.IsNull() && !features.NetApp.IsUnknown() {
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
var feature []NetApp
d := features.NetApp.ElementsAs(ctx, &feature, true)
diags.Append(d...)
if diags.HasError() {
return
}

f.NetApp.DeleteBackupsOnBackupVaultDestroy = false
if !feature[0].DeleteBackupsOnBackupVaultDestroy.IsNull() && !feature[0].DeleteBackupsOnBackupVaultDestroy.IsUnknown() {
f.NetApp.DeleteBackupsOnBackupVaultDestroy = feature[0].DeleteBackupsOnBackupVaultDestroy.ValueBool()
}

f.NetApp.PreventVolumeDestruction = true
if !feature[0].PreventVolumeDestruction.IsNull() && !feature[0].PreventVolumeDestruction.IsUnknown() {
f.NetApp.PreventVolumeDestruction = feature[0].PreventVolumeDestruction.ValueBool()
}

} else {
f.NetApp.DeleteBackupsOnBackupVaultDestroy = false
f.NetApp.PreventVolumeDestruction = true
}
}

p.clientBuilder.Features = f
Expand Down
Loading