Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_management_policy - Add supports for enable_auto_tier_to_hot_from_cool #20641

Merged
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
17 changes: 17 additions & 0 deletions internal/services/storage/storage_management_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func resourceStorageManagementPolicy() *pluginsdk.Resource {
Default: -1,
ValidateFunc: validation.IntBetween(0, 99999),
},
"auto_tier_to_hot_from_cool_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"tier_to_cool_after_days_since_creation_greater_than": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand Down Expand Up @@ -430,6 +434,11 @@ func expandStorageManagementPolicyRule(d *pluginsdk.ResourceData, ruleIndex int)
sinceCreate = d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cool_after_days_since_creation_greater_than", ruleIndex))
sinceCreateOK = sinceCreate != -1

autoTierToHotOK := d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.auto_tier_to_hot_from_cool_enabled", ruleIndex)).(bool)
if autoTierToHotOK && !sinceAccessOK {
return nil, fmt.Errorf("`auto_tier_to_hot_from_cool_enabled` must be used together with `tier_to_cool_after_days_since_last_access_time_greater_than`")
}

var cnt int
if sinceModOK {
cnt++
Expand All @@ -455,6 +464,9 @@ func expandStorageManagementPolicyRule(d *pluginsdk.ResourceData, ruleIndex int)
if sinceCreateOK {
baseBlob.TierToCool.DaysAfterCreationGreaterThan = utils.Float(float64(sinceCreate.(int)))
}
if autoTierToHotOK {
baseBlob.EnableAutoTierToHotFromCool = utils.Bool(autoTierToHotOK)
}
}

sinceMod = d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", ruleIndex))
Expand Down Expand Up @@ -635,6 +647,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
tierToCoolSinceMod = -1
tierToCoolSinceAccess = -1
tierToCoolSinceCreate = -1
autoTierToHotOK = false
tierToArchiveSinceMod = -1
tierToArchiveSinceAccess = -1
tierToArchiveSinceCreate = -1
Expand All @@ -644,6 +657,9 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
deleteSinceCreate = -1
)

if v := armActionBaseBlob.EnableAutoTierToHotFromCool; v != nil {
autoTierToHotOK = *v
}
if props := armActionBaseBlob.TierToCool; props != nil {
if props.DaysAfterModificationGreaterThan != nil {
tierToCoolSinceMod = int(*props.DaysAfterModificationGreaterThan)
Expand Down Expand Up @@ -682,6 +698,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
}
action["base_blob"] = []interface{}{
map[string]interface{}{
"auto_tier_to_hot_from_cool_enabled": autoTierToHotOK,
"tier_to_cool_after_days_since_modification_greater_than": tierToCoolSinceMod,
"tier_to_cool_after_days_since_last_access_time_greater_than": tierToCoolSinceAccess,
"tier_to_cool_after_days_since_creation_greater_than": tierToCoolSinceCreate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,14 @@ func TestAccStorageManagementPolicy_baseblobAccessTimeBased(t *testing.T) {
},
data.ImportStep(),
{
Config: r.baseblobAccessTimeBased(data),
Config: r.baseblobAccessTimeBased(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.baseblobAccessTimeBased(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -1036,7 +1043,7 @@ resource "azurerm_storage_management_policy" "test" {
`, r.templateLastAccessTimeEnabled(data))
}

func (r StorageManagementPolicyResource) baseblobAccessTimeBased(data acceptance.TestData) string {
func (r StorageManagementPolicyResource) baseblobAccessTimeBased(data acceptance.TestData, autoTierToHotEnabled bool) string {
return fmt.Sprintf(`
%s

Expand All @@ -1052,14 +1059,15 @@ resource "azurerm_storage_management_policy" "test" {
}
actions {
base_blob {
auto_tier_to_hot_from_cool_enabled = %t
tier_to_cool_after_days_since_last_access_time_greater_than = 10
tier_to_archive_after_days_since_last_access_time_greater_than = 50
delete_after_days_since_last_access_time_greater_than = 100
}
}
}
}
`, r.templateLastAccessTimeEnabled(data))
`, r.templateLastAccessTimeEnabled(data), autoTierToHotEnabled)
}

func (r StorageManagementPolicyResource) baseblobAccessTimeBasedZero(data acceptance.TestData) string {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/storage_management_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ The `base_blob` block supports the following:

~> **Note:** The `tier_to_cool_after_days_since_modification_greater_than`, `tier_to_cool_after_days_since_last_access_time_greater_than` and `tier_to_cool_after_days_since_creation_greater_than` can not be set at the same time.

* `auto_tier_to_hot_from_cool_enabled` - (Optional) Whether a blob should automatically be tiered from cool back to hot if it's accessed again after being tiered to cool. Defaults to `false`.

~> **Note:** The `auto_tier_to_hot_from_cool_enabled` must be used together with `tier_to_cool_after_days_since_last_access_time_greater_than`.

* `tier_to_archive_after_days_since_modification_greater_than` - (Optional) The age in days after last modification to tier blobs to archive storage. Supports blob currently at Hot or Cool tier. Must be between 0 and 99999. Defaults to `-1`.
* `tier_to_archive_after_days_since_last_access_time_greater_than` - (Optional) The age in days after last access time to tier blobs to archive storage. Supports blob currently at Hot or Cool tier. Must be between `0` and`99999`. Defaults to `-1`.
* `tier_to_archive_after_days_since_creation_greater_than` - (Optional) The age in days after creation to archive storage. Supports blob currently at Hot or Cool tier. Must be between `0` and`99999`. Defaults to `-1`.
Expand Down