Skip to content

Commit

Permalink
azurerm_storage_blob_inventory_policy - support for deleted blobs i…
Browse files Browse the repository at this point in the history
…n inventory policy via include_deleted property on filters (#19286)

* Support "includeDeleted" in blob inventory policy

* Fix formatting

* Fix formatting
  • Loading branch information
dknott-arcadis authored Nov 17, 2022
1 parent 5e3867c commit cb8c30b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ func storageBlobInventoryPolicyResourceSchema() map[string]*pluginsdk.Schema {
Default: false,
},

"include_deleted": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"include_snapshots": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -283,6 +289,7 @@ func expandBlobInventoryPolicyFilter(input []interface{}) *storage.BlobInventory
PrefixMatch: utils.ExpandStringSlice(v["prefix_match"].(*pluginsdk.Set).List()),
BlobTypes: utils.ExpandStringSlice(v["blob_types"].(*pluginsdk.Set).List()),
IncludeBlobVersions: utils.Bool(v["include_blob_versions"].(bool)),
IncludeDeleted: utils.Bool(v["include_deleted"].(bool)),
IncludeSnapshots: utils.Bool(v["include_snapshots"].(bool)),
}
}
Expand Down Expand Up @@ -330,6 +337,10 @@ func flattenBlobInventoryPolicyFilter(input *storage.BlobInventoryPolicyFilter)
if input.IncludeBlobVersions != nil {
includeBlobVersions = *input.IncludeBlobVersions
}
var includeDeleted bool
if input.IncludeDeleted != nil {
includeDeleted = *input.IncludeDeleted
}
var includeSnapshots bool
if input.IncludeSnapshots != nil {
includeSnapshots = *input.IncludeSnapshots
Expand All @@ -338,6 +349,7 @@ func flattenBlobInventoryPolicyFilter(input *storage.BlobInventoryPolicyFilter)
map[string]interface{}{
"blob_types": utils.FlattenStringSlice(input.BlobTypes),
"include_blob_versions": includeBlobVersions,
"include_deleted": includeDeleted,
"include_snapshots": includeSnapshots,
"prefix_match": utils.FlattenStringSlice(input.PrefixMatch),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,13 @@ resource "azurerm_storage_blob_inventory_policy" "test" {
"IsCurrentVersion",
"Snapshot",
"BlobType",
"Deleted",
"RemainingRetentionDays",
]
filter {
blob_types = ["blockBlob", "pageBlob"]
include_blob_versions = true
include_deleted = true
include_snapshots = true
prefix_match = ["*/test"]
}
Expand Down Expand Up @@ -243,10 +246,13 @@ resource "azurerm_storage_blob_inventory_policy" "test" {
"IsCurrentVersion",
"Snapshot",
"BlobType",
"Deleted",
"RemainingRetentionDays",
]
filter {
blob_types = ["blockBlob", "pageBlob"]
include_blob_versions = true
include_deleted = true
include_snapshots = true
prefix_match = ["*/test"]
}
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/storage_blob_inventory_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ A `filter` block supports the following:

~> **NOTE**: The `rules.*.schema_fields` for this rule has to include `IsCurrentVersion` and `VersionId` so that you can specify the `include_blob_versions`.

* `include_deleted` - (Optional) Includes deleted blobs in blob inventory or not? Defaults to `false`.

~> **NOTE:** If `rules.*.scope` is `Container`, the `rules.*.schema_fields` for this rule must include `Deleted`, `Version`, `DeletedTime`, and `RemainingRetentionDays` so that you can specify the `include_deleted`. If `rules.*.scope` is `Blob`, the `rules.*.schema_fields` must include `Deleted` and `RemainingRetentionDays` so that you can specify the `include_deleted`. If `rules.*.scope` is `Blob` and the storage account specified by `storage_account_id` has hierarchical namespaces enabled (`is_hns_enabled` is `true` on the storage account), the `rules.*.schema_fields` for this rule must include `Deleted`, `Version`, `DeletedTime`, and `RemainingRetentionDays` so that you can specify the `include_deleted`.

* `include_snapshots` - (Optional) Includes blob snapshots in blob inventory or not? Defaults to `false`.

~> **NOTE**: The `rules.*.schema_fields` for this rule has to include `Snapshot` so that you can specify the `include_snapshots`.
Expand Down

0 comments on commit cb8c30b

Please sign in to comment.