Skip to content

Commit

Permalink
azurerm_data_protection_backup_policy_blob_storage : remove depreca…
Browse files Browse the repository at this point in the history
…ted property `retention_duration` (#27323)
  • Loading branch information
sinbai authored Oct 11, 2024
1 parent 2ca5e2c commit 4729fba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
helperValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
azSchema "github.com/hashicorp/terraform-provider-azurerm/internal/tf/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -70,13 +69,30 @@ func resourceDataProtectionBackupPolicyBlobStorage() *schema.Resource {
},
},

"operational_default_retention_duration": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: []string{"operational_default_retention_duration", "vault_default_retention_duration"},
ValidateFunc: helperValidate.ISO8601Duration,
},

"time_zone": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"vault_default_retention_duration": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: []string{"operational_default_retention_duration", "vault_default_retention_duration"},
RequiredWith: []string{"backup_repeating_time_intervals"},
ValidateFunc: helperValidate.ISO8601Duration,
},

"retention_rule": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -204,54 +220,6 @@ func resourceDataProtectionBackupPolicyBlobStorage() *schema.Resource {
},
}

if !features.FourPointOhBeta() {
resource.Schema["operational_default_retention_duration"] = &pluginsdk.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
AtLeastOneOf: []string{
"retention_duration", "operational_default_retention_duration", "vault_default_retention_duration"},
ValidateFunc: helperValidate.ISO8601Duration,
}

resource.Schema["retention_duration"] = &pluginsdk.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
AtLeastOneOf: []string{"retention_duration", "operational_default_retention_duration", "vault_default_retention_duration"},
ValidateFunc: helperValidate.ISO8601Duration,
Deprecated: "This property has been renamed to `operational_default_retention_duration` and will be removed in v4.0 of the AzureRM provider",
}

resource.Schema["vault_default_retention_duration"] = &pluginsdk.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: []string{"retention_duration", "operational_default_retention_duration", "vault_default_retention_duration"},
RequiredWith: []string{"backup_repeating_time_intervals"},
ValidateFunc: helperValidate.ISO8601Duration,
}
} else {
resource.Schema["operational_default_retention_duration"] = &pluginsdk.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: []string{"operational_default_retention_duration", "vault_default_retention_duration"},
ValidateFunc: helperValidate.ISO8601Duration,
}

resource.Schema["vault_default_retention_duration"] = &pluginsdk.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: []string{"operational_default_retention_duration", "vault_default_retention_duration"},
RequiredWith: []string{"backup_repeating_time_intervals"},
ValidateFunc: helperValidate.ISO8601Duration,
}
}

return resource
}

Expand All @@ -277,16 +245,7 @@ func resourceDataProtectionBackupPolicyBlobStorageCreate(d *schema.ResourceData,

policyRules := make([]backuppolicies.BasePolicyRule, 0)
// expand the default operational retention rule when the operational default duration is specified
operationalDefaultDuration := ""
if !features.FourPointOhBeta() {
if v, ok := d.GetOk("retention_duration"); ok {
operationalDefaultDuration = v.(string)
} else if v, ok := d.GetOk("operational_default_retention_duration"); ok {
operationalDefaultDuration = v.(string)
}
} else {
operationalDefaultDuration = d.Get("operational_default_retention_duration").(string)
}
operationalDefaultDuration := d.Get("operational_default_retention_duration").(string)
if operationalDefaultDuration != "" {
policyRules = append(policyRules, expandBackupPolicyBlobStorageDefaultRetentionRuleArray(operationalDefaultDuration, backuppolicies.DataStoreTypesOperationalStore))
}
Expand Down Expand Up @@ -352,11 +311,6 @@ func resourceDataProtectionBackupPolicyBlobStorageRead(d *schema.ResourceData, m
if err := d.Set("operational_default_retention_duration", flattenBackupPolicyBlobStorageDefaultRetentionRuleDuration(props.PolicyRules, backuppolicies.DataStoreTypesOperationalStore)); err != nil {
return fmt.Errorf("setting `operational_default_retention_duration`: %+v", err)
}
if !features.FourPointOhBeta() {
if err := d.Set("retention_duration", flattenBackupPolicyBlobStorageDefaultRetentionRuleDuration(props.PolicyRules, backuppolicies.DataStoreTypesOperationalStore)); err != nil {
return fmt.Errorf("setting `retention_duration`: %+v", err)
}
}
d.Set("time_zone", flattenBackupPolicyBlobStorageVaultBackupTimeZone(&props.PolicyRules))
if err := d.Set("vault_default_retention_duration", flattenBackupPolicyBlobStorageDefaultRetentionRuleDuration(props.PolicyRules, backuppolicies.DataStoreTypesVaultStore)); err != nil {
return fmt.Errorf("setting `vault_default_retention_duration`: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
Expand Down Expand Up @@ -100,17 +99,6 @@ resource "azurerm_data_protection_backup_vault" "test" {

func (r DataProtectionBackupPolicyBlobStorageResource) basic(data acceptance.TestData) string {
template := r.template(data)
if !features.FourPointOhBeta() {
return fmt.Sprintf(`
%s
resource "azurerm_data_protection_backup_policy_blob_storage" "test" {
name = "acctest-dbp-%d"
vault_id = azurerm_data_protection_backup_vault.test.id
retention_duration = "P30D"
}
`, template, data.RandomInteger)
}
return fmt.Sprintf(`
%s
Expand All @@ -124,46 +112,6 @@ resource "azurerm_data_protection_backup_policy_blob_storage" "test" {

func (r DataProtectionBackupPolicyBlobStorageResource) vaultBackup(data acceptance.TestData) string {
template := r.template(data)
if !features.FourPointOhBeta() {
return fmt.Sprintf(`
%s
resource "azurerm_data_protection_backup_policy_blob_storage" "test" {
name = "acctest-dbp-%d"
vault_id = azurerm_data_protection_backup_vault.test.id
retention_duration = "P30D"
vault_default_retention_duration = "P7D"
backup_repeating_time_intervals = ["R/2024-05-08T11:30:00+00:00/P1W"]
retention_rule {
name = "Monthly"
priority = 15
life_cycle {
duration = "P6M"
data_store_type = "VaultStore"
}
criteria {
days_of_month = [1, 2, 0]
}
}
retention_rule {
name = "Daily"
priority = 25
life_cycle {
duration = "P7D"
data_store_type = "VaultStore"
}
criteria {
days_of_week = ["Thursday"]
months_of_year = ["November"]
weeks_of_month = ["First"]
scheduled_backup_times = ["2024-05-08T02:30:00Z"]
}
}
}
`, template, data.RandomInteger)
}
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -206,17 +154,6 @@ resource "azurerm_data_protection_backup_policy_blob_storage" "test" {

func (r DataProtectionBackupPolicyBlobStorageResource) requiresImport(data acceptance.TestData) string {
config := r.basic(data)
if !features.FourPointOhBeta() {
return fmt.Sprintf(`
%s
resource "azurerm_data_protection_backup_policy_blob_storage" "import" {
name = azurerm_data_protection_backup_policy_blob_storage.test.name
vault_id = azurerm_data_protection_backup_policy_blob_storage.test.vault_id
retention_duration = "P30D"
}
`, config)
}
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit 4729fba

Please sign in to comment.