Skip to content

Commit 137ea37

Browse files
committed
add customDiff function to check
1 parent 2ea59fd commit 137ea37

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

internal/services/baremetal/helpers.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"github.com/scaleway/scaleway-sdk-go/validation"
9+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
810
"sort"
911
"time"
1012

@@ -195,6 +197,39 @@ func customDiffPrivateNetworkOption() func(ctx context.Context, diff *schema.Res
195197
}
196198
}
197199

200+
func customDiffOffer() func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
201+
return func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
202+
api, zone, err := NewAPIWithZoneAndID(i, diff.Id())
203+
if err != nil {
204+
return err
205+
}
206+
207+
oldOffer, newOffer := diff.GetChange("newOfferID")
208+
newOfferID := regional.ExpandID(newOffer)
209+
oldOfferID := regional.ExpandID(oldOffer)
210+
if !validation.IsUUID(newOfferID.ID) {
211+
//TODO warning use datasource instead
212+
}
213+
oldOfferDetails, err := FindOfferByID(ctx, api, zone.Zone, oldOfferID.ID)
214+
if err != nil {
215+
return err
216+
}
217+
newOfferDetails, err := FindOfferByID(ctx, api, zone.Zone, newOfferID.ID)
218+
if err != nil {
219+
return err
220+
}
221+
if oldOfferDetails.Name != newOfferDetails.Name {
222+
//TODO error
223+
}
224+
if oldOfferDetails.SubscriptionPeriod == baremetal.OfferSubscriptionPeriodMonthly && newOfferDetails.SubscriptionPeriod == baremetal.OfferSubscriptionPeriodHourly {
225+
//TODO error
226+
}
227+
//TODO manage the migration
228+
return nil
229+
230+
}
231+
}
232+
198233
func privateNetworkSetHash(v interface{}) int {
199234
m := v.(map[string]interface{})
200235
id := locality.ExpandID(m["id"].(string))

0 commit comments

Comments
 (0)