Skip to content

Commit 51387a5

Browse files
modular-magicianc2thorn
authored andcommitted
fix storage bucket retention_period migration crash (#15000) (#10629)
[upstream:e94584a8902d4c06ca2447787d2677b0b975c2ec] Signed-off-by: Modular Magician <[email protected]>
1 parent 69fff4e commit 51387a5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changelog/15000.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
storage: fixed a conversion crash in `google_storage_bucket` state migration
3+
```

google-beta/services/storage/resource_storage_bucket_600_migration.go

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

1919
import (
2020
"context"
21+
"encoding/json"
22+
"fmt"
2123
"log"
2224
"math"
23-
"strconv"
2425
"strings"
2526

2627
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -1587,8 +1588,14 @@ func ResourceStorageBucketStateUpgradeV3(_ context.Context, rawState map[string]
15871588
retentionPolicies := rawState["retention_policy"].([]interface{})
15881589
if len(retentionPolicies) > 0 {
15891590
retentionPolicy := retentionPolicies[0].(map[string]interface{})
1590-
if v, ok := retentionPolicy["retention_period"]; ok {
1591-
retentionPolicy["retention_period"] = strconv.Itoa(v.(int))
1591+
// nil check
1592+
if v, ok := retentionPolicy["retention_period"]; ok && v != nil {
1593+
// number conversion check to error rather than crash
1594+
if num, ok := v.(json.Number); ok {
1595+
retentionPolicy["retention_period"] = num.String()
1596+
} else {
1597+
return rawState, fmt.Errorf("retention_period in state has unexpected type %T", v)
1598+
}
15921599
}
15931600
}
15941601
}

0 commit comments

Comments
 (0)