Skip to content

Commit

Permalink
acctest for multiple shares
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Dec 21, 2020
1 parent 1728d0e commit b0bde1e
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(`
Expand All @@ -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(`
Expand Down

0 comments on commit b0bde1e

Please sign in to comment.