99 "github.com/scaleway/scaleway-sdk-go/scw"
1010 "github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1111 "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
12+ "strings"
1213)
1314
1415func DataEasyPartitioning () * schema.Resource {
@@ -37,9 +38,9 @@ func DataEasyPartitioning() *schema.Resource {
3738 Type : schema .TypeBool ,
3839 Optional : true ,
3940 Default : true ,
40- Description : "set ext_4 partition" ,
41+ Description : "set extra ext_4 partition" ,
4142 },
42- "ext_4_name" : {
43+ "ext_4_name" : { //TODO change to mount point
4344 Type : schema .TypeString ,
4445 Optional : true ,
4546 Default : "/data" ,
@@ -54,6 +55,67 @@ func DataEasyPartitioning() *schema.Resource {
5455 }
5556}
5657
58+ func removeSwap (defaultDisks []* baremetal.SchemaDisk , extraPartition bool ) []* baremetal.SchemaDisk {
59+ var swapSize scw.Size
60+ var newPartition []* baremetal.SchemaPartition
61+ var newDisks []* baremetal.SchemaDisk
62+ var disk * baremetal.SchemaDisk
63+
64+ for _ , oldDisk := range defaultDisks {
65+ for _ , partition := range oldDisk .Partitions {
66+ if partition .Label == "swap" {
67+ swapSize = partition .Size
68+ continue
69+ }
70+ if partition .Label == "boot" && ! extraPartition {
71+ partition .Size += swapSize
72+ } else if partition .Label == "boot" && extraPartition {
73+ partition .Size = 20000000000
74+ }
75+ newPartition = append (newPartition , partition )
76+ }
77+ disk .Device = oldDisk .Device
78+ disk .Partitions = newPartition
79+ newDisks = append (newDisks , oldDisk )
80+ }
81+ return newDisks
82+ }
83+
84+ "raids" : [
85+ {
86+ "name" : "/dev/md2" ,
87+ "level" : "raid_level_1" ,
88+ "devices" : [
89+ "/dev/nvme0n1p5" ,
90+ "/dev/nvme1n1p4"
91+ ]
92+ }
93+ ],
94+ "filesystems" : [
95+ {
96+ "device" : "/dev/md2" ,
97+ "format" : "ext4" ,
98+ "mountpoint" : "/home"
99+ }
100+ ],
101+
102+ {
103+ "label" : "data" ,
104+ "number" : 4 ,
105+ "size" : 0 ,
106+ "use_all_available_space" : true
107+ }
108+
109+ func addExtraPartition (name string , extraPartition []* baremetal.SchemaDisk , defaultPartitionSchema * baremetal.Schema ) * baremetal.Schema {
110+ _ , label , _ := strings .Cut (name , "/" )
111+ data := & baremetal.SchemaPartition {
112+ Label : "" ,
113+ Number : 0 ,
114+ Size : 0 ,
115+ UseAllAvailableSpace : false ,
116+ }
117+ }
118+
57119func dataEasyPartitioningRead (ctx context .Context , d * schema .ResourceData , m interface {}) diag .Diagnostics {
58120 api , fallBackZone , err := newAPIWithZone (d , m )
59121 if err != nil {
@@ -93,15 +155,30 @@ func dataEasyPartitioningRead(ctx context.Context, d *schema.ResourceData, m int
93155 OfferID : offerID ,
94156 OsID : osID ,
95157 }, scw .WithContext (ctx ))
158+
96159 if err != nil {
97160 return diag .FromErr (err )
98161 }
99162
100- print (defaultPartitioningSchema )
101- append (defaultPartitioningSchema .Disks )
163+ extraPart := d .Get ("extra_partition" ).(bool )
164+
165+ var newDiskSchema []* baremetal.SchemaDisk
166+ if swap := d .Get ("swap" ); ! swap .(bool ) {
167+ newDiskSchema = removeSwap (defaultPartitioningSchema .Disks , extraPart )
168+ }
169+
170+ var newCustomPartition []* baremetal.Schema
171+ if extraPart {
172+ name := d .Get ("ext_4_name" ).(string )
173+ newCustomPartition = addExtraPartition (name , newDiskSchema , defaultPartitioningSchema )
174+ }
175+
176+ defaultPartitioningSchema .Disks = append (defaultPartitioningSchema .Disks )
102177 //TODO checker si offer custom partitoning2l;
103178 //TODO checker si offer et os compatible
104179 //TODO get default partitioning
180+ //TODO remove swap and increase boot size
181+ //TODO
105182 //TODO unmarshall
106183 //TODO replacer les valeurs
107184 //TODO marshal
0 commit comments