Skip to content

Commit 0ff3e90

Browse files
committed
update documents and test
1 parent 67cb25d commit 0ff3e90

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

internal/services/dataprotection/data_protection_backup_instance_data_lake_storage_resource.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import (
1919
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
2020
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
2121
"github.com/hashicorp/terraform-provider-azurerm/internal/services/dataprotection/custompollers"
22+
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
2223
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
2324
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
24-
"github.com/hashicorp/terraform-provider-azurerm/utils"
2525
)
2626

2727
type BackupInstanceDataLakeStorageModel struct {
28-
Name string `tfschema:"name"`
29-
DataProtectionBackupVaultId string `tfschema:"data_protection_backup_vault_id"`
30-
Location string `tfschema:"location"`
31-
BackupPolicyId string `tfschema:"backup_policy_id"`
32-
StorageAccountId string `tfschema:"storage_account_id"`
33-
StorageAccountContainerNames []string `tfschema:"storage_account_container_names"`
34-
ProtectionState string `tfschema:"protection_state"`
28+
Name string `tfschema:"name"`
29+
DataProtectionBackupVaultId string `tfschema:"data_protection_backup_vault_id"`
30+
Location string `tfschema:"location"`
31+
BackupPolicyId string `tfschema:"backup_policy_id"`
32+
StorageAccountId string `tfschema:"storage_account_id"`
33+
StorageContainerNames []string `tfschema:"storage_container_names"`
34+
ProtectionState string `tfschema:"protection_state"`
3535
}
3636

