generated from tothenew/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from deepakttn/azure_backup
Automating Azure VM and Storage Account Backups with Terraform and Recovery Services Vault
- Loading branch information
Showing
12 changed files
with
701 additions
and
24 deletions.
There are no files selected for viewing
Empty file.
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,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 | ||
} | ||
|
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,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" | ||
} |
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,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) | ||
} |
Oops, something went wrong.