diff --git a/internal/services/storage/storage_management_policy_data_source.go b/internal/services/storage/storage_management_policy_data_source.go index 4467e2b943bc..d61f879fe3f7 100644 --- a/internal/services/storage/storage_management_policy_data_source.go +++ b/internal/services/storage/storage_management_policy_data_source.go @@ -126,6 +126,18 @@ func dataSourceStorageManagementPolicy() *pluginsdk.Resource { Type: pluginsdk.TypeInt, Computed: true, }, + "tier_to_cold_after_days_since_modification_greater_than": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + "tier_to_cold_after_days_since_last_access_time_greater_than": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Computed: true, + }, "delete_after_days_since_modification_greater_than": { Type: pluginsdk.TypeInt, Computed: true, @@ -158,6 +170,10 @@ func dataSourceStorageManagementPolicy() *pluginsdk.Resource { Type: pluginsdk.TypeInt, Computed: true, }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Computed: true, + }, "delete_after_days_since_creation_greater_than": { Type: pluginsdk.TypeInt, Computed: true, @@ -182,6 +198,10 @@ func dataSourceStorageManagementPolicy() *pluginsdk.Resource { Type: pluginsdk.TypeInt, Computed: true, }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Computed: true, + }, "delete_after_days_since_creation": { Type: pluginsdk.TypeInt, Computed: true, diff --git a/internal/services/storage/storage_management_policy_resource.go b/internal/services/storage/storage_management_policy_resource.go index c7e015df19f4..c90910e01c1f 100644 --- a/internal/services/storage/storage_management_policy_resource.go +++ b/internal/services/storage/storage_management_policy_resource.go @@ -177,6 +177,24 @@ func resourceStorageManagementPolicy() *pluginsdk.Resource { Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, + "tier_to_cold_after_days_since_modification_greater_than": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntBetween(0, 99999), + }, + "tier_to_cold_after_days_since_last_access_time_greater_than": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntBetween(0, 99999), + }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntBetween(0, 99999), + }, "delete_after_days_since_modification_greater_than": { Type: pluginsdk.TypeInt, Optional: true, @@ -223,6 +241,12 @@ func resourceStorageManagementPolicy() *pluginsdk.Resource { Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntBetween(0, 99999), + }, "delete_after_days_since_creation_greater_than": { Type: pluginsdk.TypeInt, Optional: true, @@ -256,6 +280,12 @@ func resourceStorageManagementPolicy() *pluginsdk.Resource { Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, + "tier_to_cold_after_days_since_creation_greater_than": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntBetween(0, 99999), + }, "delete_after_days_since_creation": { Type: pluginsdk.TypeInt, Optional: true, @@ -559,6 +589,40 @@ func expandStorageManagementPolicyRule(d *pluginsdk.ResourceData, ruleIndex int) } } + sinceMod = d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cold_after_days_since_modification_greater_than", ruleIndex)) + sinceModOK = sinceMod != -1 + sinceAccess = d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cold_after_days_since_last_access_time_greater_than", ruleIndex)) + sinceAccessOK = sinceAccess != -1 + sinceCreate = d.Get(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cold_after_days_since_creation_greater_than", ruleIndex)) + sinceCreateOK = sinceCreate != -1 + + cnt = 0 + if sinceModOK { + cnt++ + } + if sinceAccessOK { + cnt++ + } + if sinceCreateOK { + cnt++ + } + if cnt > 1 { + return nil, fmt.Errorf("Only one of `tier_to_cold_after_days_since_modification_greater_than`, `tier_to_cold_after_days_since_last_access_time_greater_than` and `tier_to_cold_after_days_since_creation_greater_than` can be specified at the same time") + } + + if sinceModOK || sinceAccessOK || sinceCreateOK { + baseBlob.TierToCold = &managementpolicies.DateAfterModification{} + if sinceModOK { + baseBlob.TierToCold.DaysAfterModificationGreaterThan = utils.Float(float64(sinceMod.(int))) + } + if sinceAccessOK { + baseBlob.TierToCold.DaysAfterLastAccessTimeGreaterThan = utils.Float(float64(sinceAccess.(int))) + } + if sinceCreateOK { + baseBlob.TierToCold.DaysAfterCreationGreaterThan = utils.Float(float64(sinceCreate.(int))) + } + } + definition.Actions.BaseBlob = baseBlob } @@ -582,6 +646,11 @@ func expandStorageManagementPolicyRule(d *pluginsdk.ResourceData, ruleIndex int) DaysAfterCreationGreaterThan: float64(v.(int)), } } + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.snapshot.0.tier_to_cold_after_days_since_creation_greater_than", ruleIndex)); v != -1 { + snapshot.TierToCold = &managementpolicies.DateAfterCreation{ + DaysAfterCreationGreaterThan: float64(v.(int)), + } + } definition.Actions.Snapshot = snapshot } @@ -605,6 +674,11 @@ func expandStorageManagementPolicyRule(d *pluginsdk.ResourceData, ruleIndex int) DaysAfterCreationGreaterThan: float64(v.(int)), } } + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.version.0.tier_to_cold_after_days_since_creation_greater_than", ruleIndex)); v != -1 { + version.TierToCold = &managementpolicies.DateAfterCreation{ + DaysAfterCreationGreaterThan: float64(v.(int)), + } + } definition.Actions.Version = version } } @@ -665,6 +739,9 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen tierToArchiveSinceAccess = -1 tierToArchiveSinceCreate = -1 tierToArchiveSinceLastTierChange = -1 + tierToColdSinceMod = -1 + tierToColdSinceAccess = -1 + tierToColdSinceCreate = -1 deleteSinceMod = -1 deleteSinceAccess = -1 deleteSinceCreate = -1 @@ -698,6 +775,17 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen tierToArchiveSinceCreate = int(*props.DaysAfterCreationGreaterThan) } } + if props := armActionBaseBlob.TierToCold; props != nil { + if props.DaysAfterModificationGreaterThan != nil { + tierToColdSinceMod = int(*props.DaysAfterModificationGreaterThan) + } + if props.DaysAfterLastAccessTimeGreaterThan != nil { + tierToColdSinceAccess = int(*props.DaysAfterLastAccessTimeGreaterThan) + } + if props.DaysAfterCreationGreaterThan != nil { + tierToColdSinceCreate = int(*props.DaysAfterCreationGreaterThan) + } + } if props := armActionBaseBlob.Delete; props != nil { if props.DaysAfterModificationGreaterThan != nil { deleteSinceMod = int(*props.DaysAfterModificationGreaterThan) @@ -719,6 +807,9 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen "tier_to_archive_after_days_since_last_access_time_greater_than": tierToArchiveSinceAccess, "tier_to_archive_after_days_since_last_tier_change_greater_than": tierToArchiveSinceLastTierChange, "tier_to_archive_after_days_since_creation_greater_than": tierToArchiveSinceCreate, + "tier_to_cold_after_days_since_modification_greater_than": tierToColdSinceMod, + "tier_to_cold_after_days_since_last_access_time_greater_than": tierToColdSinceAccess, + "tier_to_cold_after_days_since_creation_greater_than": tierToColdSinceCreate, "delete_after_days_since_modification_greater_than": deleteSinceMod, "delete_after_days_since_last_access_time_greater_than": deleteSinceAccess, "delete_after_days_since_creation_greater_than": deleteSinceCreate, @@ -728,7 +819,13 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen armActionSnaphost := armAction.Snapshot if armActionSnaphost != nil { - deleteAfterCreation, archiveAfterCreation, archiveAfterLastTierChange, coolAfterCreation := -1, -1, -1, -1 + var ( + deleteAfterCreation = -1 + archiveAfterCreation = -1 + archiveAfterLastTierChange = -1 + coolAfterCreation = -1 + tierToColdSinceCreate = -1 + ) if armActionSnaphost.Delete != nil { deleteAfterCreation = int(armActionSnaphost.Delete.DaysAfterCreationGreaterThan) } @@ -739,6 +836,9 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen archiveAfterLastTierChange = int(*v) } } + if armActionSnaphost.TierToCold != nil { + tierToColdSinceCreate = int(armActionSnaphost.TierToCold.DaysAfterCreationGreaterThan) + } if armActionSnaphost.TierToCool != nil { coolAfterCreation = int(armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan) } @@ -746,12 +846,19 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen "delete_after_days_since_creation_greater_than": deleteAfterCreation, "change_tier_to_archive_after_days_since_creation": archiveAfterCreation, "tier_to_archive_after_days_since_last_tier_change_greater_than": archiveAfterLastTierChange, + "tier_to_cold_after_days_since_creation_greater_than": tierToColdSinceCreate, "change_tier_to_cool_after_days_since_creation": coolAfterCreation, }} } if armActionVersion := armAction.Version; armActionVersion != nil { - deleteAfterCreation, archiveAfterCreation, archiveAfterLastTierChange, coolAfterCreation := -1, -1, -1, -1 + var ( + deleteAfterCreation = -1 + archiveAfterCreation = -1 + archiveAfterLastTierChange = -1 + coolAfterCreation = -1 + tierToColdSinceCreate = -1 + ) if armActionVersion.Delete != nil { deleteAfterCreation = int(armActionVersion.Delete.DaysAfterCreationGreaterThan) } @@ -762,6 +869,9 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen archiveAfterLastTierChange = int(*v) } } + if armActionVersion.TierToCold != nil { + tierToColdSinceCreate = int(armActionVersion.TierToCold.DaysAfterCreationGreaterThan) + } if armActionVersion.TierToCool != nil { coolAfterCreation = int(armActionVersion.TierToCool.DaysAfterCreationGreaterThan) } @@ -769,6 +879,7 @@ func flattenStorageManagementPolicyRules(armRules []managementpolicies.Managemen "delete_after_days_since_creation": deleteAfterCreation, "change_tier_to_archive_after_days_since_creation": archiveAfterCreation, "tier_to_archive_after_days_since_last_tier_change_greater_than": archiveAfterLastTierChange, + "tier_to_cold_after_days_since_creation_greater_than": tierToColdSinceCreate, "change_tier_to_cool_after_days_since_creation": coolAfterCreation, }} } diff --git a/internal/services/storage/storage_management_policy_resource_test.go b/internal/services/storage/storage_management_policy_resource_test.go index 231559f1589d..16d16dfa6c0f 100644 --- a/internal/services/storage/storage_management_policy_resource_test.go +++ b/internal/services/storage/storage_management_policy_resource_test.go @@ -891,18 +891,21 @@ resource "azurerm_storage_management_policy" "test" { tier_to_cool_after_days_since_modification_greater_than = 10 tier_to_archive_after_days_since_modification_greater_than = 50 tier_to_archive_after_days_since_last_tier_change_greater_than = 10 + tier_to_cold_after_days_since_modification_greater_than = 11 delete_after_days_since_modification_greater_than = 100 } snapshot { change_tier_to_archive_after_days_since_creation = 90 tier_to_archive_after_days_since_last_tier_change_greater_than = 10 change_tier_to_cool_after_days_since_creation = 23 + tier_to_cold_after_days_since_creation_greater_than = 24 delete_after_days_since_creation_greater_than = 30 } version { change_tier_to_archive_after_days_since_creation = 9 tier_to_archive_after_days_since_last_tier_change_greater_than = 10 change_tier_to_cool_after_days_since_creation = 90 + tier_to_cold_after_days_since_creation_greater_than = 91 delete_after_days_since_creation = 3 } } @@ -947,18 +950,21 @@ resource "azurerm_storage_management_policy" "test" { tier_to_cool_after_days_since_modification_greater_than = 11 tier_to_archive_after_days_since_modification_greater_than = 51 tier_to_archive_after_days_since_last_tier_change_greater_than = 20 + tier_to_cold_after_days_since_modification_greater_than = 12 delete_after_days_since_modification_greater_than = 101 } snapshot { change_tier_to_archive_after_days_since_creation = 91 tier_to_archive_after_days_since_last_tier_change_greater_than = 20 change_tier_to_cool_after_days_since_creation = 24 + tier_to_cold_after_days_since_creation_greater_than = 25 delete_after_days_since_creation_greater_than = 31 } version { change_tier_to_archive_after_days_since_creation = 10 tier_to_archive_after_days_since_last_tier_change_greater_than = 20 change_tier_to_cool_after_days_since_creation = 91 + tier_to_cold_after_days_since_creation_greater_than = 92 delete_after_days_since_creation = 4 } } @@ -1038,6 +1044,7 @@ resource "azurerm_storage_management_policy" "test" { base_blob { tier_to_cool_after_days_since_modification_greater_than = 10 tier_to_archive_after_days_since_modification_greater_than = 50 + tier_to_cold_after_days_since_modification_greater_than = 60 delete_after_days_since_modification_greater_than = 100 } } @@ -1064,6 +1071,7 @@ resource "azurerm_storage_management_policy" "test" { base_blob { tier_to_cool_after_days_since_creation_greater_than = 10 tier_to_archive_after_days_since_creation_greater_than = 50 + tier_to_cold_after_days_since_creation_greater_than = 60 delete_after_days_since_creation_greater_than = 100 } } @@ -1091,6 +1099,7 @@ resource "azurerm_storage_management_policy" "test" { 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 + tier_to_cold_after_days_since_last_access_time_greater_than = 60 delete_after_days_since_last_access_time_greater_than = 100 } } @@ -1117,6 +1126,7 @@ resource "azurerm_storage_management_policy" "test" { base_blob { tier_to_cool_after_days_since_last_access_time_greater_than = 0 tier_to_archive_after_days_since_last_access_time_greater_than = 0 + tier_to_cold_after_days_since_last_access_time_greater_than = 0 delete_after_days_since_last_access_time_greater_than = 0 } } diff --git a/website/docs/d/storage_management_policy.html.markdown b/website/docs/d/storage_management_policy.html.markdown index a3b487889330..045bc5faa709 100644 --- a/website/docs/d/storage_management_policy.html.markdown +++ b/website/docs/d/storage_management_policy.html.markdown @@ -71,6 +71,9 @@ The following arguments are supported: * `tier_to_archive_after_days_since_last_access_time_greater_than` - The age in days after last access time to tier blobs to archive storage. * `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to archive storage. * `tier_to_archive_after_days_since_last_tier_change_greater_than` - The age in days after last tier change to the blobs to skip to be archved. +* `tier_to_cold_after_days_since_modification_greater_than` - The age in days after last modification to tier blobs to cold storage. Supports blob currently at Hot tier. +* `tier_to_cold_after_days_since_last_access_time_greater_than` - The age in days after last access time to tier blobs to cold storage. Supports blob currently at Hot tier. +* `tier_to_cold_after_days_since_creation_greater_than` - Optional The age in days after creation to cold storage. Supports blob currently at Hot tier. * `delete_after_days_since_modification_greater_than` - The age in days after last modification to delete the blob. * `delete_after_days_since_last_access_time_greater_than` - The age in days after last access time to delete the blob. * `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob. @@ -82,6 +85,7 @@ The following arguments are supported: * `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob snapshot to archive storage. * `tier_to_archive_after_days_since_last_tier_change_greater_than` - The age in days after last tier change to the blobs to skip to be archived. * `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob snapshot to cool storage. +* `tier_to_cold_after_days_since_creation_greater_than` - Optional The age in days after creation to cold storage. Supports blob currently at Hot tier. * `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. --- @@ -91,6 +95,7 @@ The following arguments are supported: * `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob version to archive storage. * `tier_to_archive_after_days_since_last_tier_change_greater_than` - The age in days after last tier change to the blobs to skip to be archived. * `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob version to cool storage. +* `tier_to_cold_after_days_since_creation_greater_than` - Optional The age in days after creation to cold storage. Supports blob currently at Hot tier. * `delete_after_days_since_creation` - The age in days after creation to delete the blob version. --- diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index cb3bb0f65e37..e305babbe1b7 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -139,6 +139,12 @@ The `base_blob` block supports the following: * `tier_to_archive_after_days_since_last_tier_change_greater_than` - (Optional) The age in days after last tier change to the blobs to skip to be archved. Must be between 0 and 99999. Defaults to `-1`. +* `tier_to_cold_after_days_since_modification_greater_than` - (Optional) The age in days after last modification to tier blobs to cold storage. Supports blob currently at Hot tier. Must be between 0 and 99999. Defaults to `-1`. +* `tier_to_cold_after_days_since_last_access_time_greater_than` - (Optional) The age in days after last access time to tier blobs to cold storage. Supports blob currently at Hot tier. Must be between `0` and `99999`. Defaults to `-1`. +* `tier_to_cold_after_days_since_creation_greater_than` - (Optional) The age in days after creation to cold storage. Supports blob currently at Hot tier. Must be between `0` and `99999`. Defaults to `-1`. + +~> **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. + * `delete_after_days_since_modification_greater_than` - (Optional) The age in days after last modification to delete the blob. Must be between 0 and 99999. Defaults to `-1`. * `delete_after_days_since_last_access_time_greater_than` - (Optional) The age in days after last access time to delete the blob. Must be between `0` and `99999`. Defaults to `-1`. * `delete_after_days_since_creation_greater_than` - (Optional) The age in days after creation to delete the blob. Must be between `0` and `99999`. Defaults to `-1`. @@ -154,6 +160,7 @@ The `snapshot` block supports the following: * `change_tier_to_archive_after_days_since_creation` - (Optional) The age in days after creation to tier blob snapshot to archive storage. Must be between 0 and 99999. Defaults to `-1`. * `tier_to_archive_after_days_since_last_tier_change_greater_than` - (Optional) The age in days after last tier change to the blobs to skip to be archved. Must be between 0 and 99999. Defaults to `-1`. * `change_tier_to_cool_after_days_since_creation` - (Optional) The age in days after creation to tier blob snapshot to cool storage. Must be between 0 and 99999. Defaults to `-1`. +* `tier_to_cold_after_days_since_creation_greater_than` - (Optional) The age in days after creation to cold storage. Supports blob currently at Hot tier. Must be between `0` and `99999`. Defaults to `-1`. * `delete_after_days_since_creation_greater_than` - (Optional) The age in days after creation to delete the blob snapshot. Must be between 0 and 99999. Defaults to `-1`. --- @@ -163,6 +170,7 @@ The `version` block supports the following: * `change_tier_to_archive_after_days_since_creation` - (Optional) The age in days after creation to tier blob version to archive storage. Must be between 0 and 99999. Defaults to `-1`. * `tier_to_archive_after_days_since_last_tier_change_greater_than` - (Optional) The age in days after last tier change to the blobs to skip to be archved. Must be between 0 and 99999. Defaults to `-1`. * `change_tier_to_cool_after_days_since_creation` - (Optional) The age in days creation create to tier blob version to cool storage. Must be between 0 and 99999. Defaults to `-1`. +* `tier_to_cold_after_days_since_creation_greater_than` - (Optional) The age in days after creation to cold storage. Supports blob currently at Hot tier. Must be between `0` and `99999`. Defaults to `-1`. * `delete_after_days_since_creation` - (Optional) The age in days after creation to delete the blob version. Must be between 0 and 99999. Defaults to `-1`. ---