Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion internal/services/instance/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"strconv"
"strings"
"time"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-cty/cty"
Expand All @@ -21,6 +22,7 @@ import (
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
product_catalog "github.com/scaleway/scaleway-sdk-go/api/product_catalog/v2alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
scwvalidation "github.com/scaleway/scaleway-sdk-go/validation"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
Expand Down Expand Up @@ -787,6 +789,11 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
diags := diag.Diagnostics{}

if server.EndOfService {
eosDate, err := GetEndOfServiceDate(ctx, meta.ExtractScwClient(m), server.Zone, server.CommercialType)
if err != nil {
return diag.FromErr(err)
}

compatibleTypes, err := api.GetServerCompatibleTypes(&instanceSDK.GetServerCompatibleTypesRequest{
Zone: zone,
ServerID: id,
Expand All @@ -800,12 +807,13 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Detail: fmt.Sprintf("Instance type %q will soon reach End of Service", server.CommercialType),
Summary: fmt.Sprintf(`Your Instance will soon reach End of Service. You can check the exact date on the Scaleway console. We recommend that you migrate your Instance before that.
Summary: fmt.Sprintf(`Your Instance will reach End of Service by %s. We recommend that you migrate your Instance before that.
Here are the %d best options for %q, ordered by relevance: [%s]

You can check the full list of compatible server types:
- on the Scaleway console
- using the CLI command 'scw instance server get-compatible-types %s zone=%s'`,
eosDate,
len(mostRelevantTypes),
server.CommercialType,
strings.Join(mostRelevantTypes, ", "),
Expand Down Expand Up @@ -1572,3 +1580,26 @@ func instanceServerVolumesUpdate(ctx context.Context, d *schema.ResourceData, ap

return volumes, nil
}

func GetEndOfServiceDate(ctx context.Context, client *scw.Client, zone scw.Zone, commercialType string) (string, error) {
api := product_catalog.NewPublicCatalogAPI(client)

products, err := api.ListPublicCatalogProducts(&product_catalog.PublicCatalogAPIListPublicCatalogProductsRequest{
ProductTypes: []product_catalog.ListPublicCatalogProductsRequestProductType{
product_catalog.ListPublicCatalogProductsRequestProductTypeInstance,
},
}, scw.WithAllPages(), scw.WithContext(ctx))
if err != nil {
return "", fmt.Errorf("could not list product catalog entries: %w", err)
}

for _, product := range products.Products {
if strings.HasPrefix(product.Product, commercialType) {
if product.Locality.Zone != nil && *product.Locality.Zone == zone {
return product.EndOfLifeAt.Format(time.DateOnly), nil
}
}
}

return "", fmt.Errorf("could not find product catalog entry for %q in %s", commercialType, zone)
}
15 changes: 15 additions & 0 deletions internal/services/instance/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance"
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
"github.com/stretchr/testify/assert"
)

func TestAccServer_Minimal1(t *testing.T) {
Expand Down Expand Up @@ -2094,3 +2096,16 @@ func TestAccServer_PrivateNetworkMissingPNIC(t *testing.T) {
},
})
}

func TestGetEndOfServiceDate(t *testing.T) {
tt := acctest.NewTestTools(t)
client := meta.ExtractScwClient(tt.Meta)
defer tt.Cleanup()

eosDate, err := instance.GetEndOfServiceDate(t.Context(), client, "fr-par-1", "ENT1-S")
if err != nil {
t.Fatal(err)
}

assert.Equal(t, "2025-09-01", eosDate)
}

Large diffs are not rendered by default.

Loading