@@ -25,53 +25,54 @@ func ResourceCockpit() *schema.Resource {
2525 Type : schema .TypeString ,
2626 Optional : true ,
2727 Default : "free" ,
28- Description : "Name or ID of the plan" ,
28+ Description : "[DEPRECATED] The plan field is deprecated. Any modification or selection will have no effect." ,
29+ Deprecated : "The 'plan' attribute is deprecated and no longer has any effect. Future updates will remove this attribute entirely." ,
2930 },
3031 "plan_id" : {
3132 Type : schema .TypeString ,
3233 Computed : true ,
33- Description : "The plan ID of the cockpit" ,
34- Deprecated : "Please use Name only " ,
34+ Description : "[DEPRECATED] The plan ID of the cockpit. This field is no longer relevant. " ,
35+ Deprecated : "The 'plan_id' attribute is deprecated and will be removed in a future release. " ,
3536 },
3637 "endpoints" : {
3738 Type : schema .TypeList ,
3839 Computed : true ,
39- Description : "Endpoints" ,
40- Deprecated : "Please use ` scaleway_cockpit_source` instead" ,
40+ Description : "[DEPRECATED] Endpoints list. Please use 'scaleway_cockpit_source' instead. " ,
41+ Deprecated : "Use ' scaleway_cockpit_source' instead of 'endpoints'. This field will be removed in future releases. " ,
4142 Elem : & schema.Resource {
4243 Schema : map [string ]* schema.Schema {
4344 "metrics_url" : {
4445 Type : schema .TypeString ,
4546 Computed : true ,
46- Description : "The metrics URL" ,
47+ Description : "The metrics URL. " ,
4748 },
4849 "logs_url" : {
4950 Type : schema .TypeString ,
5051 Computed : true ,
51- Description : "The logs URL" ,
52+ Description : "The logs URL. " ,
5253 },
5354 "alertmanager_url" : {
5455 Type : schema .TypeString ,
5556 Computed : true ,
56- Description : "The alertmanager URL" ,
57+ Description : "The alertmanager URL. " ,
5758 },
5859 "grafana_url" : {
5960 Type : schema .TypeString ,
6061 Computed : true ,
61- Description : "The grafana URL" ,
62+ Description : "The grafana URL. " ,
6263 },
6364 "traces_url" : {
6465 Type : schema .TypeString ,
6566 Computed : true ,
66- Description : "The traces URL" ,
67+ Description : "The traces URL. " ,
6768 },
6869 },
6970 },
7071 },
7172 "push_url" : {
7273 Type : schema .TypeList ,
7374 Computed : true ,
74- Description : "Push_url" ,
75+ Description : "[DEPRECATED] Push_url" ,
7576 Deprecated : "Please use `scaleway_cockpit_source` instead" ,
7677 Elem : & schema.Resource {
7778 Schema : map [string ]* schema.Schema {
@@ -93,48 +94,22 @@ func ResourceCockpit() *schema.Resource {
9394}
9495
9596func ResourceCockpitCreate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
96- api , err := NewGlobalAPI (m )
97- if err != nil {
98- return diag .FromErr (err )
99- }
100-
10197 projectID := d .Get ("project_id" ).(string )
102-
103- if targetPlanI , ok := d .GetOk ("plan" ); ok {
104- targetPlan := targetPlanI .(string )
105-
106- plans , err := api .ListPlans (& cockpit.GlobalAPIListPlansRequest {}, scw .WithContext (ctx ), scw .WithAllPages ()) //nolint:staticcheck
107- if err != nil {
108- return diag .FromErr (err )
109- }
110-
111- var planName string
112-
113- for _ , plan := range plans .Plans {
114- if plan .Name .String () == targetPlan {
115- planName = plan .Name .String ()
116-
117- break
118- }
119- }
120-
121- if planName == "" {
122- return diag .Errorf ("plan %s not found" , targetPlan )
123- }
124-
125- _ , err = api .SelectPlan (& cockpit.GlobalAPISelectPlanRequest { //nolint:staticcheck
126- ProjectID : projectID ,
127- PlanName : cockpit .PlanName (planName ),
128- }, scw .WithContext (ctx ))
98+ if projectID == "" {
99+ _ , err := getDefaultProjectID (ctx , m )
129100 if err != nil {
130101 return diag .FromErr (err )
131102 }
132103 }
133104
105+ d .SetId (projectID )
106+
134107 return ResourceCockpitRead (ctx , d , m )
135108}
136109
137110func ResourceCockpitRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
111+ var diags diag.Diagnostics
112+
138113 api , err := NewGlobalAPI (m )
139114 if err != nil {
140115 return diag .FromErr (err )
@@ -153,15 +128,14 @@ func ResourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interfac
153128 }
154129 }
155130
156- res , err := api .GetCurrentPlan (& cockpit.GlobalAPIGetCurrentPlanRequest { //nolint:staticcheck
157- ProjectID : projectID ,
158- }, scw .WithContext (ctx ))
159- if err != nil {
160- return diag .FromErr (err )
161- }
131+ diags = append (diags , diag.Diagnostic {
132+ Severity : diag .Warning ,
133+ Summary : "Deprecated attribute: 'plan'" ,
134+ Detail : "The 'plan' attribute is deprecated and will be removed in a future version. Any changes to this attribute will have no effect." ,
135+ })
162136
163- _ = d .Set ("plan" , res . Name . String ( ))
164- _ = d .Set ("plan_id" , res . Name . String () )
137+ _ = d .Set ("plan" , d . Get ( "plan" ))
138+ _ = d .Set ("plan_id" , "" )
165139
166140 dataSourcesRes , err := regionalAPI .ListDataSources (& cockpit.RegionalAPIListDataSourcesRequest {
167141 Region : region ,
@@ -203,54 +177,26 @@ func ResourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interfac
203177 _ = d .Set ("endpoints" , endpoints )
204178 _ = d .Set ("push_url" , createCockpitPushURLList (endpoints ))
205179
206- return nil
180+ return diags
207181}
208182
209183func ResourceCockpitUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
210- api , err := NewGlobalAPI (m )
211- if err != nil {
212- return diag .FromErr (err )
213- }
214-
215- projectID := d .Id ()
216-
184+ diags := diag.Diagnostics {}
217185 if d .HasChange ("plan" ) {
218- targetPlan := cockpit .PlanNameFree .String ()
219- if targetPlanI , ok := d .GetOk ("plan" ); ok {
220- targetPlan = targetPlanI .(string )
221- }
222-
223- plans , err := api .ListPlans (& cockpit.GlobalAPIListPlansRequest {}, scw .WithContext (ctx ), scw .WithAllPages ()) //nolint:staticcheck
224- if err != nil {
225- return diag .FromErr (err )
226- }
227-
228- var planName string
229-
230- for _ , plan := range plans .Plans {
231- if plan .Name .String () == targetPlan {
232- planName = plan .Name .String ()
233-
234- break
235- }
236- }
237-
238- if planName == "" {
239- return diag .Errorf ("plan %s not found" , targetPlan )
240- }
241-
242- _ , err = api .SelectPlan (& cockpit.GlobalAPISelectPlanRequest { //nolint:staticcheck
243- ProjectID : projectID ,
244- PlanName : cockpit .PlanName (planName ),
245- }, scw .WithContext (ctx ))
246- if err != nil {
247- return diag .FromErr (err )
248- }
186+ diags = append (diags , diag.Diagnostic {
187+ Severity : diag .Warning ,
188+ Summary : "Deprecated attribute update: 'plan'" ,
189+ Detail : "Updating 'plan' has no effect as it is deprecated and will be removed in a future version." ,
190+ })
249191 }
250192
251- return ResourceCockpitRead (ctx , d , m )
193+ diags = append (diags , ResourceCockpitRead (ctx , d , m )... )
194+
195+ return diags
252196}
253197
254- func ResourceCockpitDelete (_ context.Context , _ * schema.ResourceData , _ interface {}) diag.Diagnostics {
198+ func ResourceCockpitDelete (_ context.Context , d * schema.ResourceData , _ interface {}) diag.Diagnostics {
199+ d .SetId ("" )
200+
255201 return nil
256202}
0 commit comments