66
77 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9- webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1alpha1 "
9+ webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1 "
1010 "github.com/scaleway/scaleway-sdk-go/scw"
1111 "github.com/scaleway/terraform-provider-scaleway/v2/internal/datasource"
1212 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
@@ -33,8 +33,9 @@ func DataSourceOffer() *schema.Resource {
3333 Type : schema .TypeString ,
3434 },
3535 "product" : {
36- Type : schema .TypeList ,
37- Computed : true ,
36+ Type : schema .TypeList ,
37+ Computed : true ,
38+ Deprecated : "The product field is deprecated. Please use the offer field instead." ,
3839 Elem : & schema.Resource {
3940 Schema : map [string ]* schema.Schema {
4041 "name" : {
@@ -46,32 +47,113 @@ func DataSourceOffer() *schema.Resource {
4647 Computed : true ,
4748 },
4849 "email_accounts_quota" : {
49- Computed : true ,
5050 Type : schema .TypeInt ,
51+ Computed : true ,
5152 },
5253 "email_storage_quota" : {
53- Computed : true ,
5454 Type : schema .TypeInt ,
55+ Computed : true ,
5556 },
5657 "databases_quota" : {
57- Computed : true ,
5858 Type : schema .TypeInt ,
59+ Computed : true ,
5960 },
6061 "hosting_storage_quota" : {
61- Computed : true ,
6262 Type : schema .TypeInt ,
63+ Computed : true ,
6364 },
6465 "support_included" : {
65- Computed : true ,
6666 Type : schema .TypeBool ,
67+ Computed : true ,
6768 },
6869 "v_cpu" : {
69- Computed : true ,
7070 Type : schema .TypeInt ,
71+ Computed : true ,
7172 },
7273 "ram" : {
73- Computed : true ,
7474 Type : schema .TypeInt ,
75+ Computed : true ,
76+ },
77+ },
78+ },
79+ },
80+ "offer" : {
81+ Type : schema .TypeList ,
82+ Computed : true ,
83+ Description : "The offer details of the hosting" ,
84+ Elem : & schema.Resource {
85+ Schema : map [string ]* schema.Schema {
86+ "id" : {
87+ Type : schema .TypeString ,
88+ Computed : true ,
89+ },
90+ "name" : {
91+ Type : schema .TypeString ,
92+ Computed : true ,
93+ },
94+ "billing_operation_path" : {
95+ Type : schema .TypeString ,
96+ Computed : true ,
97+ },
98+ "available" : {
99+ Type : schema .TypeBool ,
100+ Computed : true ,
101+ },
102+ "control_panel_name" : {
103+ Type : schema .TypeString ,
104+ Computed : true ,
105+ },
106+ "end_of_life" : {
107+ Type : schema .TypeBool ,
108+ Computed : true ,
109+ },
110+ "quota_warning" : {
111+ Type : schema .TypeString ,
112+ Computed : true ,
113+ },
114+ "price" : {
115+ Type : schema .TypeString ,
116+ Computed : true ,
117+ },
118+ "options" : {
119+ Type : schema .TypeList ,
120+ Computed : true ,
121+ Elem : & schema.Resource {
122+ Schema : map [string ]* schema.Schema {
123+ "id" : {
124+ Type : schema .TypeString ,
125+ Computed : true ,
126+ },
127+ "name" : {
128+ Type : schema .TypeString ,
129+ Computed : true ,
130+ },
131+ "billing_operation_path" : {
132+ Type : schema .TypeString ,
133+ Computed : true ,
134+ },
135+ "min_value" : {
136+ Type : schema .TypeInt ,
137+ Computed : true ,
138+ },
139+ "current_value" : {
140+ Type : schema .TypeInt ,
141+ Computed : true ,
142+ },
143+ "max_value" : {
144+ Type : schema .TypeInt ,
145+ Computed : true ,
146+ },
147+ "quota_warning" : {
148+ Type : schema .TypeString ,
149+ Computed : true ,
150+ },
151+ "price" : {
152+ Type : schema .TypeString ,
153+ Computed : true ,
154+ },
155+ },
156+ },
75157 },
76158 },
77159 },
@@ -86,12 +168,12 @@ func DataSourceOffer() *schema.Resource {
86168}
87169
88170func dataSourceOfferRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
89- api , region , err := newAPIWithRegion (d , m )
171+ api , region , err := newOfferAPIWithRegion (d , m )
90172 if err != nil {
91173 return diag .FromErr (err )
92174 }
93175
94- res , err := api .ListOffers (& webhosting.ListOffersRequest {
176+ res , err := api .ListOffers (& webhosting.OfferAPIListOffersRequest {
95177 Region : region ,
96178 }, scw .WithContext (ctx ))
97179 if err != nil {
@@ -105,8 +187,9 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
105187 var filteredOffer * webhosting.Offer
106188
107189 for _ , offer := range res .Offers {
108- if offer .ID == d .Get ("offer_id" ) || offer .Product . Name == d .Get ("name" ) {
190+ if offer .ID == d .Get ("offer_id" ) || offer .Name == d .Get ("name" ) {
109191 filteredOffer = offer
192+ break
110193 }
111194 }
112195
@@ -117,10 +200,11 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
117200 regionalID := datasource .NewRegionalID (filteredOffer .ID , region )
118201 d .SetId (regionalID )
119202 _ = d .Set ("offer_id" , regionalID )
120- _ = d .Set ("name" , filteredOffer .Product . Name )
203+ _ = d .Set ("name" , filteredOffer .Name )
121204 _ = d .Set ("region" , region )
122205 _ = d .Set ("billing_operation_path" , filteredOffer .BillingOperationPath )
123- _ = d .Set ("product" , flattenOfferProduct (filteredOffer .Product ))
206+ _ = d .Set ("product" , nil )
207+ _ = d .Set ("offer" , flattenOffer (filteredOffer ))
124208 _ = d .Set ("price" , flattenOfferPrice (filteredOffer .Price ))
125209
126210 return nil
0 commit comments