Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -125,6 +126,21 @@ func resourceStorageBlobInventoryPolicy() *pluginsdk.Resource {
},
},

"creation_time": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"last_n_days": {
Type: pluginsdk.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 36500),
},
},
},
},

"include_blob_versions": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -307,9 +323,10 @@ func expandBlobInventoryPolicyFilter(input []interface{}, objectType string) (*b
PrefixMatch: utils.ExpandStringSlice(v["prefix_match"].(*pluginsdk.Set).List()),
ExcludePrefix: utils.ExpandStringSlice(v["exclude_prefixes"].(*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)),
IncludeBlobVersions: pointer.To(v["include_blob_versions"].(bool)),
IncludeDeleted: pointer.To(v["include_deleted"].(bool)),
IncludeSnapshots: pointer.To(v["include_snapshots"].(bool)),
CreationTime: expandBlobInventoryPolicyCreationTime(v["creation_time"].([]interface{})),
}

// If the objectType is Container, the following values must be nil when passed to the API
Expand All @@ -325,6 +342,17 @@ func expandBlobInventoryPolicyFilter(input []interface{}, objectType string) (*b
return policyFilter, nil
}

func expandBlobInventoryPolicyCreationTime(input []interface{}) *blobinventorypolicies.BlobInventoryCreationTime {
if len(input) == 0 || input[0] == nil {
return nil
}

v := input[0].(map[string]interface{})
return &blobinventorypolicies.BlobInventoryCreationTime{
LastNDays: pointer.To(int64(v["last_n_days"].(int))),
}
}

func flattenBlobInventoryPolicyRules(input []blobinventorypolicies.BlobInventoryPolicyRule) []interface{} {
results := make([]interface{}, 0)
if input == nil {
Expand Down Expand Up @@ -374,6 +402,19 @@ func flattenBlobInventoryPolicyFilter(input *blobinventorypolicies.BlobInventory
"include_snapshots": includeSnapshots,
"prefix_match": utils.FlattenStringSlice(input.PrefixMatch),
"exclude_prefixes": utils.FlattenStringSlice(input.ExcludePrefix),
"creation_time": flattenBlobInventoryPolicyCreationTime(input.CreationTime),
},
}
}

func flattenBlobInventoryPolicyCreationTime(input *blobinventorypolicies.BlobInventoryCreationTime) []interface{} {
if input == nil {
return make([]interface{}, 0)
}

return []interface{}{
map[string]interface{}{
"last_n_days": pointer.From(input.LastNDays),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ resource "azurerm_storage_blob_inventory_policy" "test" {
include_snapshots = true
prefix_match = ["*/test"]
exclude_prefixes = ["syslog.log"]
creation_time {
last_n_days = 20
}
}
}
}
Expand Down Expand Up @@ -277,6 +280,9 @@ resource "azurerm_storage_blob_inventory_policy" "test" {
include_deleted = true
include_snapshots = true
prefix_match = ["*/test"]
creation_time {
last_n_days = 100
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/storage_blob_inventory_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ A `filter` block supports the following:

~> **Note:** The `rules.*.schema_fields` for this rule has to include `BlobType` so that you can specify the `blob_types`.

* `creation_time` - (Optional) A `creation_time` block as defined below.

~> **Note:** The `rules.*.schema_fields` for this rule has to include `Creation-Time` so that you can specify the `creation_time` filter.

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

~> **Note:** The `rules.*.schema_fields` for this rule has to include `IsCurrentVersion` and `VersionId` so that you can specify the `include_blob_versions`.
Expand All @@ -91,6 +95,12 @@ A `filter` block supports the following:

---

A `creation_time` block supports the following:

* `last_n_days` - (Required) The number of days in the past to filter blob creation time. Possible value is integer between `1` and `36500`.

---

A `rules` block supports the following:

* `name` - (Required) The name which should be used for this Blob Inventory Policy Rule.
Expand Down
Loading