Skip to content

Commit e94584a

Browse files
authored
fix storage bucket retention_period migration crash (#15000)
1 parent c30a428 commit e94584a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

mmv1/third_party/terraform/services/storage/resource_storage_bucket_600_migration.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package storage
22

33
import (
44
"context"
5+
"encoding/json"
6+
"fmt"
57
"log"
68
"math"
7-
"strconv"
89
"strings"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -1571,8 +1572,14 @@ func ResourceStorageBucketStateUpgradeV3(_ context.Context, rawState map[string]
15711572
retentionPolicies := rawState["retention_policy"].([]interface{})
15721573
if len(retentionPolicies) > 0 {
15731574
retentionPolicy := retentionPolicies[0].(map[string]interface{})
1574-
if v, ok := retentionPolicy["retention_period"]; ok {
1575-
retentionPolicy["retention_period"] = strconv.Itoa(v.(int))
1575+
// nil check
1576+
if v, ok := retentionPolicy["retention_period"]; ok && v != nil {
1577+
// number conversion check to error rather than crash
1578+
if num, ok := v.(json.Number); ok {
1579+
retentionPolicy["retention_period"] = num.String()
1580+
} else {
1581+
return rawState, fmt.Errorf("retention_period in state has unexpected type %T", v)
1582+
}
15761583
}
15771584
}
15781585
}

0 commit comments

Comments
 (0)