3737
type DataProtectionBackupInstanceDataLakeStorageResource struct{}
@@ -67,12 +67,13 @@ func (r DataProtectionBackupInstanceDataLakeStorageResource) Arguments() map[str
6767

6868
"storage_account_id": commonschema.ResourceIDReferenceRequiredForceNew(&commonids.StorageAccountId{}),
6969

70-
"storage_account_container_names": {
70+
"storage_container_names": {
7171
Type: pluginsdk.TypeList,
7272
Required: true,
7373
MinItems: 1,
7474
Elem: &pluginsdk.Schema{
75-
Type: pluginsdk.TypeString,
75+
Type: pluginsdk.TypeString,
76+
ValidateFunc: storageValidate.StorageContainerName,
7677
},
7778
},
7879
}
@@ -154,7 +155,7 @@ func (r DataProtectionBackupInstanceDataLakeStorageResource) Create() sdk.Resour
154155
PolicyParameters: &backupinstanceresources.PolicyParameters{
155156
BackupDatasourceParametersList: &[]backupinstanceresources.BackupDatasourceParameters{
156157
backupinstanceresources.AdlsBlobBackupDatasourceParameters{
157-
ContainersList: model.StorageAccountContainerNames,
158+
ContainersList: model.StorageContainerNames,
158159
},
159160
},
160161
},
@@ -229,10 +230,10 @@ func (r DataProtectionBackupInstanceDataLakeStorageResource) Read() sdk.Resource
229230
if dataStoreParas := policyParas.BackupDatasourceParametersList; dataStoreParas != nil {
230231
if dsp := pointer.From(dataStoreParas); len(dsp) > 0 {
231232
if parameter, ok := dsp[0].(backupinstanceresources.AdlsBlobBackupDatasourceParameters); ok {
232-
containerNames := utils.FlattenStringSlice(&parameter.ContainersList)
233-
state.StorageAccountContainerNames = make([]string, len(containerNames))
233+
containerNames := parameter.ContainersList
234+
state.StorageContainerNames = make([]string, len(containerNames))
234235
for i, v := range containerNames {
235-
state.StorageAccountContainerNames[i] = v.(string)
236+
state.StorageContainerNames[i] = v
236237
}
237238
}
238239
}
@@ -286,11 +287,11 @@ func (r DataProtectionBackupInstanceDataLakeStorageResource) Update() sdk.Resour
286287
parameters.Properties.PolicyInfo.PolicyId = policyId.ID()
287288
}
288289

289-
if metadata.ResourceData.HasChange("storage_account_container_names") {
290+
if metadata.ResourceData.HasChange("storage_container_names") {
290291
parameters.Properties.PolicyInfo.PolicyParameters = &backupinstanceresources.PolicyParameters{
291292
BackupDatasourceParametersList: &[]backupinstanceresources.BackupDatasourceParameters{
292293
backupinstanceresources.AdlsBlobBackupDatasourceParameters{
293-
ContainersList: model.StorageAccountContainerNames,
294+
ContainersList: model.StorageContainerNames,
294295
},
295296
},
296297
}

internal/services/dataprotection/data_protection_backup_instance_data_lake_storage_resource_test.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ resource "azurerm_storage_container" "test" {
122122
storage_account_id = azurerm_storage_account.test.id
123123
}
124124
125-
resource "azurerm_storage_container" "another" {
126-
name = "testaccsc2%[3]d"
127-
storage_account_id = azurerm_storage_account.test.id
128-
}
129-
130125
resource "azurerm_data_protection_backup_vault" "test" {
131126
name = "acctest-dataprotection-vault-%[1]d"
132127
resource_group_name = azurerm_resource_group.test.name
@@ -152,9 +147,20 @@ resource "azurerm_data_protection_backup_policy_data_lake_storage" "test" {
152147
153148
default_retention_duration = "P4M"
154149
}
150+
`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(8))
151+
}
152+
153+
func (r DataProtectionBackupInstanceDataLakeStorageResource) templateComplete(data acceptance.TestData) string {
154+
return fmt.Sprintf(`
155+
%s
156+
157+
resource "azurerm_storage_container" "another" {
158+
name = "testaccsc2%[2]d"
159+
storage_account_id = azurerm_storage_account.test.id
160+
}
155161
156162
resource "azurerm_data_protection_backup_policy_data_lake_storage" "another" {
157-
name = "acctest-dbp-other-%[1]d"
163+
name = "acctest-dbp-other-%[3]d"
158164
data_protection_backup_vault_id = azurerm_data_protection_backup_vault.test.id
159165
backup_schedule = ["R/2021-05-23T02:30:00+00:00/P1W", "R/2021-05-24T03:40:00+00:00/P1W"]
160166
time_zone = "Coordinated Universal Time"
@@ -183,7 +189,7 @@ resource "azurerm_data_protection_backup_policy_data_lake_storage" "another" {
183189
scheduled_backup_times = ["2021-05-23T02:30:00Z", "2021-05-24T03:40:00Z"]
184190
}
185191
}
186-
`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(8))
192+
`, r.template(data), data.RandomIntOfLength(8), data.RandomInteger)
187193
}
188194

189195
func (r DataProtectionBackupInstanceDataLakeStorageResource) basic(data acceptance.TestData) string {
@@ -196,7 +202,7 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "test" {
196202
location = azurerm_resource_group.test.location
197203
storage_account_id = azurerm_storage_account.test.id
198204
backup_policy_id = azurerm_data_protection_backup_policy_data_lake_storage.test.id
199-
storage_account_container_names = [azurerm_storage_container.test.name, azurerm_storage_container.another.name]
205+
storage_container_names = [azurerm_storage_container.test.name]
200206
201207
depends_on = [azurerm_role_assignment.test]
202208
}
@@ -213,7 +219,7 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "import" {
213219
location = azurerm_data_protection_backup_instance_data_lake_storage.test.location
214220
storage_account_id = azurerm_data_protection_backup_instance_data_lake_storage.test.storage_account_id
215221
backup_policy_id = azurerm_data_protection_backup_instance_data_lake_storage.test.backup_policy_id
216-
storage_account_container_names = azurerm_data_protection_backup_instance_data_lake_storage.test.storage_account_container_names
222+
storage_container_names = azurerm_data_protection_backup_instance_data_lake_storage.test.storage_container_names
217223
218224
depends_on = [azurerm_role_assignment.test]
219225
}
@@ -230,11 +236,11 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "test" {
230236
location = azurerm_resource_group.test.location
231237
storage_account_id = azurerm_storage_account.test.id
232238
backup_policy_id = azurerm_data_protection_backup_policy_data_lake_storage.another.id
233-
storage_account_container_names = [azurerm_storage_container.test.name, azurerm_storage_container.another.name]
239+
storage_container_names = [azurerm_storage_container.test.name, azurerm_storage_container.another.name]
234240
235241
depends_on = [azurerm_role_assignment.test]
236242
}
237-
`, r.template(data), data.RandomInteger)
243+
`, r.templateComplete(data), data.RandomInteger)
238244
}
239245

240246
func (r DataProtectionBackupInstanceDataLakeStorageResource) update(data acceptance.TestData) string {
@@ -247,9 +253,9 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "test" {
247253
location = azurerm_resource_group.test.location
248254
storage_account_id = azurerm_storage_account.test.id
249255
backup_policy_id = azurerm_data_protection_backup_policy_data_lake_storage.another.id
250-
storage_account_container_names = [azurerm_storage_container.test.name, azurerm_storage_container.another.name]
256+
storage_container_names = [azurerm_storage_container.test.name, azurerm_storage_container.another.name]
251257
252258
depends_on = [azurerm_role_assignment.test]
253259
}
254-
`, r.template(data), data.RandomInteger)
260+
`, r.templateComplete(data), data.RandomInteger)
255261
}

