|
5 | 5 | "context" |
6 | 6 | "errors" |
7 | 7 | "fmt" |
| 8 | + "github.com/scaleway/scaleway-sdk-go/validation" |
| 9 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional" |
8 | 10 | "sort" |
9 | 11 | "time" |
10 | 12 |
|
@@ -195,6 +197,39 @@ func customDiffPrivateNetworkOption() func(ctx context.Context, diff *schema.Res |
195 | 197 | } |
196 | 198 | } |
197 | 199 |
|
| 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 | + |
198 | 233 | func privateNetworkSetHash(v interface{}) int { |
199 | 234 | m := v.(map[string]interface{}) |
200 | 235 | id := locality.ExpandID(m["id"].(string)) |
|
0 commit comments