forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource_arm_storage_account_blob_settings_test.go
125 lines (108 loc) · 4.16 KB
/
resource_arm_storage_account_blob_settings_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package azurerm
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func TestAccAzureRMStorageAccountBlobSettings_basic(t *testing.T) {
resourceName := "azurerm_storage_account_blob_settings.testsabs"
storageAccountResourceName := "azurerm_storage_account.testsa"
ri := tf.AccRandTimeInt()
rs := acctest.RandString(4)
location := testLocation()
createConfig := testAccAzureRMStorageAccountBlobSettings_basic(ri, rs, location)
updateConfig := testAccAzureRMStorageAccountBlobSettings_update(ri, rs, location)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageAccountBlobSettingsDestroy,
Steps: []resource.TestStep{
{
Config: createConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(storageAccountResourceName),
resource.TestCheckResourceAttr(resourceName, "enable_soft_delete", "true"),
resource.TestCheckResourceAttr(resourceName, "soft_delete_retention_days", "123"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: updateConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(storageAccountResourceName),
resource.TestCheckResourceAttr(resourceName, "enable_soft_delete", "true"),
resource.TestCheckResourceAttr(resourceName, "soft_delete_retention_days", "99"),
),
},
},
})
}
func testAccAzureRMStorageAccountBlobSettings_basic(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
name = "acctestAzureRMSABS-%d"
location = "%s"
}
resource "azurerm_storage_account" "testsa" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "${azurerm_resource_group.testrg.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_account_blob_settings" "testsabs" {
resource_group_name = "${azurerm_resource_group.testrg.name}"
storage_account_name = "${azurerm_storage_account.testsa.name}"
enable_soft_delete = true
soft_delete_retention_days = 123
}
`, rInt, location, rString)
}
func testAccAzureRMStorageAccountBlobSettings_update(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
name = "acctestAzureRMSABS-%d"
location = "%s"
}
resource "azurerm_storage_account" "testsa" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "${azurerm_resource_group.testrg.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_account_blob_settings" "testsabs" {
resource_group_name = "${azurerm_resource_group.testrg.name}"
storage_account_name = "${azurerm_storage_account.testsa.name}"
enable_soft_delete = true
soft_delete_retention_days = 99
}
`, rInt, location, rString)
}
func testCheckAzureRMStorageAccountBlobSettingsDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).storageBlobServicesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_storage_account_blob_settings" {
continue
}
storageAccountName := rs.Primary.Attributes["storage_account_name"]
resourceGroupName := rs.Primary.Attributes["resource_group_name"]
resp, err := client.GetServiceProperties(ctx, resourceGroupName, storageAccountName)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Storage Account Blob Settings still exist:\n%#v", resp.BlobServicePropertiesProperties)
}
return nil
}
}
return nil
}