website/docs/r/data_protection_backup_instance_data_lake_storage.html.markdown

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ subcategory: "DataProtection"
33
layout: "azurerm"
44
page_title: "Azure Resource Manager: azurerm_data_protection_backup_instance_data_lake_storage"
55
description: |-
6-
Manages a Backup Instance to back up Azure Data Lake Storage.
6+
Manages a Backup Instance to back up Data Lake Storage.
77
---
88

99
# azurerm_data_protection_backup_instance_data_lake_storage
1010

11-
Manages a Backup Instance to back up Azure Data Lake Storage.
11+
Manages a Backup Instance to back up Data Lake Storage.
1212

1313
## Example Usage
1414

@@ -58,7 +58,7 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "example" {
5858
location = azurerm_resource_group.example.location
5959
storage_account_id = azurerm_storage_account.example.id
6060
backup_policy_id = azurerm_data_protection_backup_policy_data_lake_storage.example.id
61-
storage_account_container_names = ["container1", "container2"]
61+
storage_container_names = ["container1", "container2"]
6262
6363
depends_on = [azurerm_role_assignment.example]
6464
}
@@ -68,17 +68,17 @@ resource "azurerm_data_protection_backup_instance_data_lake_storage" "example" {
6868

6969
The following arguments are supported:
7070

71-
* `name` - (Required) The name which should be used for this Backup Instance Data Lake Storage. Changing this forces a new resource to be created.
71+
* `name` - (Required) The name which should be used for this Backup Instance Data Lake Storage. Changing this forces a new Data Protection Backup instance of Backup Instance Data Lake Storage to be created.
7272

73-
* `data_protection_backup_vault_id` - (Required) The ID of the Backup Vault within which the Backup Instance Data Lake Storage should exist. Changing this forces a new resource to be created.
73+
* `data_protection_backup_vault_id` - (Required) The ID of the Backup Vault within which the Backup Instance Data Lake Storage should exist. Changing this forces a new Data Protection Backup instance of Backup Instance Data Lake Storage to be created.
7474

75-
* `location` - (Required) The location of the source Storage Account. Changing this forces a new resource to be created.
75+
* `location` - (Required) The location of the source Storage Account. Changing this forces a new Data Protection Backup instance of Backup Instance Data Lake Storage to be created.
7676

7777
* `backup_policy_id` - (Required) The ID of the Backup Policy.
7878

79-
* `storage_account_id` - (Required) The ID of the source Storage Account. The Storage Account must have Hierarchical Namespace enabled. Changing this forces a new resource to be created.
79+
* `storage_account_id` - (Required) The ID of the source Storage Account. The Storage Account must have Hierarchical Namespace enabled. Changing this forces a new Data Protection Backup instance of Backup Instance Data Lake Storage to be created.
8080

81-
* `storage_account_container_names` - (Required) The list of the container names of the source Storage Account.
81+
* `storage_container_names` - (Required) The list of the storage container names of the source Storage Account.
8282

8383
## Attributes Reference
8484

0 commit comments

Comments
 (0)