Skip to content

Commit a247f9e

Browse files
authored
fix(baremetal): add warning offer (#3002)
* fix(baremetal): add warning offer * fix linter
1 parent fadbd55 commit a247f9e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,28 @@ func IsUUIDWithLocality() schema.SchemaValidateDiagFunc {
6666
return IsUUID()(subUUID, path)
6767
}
6868
}
69+
70+
func IsUUIDOrNameOffer() schema.SchemaValidateDiagFunc {
71+
return func(value interface{}, path cty.Path) diag.Diagnostics {
72+
uuid, _ := value.(string)
73+
if !validation.IsUUID(uuid) {
74+
return diag.Diagnostics{diag.Diagnostic{
75+
Severity: diag.Warning,
76+
Summary: "Using a datasource for better consistency and reliability is recommended instead of directly using offer names.",
77+
AttributePath: path,
78+
Detail: `The offer name should be retrieved using a datasource to ensure reliable and consistent configuration.
79+
80+
Example:
81+
data "scaleway_baremetal_offer" "my_offer_monthly" {
82+
zone = "fr-par-2"
83+
name = "EM-B112X-SSD"
84+
subscription_period = "monthly"
85+
}
86+
87+
Then, you can reference the datasource's attributes in your resources.`,
88+
}}
89+
}
90+
91+
return nil
92+
}
93+
}

0 commit comments

Comments
 (0)