-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added terraform HCL integration tests and integrated test execution into CI pipeline. * Removed superfluous comments from tf tests.
- Loading branch information
1 parent
b366831
commit 8ced5a7
Showing
14 changed files
with
340 additions
and
52 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
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,16 @@ | ||
module "blob_storage_policy" { | ||
source = "./modules/backup_policy/blob_storage" | ||
policy_name = "bkpol-${var.vault_name}-blobstorage" | ||
vault_id = azurerm_data_protection_backup_vault.backup_vault.id | ||
retention_period = "P7D" # 7 days | ||
# NOTE - this blob policy has been configured for operational backup | ||
# only, which continuously backs up data and does not need a schedule | ||
} | ||
|
||
module "managed_disk_policy" { | ||
source = "./modules/backup_policy/managed_disk" | ||
policy_name = "bkpol-${var.vault_name}-manageddisk" | ||
vault_id = azurerm_data_protection_backup_vault.backup_vault.id | ||
retention_period = "P7D" # 7 days | ||
backup_intervals = ["R/2024-01-01T00:00:00+00:00/P1D"] # Once per day at 00:00 | ||
} |
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,11 @@ | ||
resource "azurerm_data_protection_backup_vault" "backup_vault" { | ||
name = "bvault-${var.vault_name}" | ||
resource_group_name = azurerm_resource_group.resource_group.name | ||
location = var.vault_location | ||
datastore_type = "VaultStore" | ||
redundancy = var.vault_redundancy | ||
soft_delete = "Off" | ||
identity { | ||
type = "SystemAssigned" | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
infrastructure/modules/backup_policy/blob_storage/output.tf
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 |
---|---|---|
@@ -1,3 +1,15 @@ | ||
output "id" { | ||
value = azurerm_data_protection_backup_policy_blob_storage.backup_policy.id | ||
} | ||
|
||
output "name" { | ||
value = azurerm_data_protection_backup_policy_blob_storage.backup_policy.name | ||
} | ||
|
||
output "vault_id" { | ||
value = azurerm_data_protection_backup_policy_blob_storage.backup_policy.vault_id | ||
} | ||
|
||
output "retention_period" { | ||
value = azurerm_data_protection_backup_policy_blob_storage.backup_policy.operational_default_retention_duration | ||
} |
16 changes: 16 additions & 0 deletions
16
infrastructure/modules/backup_policy/managed_disk/output.tf
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 |
---|---|---|
@@ -1,3 +1,19 @@ | ||
output "id" { | ||
value = azurerm_data_protection_backup_policy_disk.backup_policy.id | ||
} | ||
|
||
output "name" { | ||
value = azurerm_data_protection_backup_policy_disk.backup_policy.name | ||
} | ||
|
||
output "vault_id" { | ||
value = azurerm_data_protection_backup_policy_disk.backup_policy.vault_id | ||
} | ||
|
||
output "retention_period" { | ||
value = azurerm_data_protection_backup_policy_disk.backup_policy.default_retention_duration | ||
} | ||
|
||
output "backup_intervals" { | ||
value = azurerm_data_protection_backup_policy_disk.backup_policy.backup_repeating_time_intervals | ||
} |
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,4 @@ | ||
resource "azurerm_resource_group" "resource_group" { | ||
location = var.vault_location | ||
name = "rg-nhsbackup-${var.vault_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,5 @@ | ||
mock_resource "azurerm_data_protection_backup_vault" { | ||
defaults = { | ||
id = "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/bvault-testvault" | ||
} | ||
} |
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,78 @@ | ||
mock_provider "azurerm" { | ||
source = "./azurerm" | ||
} | ||
|
||
run "setup_tests" { | ||
module { | ||
source = "./setup" | ||
} | ||
} | ||
|
||
run "create_blob_storage_policy" { | ||
command = apply | ||
|
||
module { | ||
source = "../../infrastructure" | ||
} | ||
|
||
variables { | ||
vault_name = run.setup_tests.vault_name | ||
} | ||
|
||
assert { | ||
condition = length(module.blob_storage_policy.id) > 0 | ||
error_message = "Blob storage policy id not as expected." | ||
} | ||
|
||
assert { | ||
condition = module.blob_storage_policy.name == "bkpol-${var.vault_name}-blobstorage" | ||
error_message = "Blob storage policy name not as expected." | ||
} | ||
assert { | ||
condition = module.blob_storage_policy.vault_id == azurerm_data_protection_backup_vault.backup_vault.id | ||
error_message = "Blob storage policy vault id not as expected." | ||
} | ||
assert { | ||
condition = module.blob_storage_policy.retention_period == "P7D" | ||
error_message = "Blob storage policy retention period not as expected." | ||
} | ||
} | ||
run "create_managed_disk_policy" { | ||
command = apply | ||
|
||
module { | ||
source = "../../infrastructure" | ||
} | ||
|
||
variables { | ||
vault_name = run.setup_tests.vault_name | ||
} | ||
|
||
assert { | ||
condition = length(module.managed_disk_policy.id) > 0 | ||
error_message = "Managed disk policy id not as expected." | ||
} | ||
|
||
assert { | ||
condition = module.managed_disk_policy.name == "bkpol-${var.vault_name}-manageddisk" | ||
error_message = "Managed disk policy name not as expected." | ||
} | ||
assert { | ||
condition = module.managed_disk_policy.vault_id == azurerm_data_protection_backup_vault.backup_vault.id | ||
error_message = "Managed disk policy vault id not as expected." | ||
} | ||
assert { | ||
condition = module.managed_disk_policy.retention_period == "P7D" | ||
error_message = "Managed disk policy retention period not as expected." | ||
} | ||
assert { | ||
condition = can(module.managed_disk_policy.backup_intervals) && length(module.managed_disk_policy.backup_intervals) == 1 && module.managed_disk_policy.backup_intervals[0] == "R/2024-01-01T00:00:00+00:00/P1D" | ||
error_message = "Managed disk policy backup intervals not as expected." | ||
} | ||
} |
Oops, something went wrong.