@@ -2,14 +2,31 @@ package baremetal
22
33import (
44 "context"
5+ "fmt"
56 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+ "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
9+ "github.com/scaleway/scaleway-sdk-go/scw"
10+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
11+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
712)
813
914func DataEasyPartitioning () * schema.Resource {
1015 return & schema.Resource {
1116 ReadContext : dataEasyPartitioningRead ,
1217 Schema : map [string ]* schema.Schema {
18+ "offer_id" : {
19+ Type : schema .TypeString ,
20+ Required : true ,
21+ Description : "ID of the server offer" ,
22+ },
23+ "os" : {
24+ Type : schema .TypeString ,
25+ Required : true ,
26+ Description : "The base image of the server" ,
27+ DiffSuppressFunc : dsf .Locality ,
28+ ValidateDiagFunc : verify .IsUUIDorUUIDWithLocality (),
29+ },
1330 "swap" : {
1431 Type : schema .TypeBool ,
1532 Optional : true ,
@@ -26,13 +43,67 @@ func DataEasyPartitioning() *schema.Resource {
2643 Type : schema .TypeString ,
2744 Optional : true ,
2845 Default : "/data" ,
29- Description : "ext_4 partition's name" ,
46+ Description : "Mount point must be an absolute path with alphanumeric characters and underscores" ,
47+ },
48+ "custom_partition" : {
49+ Type : schema .TypeString ,
50+ Optional : true ,
51+ Description : "The partitioning schema in json format" ,
3052 },
3153 },
3254 }
3355}
3456
3557func dataEasyPartitioningRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
58+ api , fallBackZone , err := newAPIWithZone (d , m )
59+ if err != nil {
60+ return diag .FromErr (err )
61+ }
62+
63+ osID := d .Get ("os" ).(string )
64+
65+ os , err := api .GetOS (& baremetal.GetOSRequest {
66+ Zone : fallBackZone ,
67+ OsID : osID ,
68+ }, scw .WithContext (ctx ))
69+ if err != nil {
70+ return diag .FromErr (err )
71+ }
72+
73+ if ! os .CustomPartitioningSupported {
74+ return diag .FromErr (fmt .Errorf ("custom partitioning is not supported with this OS" ))
75+ }
76+
77+ offerID := d .Get ("offer_id" ).(string )
78+
79+ offer , err := api .GetOffer (& baremetal.GetOfferRequest {
80+ Zone : fallBackZone ,
81+ OfferID : offerID ,
82+ }, scw .WithContext (ctx ))
83+ if err != nil {
84+ return diag .FromErr (err )
85+ }
86+
87+ if ! isOSCompatible (offer , os ) {
88+ return diag .FromErr (fmt .Errorf ("os and offer are not compatible" ))
89+ }
90+
91+ defaultPartitioningSchema , err := api .GetDefaultPartitioningSchema (& baremetal.GetDefaultPartitioningSchemaRequest {
92+ Zone : fallBackZone ,
93+ OfferID : offerID ,
94+ OsID : osID ,
95+ }, scw .WithContext (ctx ))
96+ if err != nil {
97+ return diag .FromErr (err )
98+ }
99+
100+ //TODO checker si offer custom partitoning
101+ //TODO checker si offer et os compatible
102+ //TODO get default partitioning
103+ //TODO unmarshall
104+ //TODO replacer les valeurs
105+ //TODO marshal
106+
36107 var diags diag.Diagnostics
37108 return diags
38109}
0 commit comments