-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom support for File Share Protected Items (#3809)
Resolves #1420 The [recoveryservices.ProtectedItem](https://www.pulumi.com/registry/packages/azure-native/api-docs/recoveryservices/protecteditem/) represents a resource that's backed up via Azure Backup Service (which confusingly has the namespace Microsoft.RecoveryServices). ProtectedItem is a sort of union type with one member per Azure resource that can be protected, e.g., AzureVmWorkloadProtectedItem. One of these types, AzureFileshareProtectedItem, is special in that it requires a file share name as input that's _not_ the name of the file share as given by the user and as shown by the portal, but an internal "system name". Therefore, attempting to use AzureFileshareProtectedItem in the standard way is not possible, because for file share "Foo", `"protectedItemName": "Foo"` will not work. Instead, we need to look up the system name for the user-visible name "Foo" first, and use it instead.
- Loading branch information
Showing
16 changed files
with
772 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: recoveryservices-protecteditem | ||
description: A minimal Azure Native TypeScript Pulumi program | ||
runtime: | ||
name: nodejs | ||
options: | ||
packagemanager: yarn | ||
config: | ||
pulumi:tags: | ||
value: | ||
pulumi:template: azure-typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
import * as recoveryservices from '@pulumi/azure-native/recoveryservices/v20240101'; | ||
import * as recoveryservicesTypes from '@pulumi/azure-native/types'; | ||
import * as resources from '@pulumi/azure-native/resources'; | ||
import * as storage from '@pulumi/azure-native/storage'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
|
||
const resourceGroup = new resources.ResourceGroup('resourceGroup'); | ||
|
||
const storageAccount = new storage.StorageAccount('recoverysa', { | ||
resourceGroupName: resourceGroup.name, | ||
location: resourceGroup.location, | ||
kind: 'StorageV2', | ||
sku: { | ||
name: 'Standard_LRS', | ||
}, | ||
publicNetworkAccess: 'Enabled', | ||
}); | ||
|
||
const vault = new recoveryservices.Vault('vault', { | ||
identity: { | ||
type: 'SystemAssigned', | ||
}, | ||
location: resourceGroup.location, | ||
properties: { | ||
publicNetworkAccess: 'Enabled', | ||
securitySettings: { | ||
softDeleteSettings: { | ||
// Deleting the vault is not allowed with soft delete enabled. | ||
// BUT: setting these to "Disabled" seems to have no effect as of 2025-01, though. Deleted items in | ||
// the vault are still soft-deleted. #3832 | ||
softDeleteState: recoveryservices.SoftDeleteState.Disabled, | ||
enhancedSecurityState: recoveryservices.EnhancedSecurityState.Disabled, | ||
} | ||
}, | ||
}, | ||
resourceGroupName: resourceGroup.name, | ||
sku: { | ||
name: 'Standard', | ||
}, | ||
}, { | ||
// This dependency isn't required for creation of the resources but for deletion order. The storage account is | ||
// locked as long as backup protection is active. | ||
dependsOn: [storageAccount], | ||
}); | ||
|
||
const protectionPolicy = new recoveryservices.ProtectionPolicy('protectionPolicy', { | ||
location: resourceGroup.location, | ||
resourceGroupName: resourceGroup.name, | ||
vaultName: vault.name, | ||
properties: { | ||
backupManagementType: recoveryservices.BackupManagementType.AzureStorage, | ||
schedulePolicy: { | ||
schedulePolicyType: 'SimpleSchedulePolicy', | ||
scheduleRunFrequency: recoveryservices.ScheduleRunType.Daily, | ||
scheduleRunTimes: ['2024-10-08T19:30:00Z'], | ||
}, | ||
retentionPolicy: { | ||
retentionPolicyType: 'LongTermRetentionPolicy', | ||
dailySchedule: { | ||
retentionDuration: { | ||
count: 1, | ||
durationType: recoveryservices.RetentionDurationType.Days, | ||
}, | ||
retentionTimes: ['2024-10-08T19:30:00Z'], | ||
}, | ||
}, | ||
timeZone: 'GTB Standard Time', | ||
workLoadType: recoveryservices.WorkloadType.AzureFileShare, | ||
} // as recoveryservicesTypes.input.recoveryservices.AzureFileShareProtectionPolicyArgs, | ||
}, { | ||
// This dependency isn't required for creation of the resources but for deletion order. | ||
// The protection policy must be deleted before the storage account. | ||
dependsOn: [storageAccount], | ||
}); | ||
|
||
const protectionContainer = new recoveryservices.ProtectionContainer("exampleProtectionContainer", { | ||
resourceGroupName: resourceGroup.name, | ||
vaultName: vault.name, | ||
containerName: pulumi.interpolate`storagecontainer;storage;${resourceGroup.name};${storageAccount.name}`, | ||
fabricName: "Azure", | ||
properties: { | ||
friendlyName: "exampleContainer", | ||
containerType: "StorageContainer", | ||
backupManagementType: recoveryservices.BackupManagementType.AzureStorage, | ||
sourceResourceId: storageAccount.id, | ||
}, | ||
}); | ||
|
||
const fileShare = new storage.FileShare('fileshare', { | ||
accountName: storageAccount.name, | ||
accessTier: 'TransactionOptimized', | ||
resourceGroupName: resourceGroup.name, | ||
}, { | ||
deletedWith: storageAccount, | ||
}); | ||
|
||
// Enable backup for Azure File Share (Protected Item) | ||
const protectedItem = new recoveryservices.ProtectedItem('protectedItem', { | ||
containerName: protectionContainer.name, | ||
fabricName: 'Azure', | ||
properties: { | ||
policyId: protectionPolicy.id, | ||
protectedItemType: 'AzureFileShareProtectedItem', | ||
softDeleteRetentionPeriodInDays: 1, | ||
sourceResourceId: storageAccount.id, | ||
}, // as recoveryservicesTypes.input.recoveryservices.AzureFileshareProtectedItemArgs, | ||
protectedItemName: fileShare.name, | ||
resourceGroupName: resourceGroup.name, | ||
vaultName: vault.name, | ||
}); | ||
|
||
export const vaultId = vault.id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "recoveryservices-protecteditem", | ||
"main": "index.ts", | ||
"devDependencies": { | ||
"@types/node": "^18", | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/azure-native": "^2.0.0", | ||
"@pulumi/pulumi": "^3.113.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.