diff --git a/internal/services/baremetal/server.go b/internal/services/baremetal/server.go index 2742874684..cd59797fad 100644 --- a/internal/services/baremetal/server.go +++ b/internal/services/baremetal/server.go @@ -68,6 +68,7 @@ func ResourceServer() *schema.Resource { return ok && newValue == offerName }, + ValidateDiagFunc: verify.IsUUIDOrNameOffer(), }, "offer_id": { Type: schema.TypeString, diff --git a/internal/verify/uuid.go b/internal/verify/uuid.go index e438097f6b..b4cdd1617d 100644 --- a/internal/verify/uuid.go +++ b/internal/verify/uuid.go @@ -66,3 +66,28 @@ func IsUUIDWithLocality() schema.SchemaValidateDiagFunc { return IsUUID()(subUUID, path) } } + +func IsUUIDOrNameOffer() schema.SchemaValidateDiagFunc { + return func(value interface{}, path cty.Path) diag.Diagnostics { + uuid, _ := value.(string) + if !validation.IsUUID(uuid) { + return diag.Diagnostics{diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Using a datasource for better consistency and reliability is recommended instead of directly using offer names.", + AttributePath: path, + Detail: `The offer name should be retrieved using a datasource to ensure reliable and consistent configuration. + +Example: +data "scaleway_baremetal_offer" "my_offer_monthly" { + zone = "fr-par-2" + name = "EM-B112X-SSD" + subscription_period = "monthly" +} + +Then, you can reference the datasource's attributes in your resources.`, + }} + } + + return nil + } +}