Skip to content

Commit 69e983d

Browse files
committed
fix(baremetal): add warning offer
1 parent f5d4aa6 commit 69e983d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

internal/services/baremetal/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func ResourceServer() *schema.Resource {
6868

6969
return ok && newValue == offerName
7070
},
71+
ValidateDiagFunc: verify.IsUUIDOrNameOffer(),
7172
},
7273
"offer_id": {
7374
Type: schema.TypeString,

internal/verify/uuid.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package verify
22

33
import (
4+
"fmt"
45
"github.com/hashicorp/go-cty/cty"
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -66,3 +67,29 @@ func IsUUIDWithLocality() schema.SchemaValidateDiagFunc {
6667
return IsUUID()(subUUID, path)
6768
}
6869
}
70+
71+
func IsUUIDOrNameOffer() schema.SchemaValidateDiagFunc {
72+
return func(value interface{}, path cty.Path) diag.Diagnostics {
73+
uuid, _ := value.(string)
74+
if !validation.IsUUID(uuid) {
75+
return diag.Diagnostics{diag.Diagnostic{
76+
Severity: diag.Warning,
77+
Summary: "Using a datasource for better consistency and reliability is recommended instead of directly using offer names.",
78+
AttributePath: path,
79+
Detail: fmt.Sprintf(
80+
`The offer name should be retrieved using a datasource to ensure reliable and consistent configuration.
81+
82+
Example:
83+
data "scaleway_baremetal_offer" "my_offer_monthly" {
84+
zone = "fr-par-2"
85+
name = "EM-B112X-SSD"
86+
subscription_period = "monthly"
87+
}
88+
89+
Then, you can reference the datasource's attributes in your resources.`,
90+
),
91+
}}
92+
}
93+
return nil
94+
}
95+
}

0 commit comments

Comments
 (0)