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 - Support properties rule.*.actions.*.base_blob.0.tier_to_cold_after_days_since_{modification|last_access_time|creation}_greater_than and rule.*.actions.*.{snapshot|version}.0.tier_to_cold_after_days_since_creation_greater_than #23574

Merged
merged 1 commit into from
Oct 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
115 changes: 113 additions & 2 deletions internal/services/storage/storage_management_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
Expand All @@ -739,19 +836,29 @@ 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)
}
action["snapshot"] = []interface{}{map[string]interface{}{
"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)
}
Expand All @@ -762,13 +869,17 @@ 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)
}
action["version"] = []interface{}{map[string]interface{}{
"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,
}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions website/docs/d/storage_management_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

---
Expand All @@ -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.

---
Expand Down
Loading
Loading