diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 52779d4..75eef12 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,140 @@ -# terraform-aws-template +# Azure Backup Terraform module -[![Lint Status](https://github.com/tothenew/terraform-aws-template/workflows/Lint/badge.svg)](https://github.com/tothenew/terraform-aws-template/actions) -[![LICENSE](https://img.shields.io/github/license/tothenew/terraform-aws-template)](https://github.com/tothenew/terraform-aws-template/blob/master/LICENSE) +[![Lint Status](https://github.com/tothenew/terraform-azure-rsv/workflows/Lint/badge.svg)](https://github.com/tothenew/terraform-azure-rsv/actions) +[![LICENSE](https://img.shields.io/github/license/tothenew/terraform-azure-rsv)](https://github.com/tothenew/terraform-azure-rsv/blob/master/LICENSE) -This is a template to use for baseline. The default actions will provide updates for section bitween Requirements and Outputs. +Take advantage of fully managed backup of virtual machines and storage accounts in the cloud. -The following content needed to be created and managed: - - Introduction - - Explaination of module - - Intended users - - Resource created and managed by this module - - Example Usages +Azure Backup provides independent and isolated backups to guard against unintended destruction of the data on your VMs. Backups are stored in a Recovery Services vault with built-in management of recovery points. Configuration and scaling are simple, backups are optimized, and you can easily restore as needed. + +# Workflow of this module + +Two child modules, storage-backup and vm-backup, are located in the example folder of this module. Therefore, you must execute only storage-backup if you only want to create storage account backups, and you must run the vm-backup module in the example folder if you only want to produce VM backups. + +## vm-backup module + +```hcl +# Azurerm Provider configuration +provider "azurerm" { + features {} +} + +module "azure-backup" { + source = "../../" + + # Name of the azure file sync instance (default "backup") + name = "backup" + + create_resource_group = false + + resource_group_name = "Deepak" + + location = "Central India" + + # (Optional) Prefix to use for all resoruces created (Defaults to resource_group_name) + resource_prefix = "vm-backup" + + # (Optional) Indicates the name of recovery services vault to be created + recovery_services_vault_name = "rsv" + + # (Optional) Indicates the sku for the recovery services value to use during creation + recovery_services_vault_sku = "Standard" + + # (Optional) Indicates which version type to use when creating the backup policy + backup_policy_type = "V1" + + # (Optional) Indicate the fequency to use for the backup policy + backup_policy_frequency = "Daily" + + # (Optional) Indicates the time for when to execute the backup policy + backup_policy_time = "23:00" + + # (Optional) Indicates the number of daily backups to retain (set to blank to disable) + backup_policy_retention_daily_count = 7 + + # (Optional) Indicates the number of weekly backups to retain (set to blank to disable) + backup_polcy_retention_weekly_count = 4 + + # (Optional) Indicates the number of monthly backups to retain (set to blank to disable) + backup_polcy_retention_monthly_count = 6 + + create_vm_backup = true + + backup_virtual_machines = [ + { + name = "demovm" + resource_group_name = "Deepak" + os_type = "Linux" + } + ] +} + +``` + +## storage-backup module + +```hcl +# Azurerm Provider configuration +provider "azurerm" { + features {} +} + +module "azure-backup" { + source = "../../" + + # Name of the azure file sync instance (default "backup") + name = "backup" + + create_resource_group = false + + resource_group_name = "Deepak" + + location = "Central India" + + # (Optional) Prefix to use for all resoruces created (Defaults to resource_group_name) + resource_prefix = "storage-backup" + + # (Optional) Indicates the name of recovery services vault to be created + recovery_services_vault_name = "rsv" + + # (Optional) Indicates the sku for the recovery services value to use during creation + recovery_services_vault_sku = "Standard" + + # (Optional) Indicate the fequency to use for the backup policy + backup_policy_frequency = "Daily" + + # (Optional) Indicates the time for when to execute the backup policy + backup_policy_time = "23:00" + + # (Optional) Indicates the number of daily backups to retain (set to blank to disable) + backup_policy_retention_daily_count = 7 + + # (Optional) Indicates the number of weekly backups to retain (set to blank to disable) + backup_polcy_retention_weekly_count = 4 + + # (Optional) Indicates the number of monthly backups to retain (set to blank to disable) + backup_polcy_retention_monthly_count = 6 + + create_file_share_backup = true + + backup_file_shares = [ + { + name = "demotesting01b3bb" + resource_group_name = "Deepak" + storage_account_name = "deepak8754" + } + ] +} + +``` + + +## Create resource group + +By default, this module will create a resource group and the name of the resource group to be given in an argument `resource_group_name`. If you want to use an existing resource group, specify the existing resource group name, and set the argument to `create_resource_group = false`. + +> *If you are using an existing resource group, then this module uses the same resource group location to create all resources in this module.* - ## Requirements | Name | Version | @@ -21,29 +143,59 @@ The following content needed to be created and managed: ## Providers -No providers. - -## Modules - -No modules. - -## Resources - -No resources. +| Name | Version | +|------|---------| +| [azurerm](#requirement\_terraform) | >= 3.39.0 | ## Inputs -No inputs. +Name | Description | Type | Default +---- | ----------- | ---- | ------- +`name` | Name of the azure file storage instance | `string` | `filestorage` +`create_resource_group` | Whether to create resource group and use it for all networking resources | `boolean` | `true` +`resource_group_name` | A container that holds related resources for an Azure solution | `string` | `rg-filestorage` +`location` | The location/region to keep all your network resources. To get the list of all locations with table format from azure cli, run 'az account list-locations -o table' | `string` | `eastus2` +`resource_prefix` | (Optional) Prefix to use for all resoruces created (Defaults to resource_group_name) | `string` | `` +`recovery_services_vault_name` | (Optional) Indicates the name of recovery services vault to be created | `string` | `` +`recovery_services_vault_sku` | (Optional) Indicates the sku for the recovery services value to use during creation | `string` | `Standard` +`backup_policy_type` | (Optional) Indicates which version type to use when creating the backup policy | `string` | `V2` +`backup_policy_frequency` | (Optional) Indicate the fequency to use for the backup policy | `string` | `Daily` +`backup_policy_time` | (Optional) Indicates the time for when to execute the backup policy | `string` | `23:00` +`backup_policy_retention_daily_count` | (Optional) Indicates the number of daily backups to retain (set to blank to disable) | `string` | `7` +`backup_polcy_retention_weekly_count` | (Optional) Indicates the number of weekly backups to retain (set to blank to disable) | `string` | `4` +`backup_policy_retention_weekly_weekdays` | (Optional) Indicates which days of the week the monthly backup will be taken | `set(string)` | `[ "Saturday" ]` +`backup_polcy_retention_monthly_count` | (Optional) Indicates the number of monthly backups to retain (set to blank to disable) | `string` | `6` +`backup_policy_retention_monthly_weekdays` | (Optional) Indicates which days of the week the monthly backup will be taken | `set(string)` | `[ "Saturday" ]` +`default_tags` | A map of default tags to add to all resources | `map(string)` | `{}` +`common_tags` | A map of common tags to add to all resources | `map(string)` | `{}` ## Outputs -No outputs. - +Name | Description +---- | ----------- +`resource_group_name` | The name of the resource group in which resources are created +`resource_group_id` | The id of the resource group in which resources are created +`resource_group_location` | The location of the resource group in which resources are created +`azurerm_backup_policy_vm_id` | The id of the backup policy +`azurerm_backup_protected_vm_id` | The id of the backup protected vm resource +`azurerm_recovery_services_vault_id` | The id of the recover services vault +`azurerm_recovery_services_vault_name` | The name of the recover services vault +`azurerm_backup_protected_vm_ids` | The id of the backup protected vm + + ## Authors Module managed by [TO THE NEW Pvt. Ltd.](https://github.com/tothenew) + ## License -Apache 2 Licensed. See [LICENSE](https://github.com/tothenew/terraform-aws-template/blob/main/LICENSE) for full details. +Apache 2 Licensed. See [LICENSE](https://github.com/tothenew/terraform-azure-rsv/blob/main/LICENSE) for full details. + + + +## Other resources + +* [Azure Backup](https://azure.microsoft.com/en-us/products/backup/#overview) +* [Terraform AzureRM Provider Documentation](https://www.terraform.io/docs/providers/azurerm/index.html) \ No newline at end of file diff --git a/_data.tf b/_data.tf new file mode 100644 index 0000000..8283ece --- /dev/null +++ b/_data.tf @@ -0,0 +1,19 @@ +data "azurerm_resource_group" "rgrp" { + count = var.create_resource_group == false ? 1 : 0 + name = var.resource_group_name +} + +data "azurerm_virtual_machine" "vm" { + for_each = local.virtual_machines + + name = each.value.vm.name + resource_group_name = each.value.vm.resource_group_name != "" ? each.value.vm.resource_group_name : local.resource_group_name +} + +data "azurerm_storage_account" "storage_backup" { + for_each = local.file_shares + + name = each.value.file_share.storage_account_name + resource_group_name = each.value.file_share.resource_group_name +} + diff --git a/_locals.tf b/_locals.tf new file mode 100644 index 0000000..91298b6 --- /dev/null +++ b/_locals.tf @@ -0,0 +1,25 @@ +locals { + name = var.name == "" ? "-backup" : "-${var.name}" + resource_group_name = element(coalescelist(data.azurerm_resource_group.rgrp.*.name, azurerm_resource_group.rg.*.name, [""]), 0) + resource_prefix = var.resource_prefix == "" ? local.resource_group_name : var.resource_prefix + location = element(coalescelist(data.azurerm_resource_group.rgrp.*.location, azurerm_resource_group.rg.*.location, [""]), 0) + common_tags = length(var.common_tags) == 0 ? var.default_tags : merge(var.default_tags, var.common_tags) + + virtual_machines = { + for idx, vm in var.backup_virtual_machines : vm.name => { + idx : idx, + vm : vm, + } + } + + file_shares = { + for idx, fs in var.backup_file_shares : fs.name => { + idx : idx + file_share : fs + } + } + + timeout_create = "180m" + timeout_delete = "60m" + timeout_read = "60m" +} \ No newline at end of file diff --git a/_outputs.tf b/_outputs.tf new file mode 100644 index 0000000..ce4f67e --- /dev/null +++ b/_outputs.tf @@ -0,0 +1,35 @@ +output "resource_group_name" { + description = "The name of the resource group in which resources are created" + value = element(coalescelist(data.azurerm_resource_group.rgrp.*.name, azurerm_resource_group.rg.*.name, [""]), 0) +} + +output "resource_group_id" { + description = "The id of the resource group in which resources are created" + value = element(coalescelist(data.azurerm_resource_group.rgrp.*.id, azurerm_resource_group.rg.*.id, [""]), 0) +} + +output "resource_group_location" { + description = "The location of the resource group in which resources are created" + value = element(coalescelist(data.azurerm_resource_group.rgrp.*.location, azurerm_resource_group.rg.*.location, [""]), 0) +} + +# Vnet and Subnets +output "azurerm_backup_policy_vm_id" { + description = "The id of the backup policy" + value = element(concat(resource.azurerm_backup_policy_vm.policy.*.id, [""]), 0) +} + +output "azurerm_backup_protected_vm_ids" { + description = "The ids of the backup protected vm resource" + value = values(resource.azurerm_backup_protected_vm.vm).*.id +} + +output "azurerm_recovery_services_vault_id" { + description = "The id of the recover services vault" + value = element(concat(resource.azurerm_recovery_services_vault.vault.*.id, [""]), 0) +} + +output "azurerm_recovery_services_vault_name" { + description = "The name of the recover services vault" + value = element(concat(resource.azurerm_recovery_services_vault.vault.*.name, [""]), 0) +} diff --git a/_variables.tf b/_variables.tf new file mode 100644 index 0000000..49fdf91 --- /dev/null +++ b/_variables.tf @@ -0,0 +1,161 @@ +variable "name" { + description = "Name of the azure file storage instance" + default = "backup" +} + +variable "create_resource_group" { + description = "Whether to create resource group and use it for all resources" + default = true +} + +variable "resource_group_name" { + description = "A container that holds related resources for an Azure solution" + default = "" +} + +variable "location" { + description = "The location/region to keep all your network resources. To get the list of all locations with table format from azure cli, run 'az account list-locations -o table'" + default = "eastus2" +} + +variable "resource_prefix" { + description = "(Optional) Prefix to use for all resoruces created (Defaults to resource_group_name)" + default = "" +} + +variable "recovery_services_vault_name" { + description = "(Optional) Indicates the name of recovery services vault to be created" + default = "" +} + +variable "recovery_services_vault_sku" { + description = "(Optional) Indicates the sku for the recovery services value to use during creation" + default = "Standard" +} + +variable "recovery_services_vault_storage_mode" { + description = "(Optional) Indicates the mode for the recovery storage vault" + default = "LocallyRedundant" + + # validation { + # condition = contains(["LocallyRedundant"], var.recovery_services_vault_storage_mode) + # error_message = "The value must be set to one of the following: LocallyRedundant" + # } +} + +variable "backup_policy_type" { + description = "(Optional) Indicates which version type to use when creating the backup policy" + default = "V2" + + # validation { + # condition = contains(["V1","V2"], var.backup_policy_type) + # error_message = "The value must be set to one of the following: V1, V2" + # } +} + +variable "backup_policy_time_zone" { + description = "(Optional) Indicates the timezone that the policy will use" + default = "UTC" +} + +variable "backup_policy_frequency" { + description = "(Optional) Indicate the fequency to use for the backup policy" + default = "Daily" + + # validation { + # condition = contains(["Daily"], var.backup_policy_frequency) + # error_message = "The value must be set to one of the following: Daily" + # } +} + +variable "backup_policy_time" { + description = "(Optional) Indicates the time for when to execute the backup policy" + default = "23:00" +} + +variable "backup_policy_retention_daily_count" { + description = "(Optional) Indicates the number of daily backups to retain (set to blank to disable)" + type = number + default = 7 +} + +variable "backup_polcy_retention_weekly_count" { + description = "(Optional) Indicates the number of weekly backups to retain (set to blank to disable)" + type = number + default = 4 +} + +variable "backup_policy_retention_weekly_weekdays" { + description = "(Optional) Indicates which days of the week the weekly backup will be taken" + type = set(string) + default = [ "Saturday" ] + + # validation { + # condition = can([for s in var.backup_policy_retention_weekly_weekdays : contains([ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ], s)]) + # error_message = "The value must contain one of the following: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday" + # } +} + +variable "backup_polcy_retention_monthly_count" { + description = "(Optional) Indicates the number of monthly backups to retain (set to blank to disable)" + type = number + default = 6 +} + +variable "backup_policy_retention_monthly_weekdays" { + description = "(Optional) Indicates which days of the week the monthly backup will be taken" + type = set(string) + default = [ "Saturday" ] + + # validation { + # condition = can([for s in var.backup_policy_retention_monthly_weekdays : contains([ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ], s)]) + # error_message = "The value must contain one of the following: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday" + # } +} + +variable "backup_virtual_machines" { + description = "Contains the list virtual machines that will be backed up" + type = list(object({ + name = string + resource_group_name = string + os_type = string + })) + default = [] +} + +variable "backup_file_shares" { + description = "Contains the list file shares that will be backed up" + type = list(object({ + name = string + storage_account_name = string + resource_group_name = string + })) + default = [] +} + +variable "default_tags" { + type = map(string) + description = "A map to add common tags to all the resources" + default = { + "Scope" : "Module" + "CreatedBy" : "deepak" + } +} + +variable "common_tags" { + type = map(string) + description = "A map to add common tags to all the resources" + default = {} +} + +variable "create_vm_backup" { + description = "Set to true to create VM backup resources" + type = bool + default = false +} + +variable "create_file_share_backup" { + description = "Set to true to create file share backup resources" + type = bool + default = false +} \ No newline at end of file diff --git a/example/storage-backup/main.tf b/example/storage-backup/main.tf new file mode 100644 index 0000000..4323056 --- /dev/null +++ b/example/storage-backup/main.tf @@ -0,0 +1,51 @@ +# Azurerm Provider configuration +provider "azurerm" { + features {} +} + +module "azure-backup" { + source = "../../" + + # Name of the azure file sync instance (default "backup") + name = "backup" + + create_resource_group = false + + resource_group_name = "Deepak" + + location = "Central India" + + # (Optional) Prefix to use for all resoruces created (Defaults to resource_group_name) + resource_prefix = "storage-backup" + + # (Optional) Indicates the name of recovery services vault to be created + recovery_services_vault_name = "rsv" + + # (Optional) Indicates the sku for the recovery services value to use during creation + recovery_services_vault_sku = "Standard" + + # (Optional) Indicate the fequency to use for the backup policy + backup_policy_frequency = "Daily" + + # (Optional) Indicates the time for when to execute the backup policy + backup_policy_time = "23:00" + + # (Optional) Indicates the number of daily backups to retain (set to blank to disable) + backup_policy_retention_daily_count = 7 + + # (Optional) Indicates the number of weekly backups to retain (set to blank to disable) + backup_polcy_retention_weekly_count = 4 + + # (Optional) Indicates the number of monthly backups to retain (set to blank to disable) + backup_polcy_retention_monthly_count = 6 + + create_file_share_backup = true + + backup_file_shares = [ + { + name = "demotesting01b3bb" + resource_group_name = "Deepak" + storage_account_name = "deepak8754" + } + ] +} \ No newline at end of file diff --git a/example/storage-backup/output.tf b/example/storage-backup/output.tf new file mode 100644 index 0000000..57e591f --- /dev/null +++ b/example/storage-backup/output.tf @@ -0,0 +1,4 @@ +output "azure_bastion_subnet_id" { + description = "Output" + value = module.azure-backup +} \ No newline at end of file diff --git a/example/vm-backup/main.tf b/example/vm-backup/main.tf new file mode 100644 index 0000000..d0557cd --- /dev/null +++ b/example/vm-backup/main.tf @@ -0,0 +1,54 @@ +# Azurerm Provider configuration +provider "azurerm" { + features {} +} + +module "azure-backup" { + source = "../../" + + # Name of the azure file sync instance (default "backup") + name = "backup" + + create_resource_group = false + + resource_group_name = "Deepak" + + location = "Central India" + + # (Optional) Prefix to use for all resoruces created (Defaults to resource_group_name) + resource_prefix = "vm-backup" + + # (Optional) Indicates the name of recovery services vault to be created + recovery_services_vault_name = "rsv" + + # (Optional) Indicates the sku for the recovery services value to use during creation + recovery_services_vault_sku = "Standard" + + # (Optional) Indicates which version type to use when creating the backup policy + backup_policy_type = "V1" + + # (Optional) Indicate the fequency to use for the backup policy + backup_policy_frequency = "Daily" + + # (Optional) Indicates the time for when to execute the backup policy + backup_policy_time = "23:00" + + # (Optional) Indicates the number of daily backups to retain (set to blank to disable) + backup_policy_retention_daily_count = 7 + + # (Optional) Indicates the number of weekly backups to retain (set to blank to disable) + backup_polcy_retention_weekly_count = 4 + + # (Optional) Indicates the number of monthly backups to retain (set to blank to disable) + backup_polcy_retention_monthly_count = 6 + + create_vm_backup = true + + backup_virtual_machines = [ + { + name = "demovm" + resource_group_name = "Deepak" + os_type = "Linux" + } + ] +} \ No newline at end of file diff --git a/example/vm-backup/output.tf b/example/vm-backup/output.tf new file mode 100644 index 0000000..57e591f --- /dev/null +++ b/example/vm-backup/output.tf @@ -0,0 +1,4 @@ +output "azure_bastion_subnet_id" { + description = "Output" + value = module.azure-backup +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..d7eb824 --- /dev/null +++ b/main.tf @@ -0,0 +1,160 @@ +resource "azurerm_resource_group" "rg" { + count = var.create_resource_group ? 1 : 0 + name = var.resource_group_name + location = var.location + + tags = merge(local.common_tags, tomap({ + "Env" : "Dev" + })) +} + +#------------------------------------- +## Recovery Services +#------------------------------------- + +resource "azurerm_recovery_services_vault" "vault" { + name = var.recovery_services_vault_name != "" ? var.recovery_services_vault_name : "${local.resource_prefix}-bvault" + location = var.location + resource_group_name = local.resource_group_name + sku = var.recovery_services_vault_sku != null ? var.recovery_services_vault_sku : "Standard" + storage_mode_type = var.recovery_services_vault_storage_mode != null ? var.recovery_services_vault_storage_mode : "LocallyRedundant" + + #cross_region_restore_enabled = var.recovery_servuces_vault_cross_region_restore_enabled + + tags = merge(local.common_tags, tomap({ + "Env" : "Dev" + })) +} + + +#------------------------------------- +## Backup Policy +#------------------------------------- + +resource "azurerm_backup_policy_vm" "policy" { + count = var.create_vm_backup ? 1 : 0 + name = "${local.resource_prefix}-bkpool-vms" + resource_group_name = local.resource_group_name + recovery_vault_name = azurerm_recovery_services_vault.vault.name + policy_type = var.backup_policy_type != null ? var.backup_policy_type : "V2" + + timezone = var.backup_policy_time_zone != null ? var.backup_policy_time_zone : "UTC" + + backup { + frequency = var.backup_policy_frequency != null ? var.backup_policy_frequency : "Daily" + time = var.backup_policy_time != null ? var.backup_policy_time : "23:00" + } + + dynamic "retention_daily" { + for_each = var.backup_policy_retention_daily_count != "" ? [1] : [] + + content { + count = var.backup_policy_retention_daily_count + } + } + + dynamic "retention_weekly" { + for_each = var.backup_polcy_retention_weekly_count != "" ? [1] : [] + + content { + count = var.backup_polcy_retention_weekly_count + weekdays = var.backup_policy_retention_weekly_weekdays != null ? var.backup_policy_retention_weekly_weekdays : [ "Saturday" ] + } + } + + dynamic "retention_monthly" { + for_each = var.backup_polcy_retention_monthly_count != "" ? [1] : [] + + content { + count = var.backup_polcy_retention_monthly_count + weekdays = var.backup_policy_retention_monthly_weekdays != null ? var.backup_policy_retention_monthly_weekdays : [ "Saturday" ] + weeks = [ "Last" ] + } + } +} + +resource "azurerm_backup_policy_file_share" "policy" { + count = var.create_file_share_backup ? 1 : 0 + name = "${local.resource_prefix}-bkpool-fileshares" + resource_group_name = local.resource_group_name + recovery_vault_name = azurerm_recovery_services_vault.vault.name + + timezone = var.backup_policy_time_zone != null ? var.backup_policy_time_zone : "UTC" + + backup { + frequency = var.backup_policy_frequency != null ? var.backup_policy_frequency : "Daily" + time = var.backup_policy_time != null ? var.backup_policy_time : "23:00" + } + + dynamic "retention_daily" { + for_each = var.backup_policy_retention_daily_count != "" ? [1] : [] + + content { + count = var.backup_policy_retention_daily_count + } + } + + dynamic "retention_weekly" { + for_each = var.backup_polcy_retention_weekly_count != "" ? [1] : [] + + content { + count = var.backup_polcy_retention_weekly_count + weekdays = var.backup_policy_retention_weekly_weekdays != null ? var.backup_policy_retention_weekly_weekdays : [ "Saturday" ] + } + } + + dynamic "retention_monthly" { + for_each = var.backup_polcy_retention_monthly_count != "" ? [1] : [] + + content { + count = var.backup_polcy_retention_monthly_count + weekdays = var.backup_policy_retention_monthly_weekdays != null ? var.backup_policy_retention_monthly_weekdays : [ "Saturday" ] + weeks = [ "Last" ] + } + } +} + + +#------------------------------------- +## Enable Backups for VMs +#------------------------------------- +resource "azurerm_backup_protected_vm" "vm" { + for_each = var.create_vm_backup ? local.virtual_machines : {} + + resource_group_name = local.resource_group_name + recovery_vault_name = azurerm_recovery_services_vault.vault.name + backup_policy_id = azurerm_backup_policy_vm.policy[0].id + + source_vm_id = data.azurerm_virtual_machine.vm[each.value.vm.name].id +} + +#------------------------------------- +## Enable Backups for File Shares +#------------------------------------- +resource "azurerm_backup_container_storage_account" "container" { + for_each = var.create_file_share_backup ? local.file_shares : {} + + recovery_vault_name = azurerm_recovery_services_vault.vault.name + resource_group_name = local.resource_group_name + + storage_account_id = data.azurerm_storage_account.storage_backup[each.value.file_share.name].id + + depends_on = [ + data.azurerm_storage_account.storage_backup + ] +} + +resource "azurerm_backup_protected_file_share" "share" { + for_each = var.create_file_share_backup ? local.file_shares : {} + + resource_group_name = local.resource_group_name + recovery_vault_name = azurerm_recovery_services_vault.vault.name + backup_policy_id = azurerm_backup_policy_file_share.policy[0].id + + source_storage_account_id = data.azurerm_storage_account.storage_backup[each.value.file_share.name].id + source_file_share_name = each.value.file_share.name + + depends_on = [ + azurerm_backup_container_storage_account.container + ] +} \ No newline at end of file diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..7c0386b --- /dev/null +++ b/provider.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.39.0" + } + } +} + +provider "azurerm" { + features {} +}