Skip to content

Commit

Permalink
azurerm_storage_management_policy - fix panic in slice/array return (
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Jul 6, 2021
1 parent a3e6f45 commit 623dd68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func resourceStorageManagementPolicyRead(d *pluginsdk.ResourceData, meta interfa
if policy := result.Policy; policy != nil {
policy := result.Policy
if rules := policy.Rules; rules != nil {
if err := d.Set("rule", flattenStorageManagementPolicyRules(policy.Rules)); err != nil {
if err := d.Set("rule", flattenStorageManagementPolicyRules(rules)); err != nil {
return fmt.Errorf("flattening `rule`: %+v", err)
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul

filter["match_blob_index_tag"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch)

rule["filters"] = [1]interface{}{filter}
rule["filters"] = []interface{}{filter}
}

armAction := armDefinition.Actions
Expand All @@ -511,7 +511,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
intTemp := int(*armActionBaseBlob.Delete.DaysAfterModificationGreaterThan)
baseBlob["delete_after_days_since_modification_greater_than"] = intTemp
}
action["base_blob"] = [1]interface{}{baseBlob}
action["base_blob"] = []interface{}{baseBlob}
}

armActionSnaphost := armAction.Snapshot
Expand All @@ -526,7 +526,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
if armActionSnaphost.TierToCool != nil && armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan != nil {
coolAfterCreation = int(*armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan)
}
action["snapshot"] = [1]interface{}{map[string]interface{}{
action["snapshot"] = []interface{}{map[string]interface{}{
"delete_after_days_since_creation_greater_than": deleteAfterCreation,
"change_tier_to_archive_after_days_since_creation": archiveAfterCreation,
"change_tier_to_cool_after_days_since_creation": coolAfterCreation,
Expand All @@ -544,14 +544,14 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul
if armActionVersion.TierToCool != nil && armActionVersion.TierToCool.DaysAfterCreationGreaterThan != nil {
coolAfterCreation = int(*armActionVersion.TierToCool.DaysAfterCreationGreaterThan)
}
action["version"] = [1]interface{}{map[string]interface{}{
action["version"] = []interface{}{map[string]interface{}{
"delete_after_days_since_creation": deleteAfterCreation,
"change_tier_to_archive_after_days_since_creation": archiveAfterCreation,
"change_tier_to_cool_after_days_since_creation": coolAfterCreation,
}}
}

rule["actions"] = [1]interface{}{action}
rule["actions"] = []interface{}{action}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAccStorageManagementPolicy_basic(t *testing.T) {
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("rule.#").HasValue("1"),
check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"),
check.That(data.ResourceName).Key("rule.0.name").HasValue("rule-1"),
check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"),
check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"),
check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"),
Expand Down

0 comments on commit 623dd68

Please sign in to comment.