diff --git a/GNUmakefile b/GNUmakefile index b36b1bfb409a7..5f8d74af571a9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -104,7 +104,7 @@ testacc: fmtcheck TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout $(TESTTIMEOUT) -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc" acctests: fmtcheck - TF_ACC=1 go test -v ./azurerm/internal/services/$(SERVICE)/tests/ $(TESTARGS) -timeout $(TESTTIMEOUT) -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc" + TF_ACC=1 go test -v ./azurerm/internal/services/$(SERVICE)/ $(TESTARGS) -timeout $(TESTTIMEOUT) -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc" debugacc: fmtcheck TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS) diff --git a/azurerm/internal/services/recoveryservices/backup_protected_file_share_resource_test.go b/azurerm/internal/services/recoveryservices/backup_protected_file_share_resource_test.go index 09e4cebbaf3c6..0b5f64a1c5fed 100644 --- a/azurerm/internal/services/recoveryservices/backup_protected_file_share_resource_test.go +++ b/azurerm/internal/services/recoveryservices/backup_protected_file_share_resource_test.go @@ -37,6 +37,30 @@ func TestAccAzureRMBackupProtectedFileShare_basic(t *testing.T) { }) } +func TestAccAzureRMBackupProtectedFileShare_multiple(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_backup_protected_file_share", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMBackupProtectedFileShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMBackupProtectedFileShare_multiple(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMBackupProtectedFileShareExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + ), + }, + data.ImportStep(), + { + // vault cannot be deleted unless we unregister all backups + Config: testAccAzureRMBackupProtectedFileShare_baseMultiple(data), + }, + }, + }) +} + func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_backup_protected_file_share", "test") @@ -240,6 +264,71 @@ resource "azurerm_backup_policy_file_share" "test1" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } +func testAccAzureRMBackupProtectedFileShare_baseMultiple(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-backup-%[1]d" + location = "%[2]s" +} + +resource "azurerm_storage_account" "test" { + name = "acctest%[3]s" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_share" "testshare1" { + name = "acctest-ss-%[1]d-1" + storage_account_name = "${azurerm_storage_account.test.name}" + metadata = {} + + lifecycle { + ignore_changes = [metadata] // Ignore changes Azure Backup makes to the metadata + } +} + +resource "azurerm_storage_share" "testshare2" { + name = "acctest-ss-%[1]d-2" + storage_account_name = "${azurerm_storage_account.test.name}" + metadata = {} + + lifecycle { + ignore_changes = [metadata] // Ignore changes Azure Backup makes to the metadata + } + } + +resource "azurerm_recovery_services_vault" "test" { + name = "acctest-VAULT-%[1]d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Standard" + + soft_delete_enabled = false +} + +resource "azurerm_backup_policy_file_share" "test1" { + name = "acctest-PFS-%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + + backup { + frequency = "Daily" + time = "23:00" + } + + retention_daily { + count = 10 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + func testAccAzureRMBackupProtectedFileShare_basic(data acceptance.TestData) string { template := testAccAzureRMBackupProtectedFileShare_base(data) return fmt.Sprintf(` @@ -261,6 +350,27 @@ resource "azurerm_backup_protected_file_share" "test" { `, template) } +func testAccAzureRMBackupProtectedFileShare_multiple(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedFileShare_baseMultiple(data) + return fmt.Sprintf(` +%s + +resource "azurerm_backup_container_storage_account" "test" { + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + storage_account_id = azurerm_storage_account.test.id +} + +resource "azurerm_backup_protected_file_share" "test" { + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_storage_account_id = azurerm_backup_container_storage_account.test.storage_account_id + source_file_share_name = azurerm_storage_share.testshare2.name + backup_policy_id = azurerm_backup_policy_file_share.test1.id +} +`, template) +} + func testAccAzureRMBackupProtectedFileShare_updatePolicy(data acceptance.TestData) string { template := testAccAzureRMBackupProtectedFileShare_base(data) return fmt.Sprintf(`