@@ -25,53 +25,54 @@ func ResourceCockpit() *schema.Resource {
25
25
Type : schema .TypeString ,
26
26
Optional : true ,
27
27
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." ,
29
30
},
30
31
"plan_id" : {
31
32
Type : schema .TypeString ,
32
33
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. " ,
35
36
},
36
37
"endpoints" : {
37
38
Type : schema .TypeList ,
38
39
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. " ,
41
42
Elem : & schema.Resource {
42
43
Schema : map [string ]* schema.Schema {
43
44
"metrics_url" : {
44
45
Type : schema .TypeString ,
45
46
Computed : true ,
46
- Description : "The metrics URL" ,
47
+ Description : "The metrics URL. " ,
47
48
},
48
49
"logs_url" : {
49
50
Type : schema .TypeString ,
50
51
Computed : true ,
51
- Description : "The logs URL" ,
52
+ Description : "The logs URL. " ,
52
53
},
53
54
"alertmanager_url" : {
54
55
Type : schema .TypeString ,
55
56
Computed : true ,
56
- Description : "The alertmanager URL" ,
57
+ Description : "The alertmanager URL. " ,
57
58
},
58
59
"grafana_url" : {
59
60
Type : schema .TypeString ,
60
61
Computed : true ,
61
- Description : "The grafana URL" ,
62
+ Description : "The grafana URL. " ,
62
63
},
63
64
"traces_url" : {
64
65
Type : schema .TypeString ,
65
66
Computed : true ,
66
- Description : "The traces URL" ,
67
+ Description : "The traces URL. " ,
67
68
},
68
69
},
69
70
},
70
71
},
71
72
"push_url" : {
72
73
Type : schema .TypeList ,
73
74
Computed : true ,
74
- Description : "Push_url" ,
75
+ Description : "[DEPRECATED] Push_url" ,
75
76
Deprecated : "Please use `scaleway_cockpit_source` instead" ,
76
77
Elem : & schema.Resource {
77
78
Schema : map [string ]* schema.Schema {
@@ -93,48 +94,22 @@ func ResourceCockpit() *schema.Resource {
93
94
}
94
95
95
96
func 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
-
101
97
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 )
129
100
if err != nil {
130
101
return diag .FromErr (err )
131
102
}
132
103
}
133
104
105
+ d .SetId (projectID )
106
+
134
107
return ResourceCockpitRead (ctx , d , m )
135
108
}
136
109
137
110
func ResourceCockpitRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
111
+ var diags diag.Diagnostics
112
+
138
113
api , err := NewGlobalAPI (m )
139
114
if err != nil {
140
115
return diag .FromErr (err )
@@ -153,15 +128,14 @@ func ResourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interfac
153
128
}
154
129
}
155
130
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
+ })
162
136
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" , "" )
165
139
166
140
dataSourcesRes , err := regionalAPI .ListDataSources (& cockpit.RegionalAPIListDataSourcesRequest {
167
141
Region : region ,
@@ -203,54 +177,26 @@ func ResourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interfac
203
177
_ = d .Set ("endpoints" , endpoints )
204
178
_ = d .Set ("push_url" , createCockpitPushURLList (endpoints ))
205
179
206
- return nil
180
+ return diags
207
181
}
208
182
209
183
func 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 {}
217
185
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
+ })
249
191
}
250
192
251
- return ResourceCockpitRead (ctx , d , m )
193
+ diags = append (diags , ResourceCockpitRead (ctx , d , m )... )
194
+
195
+ return diags
252
196
}
253
197
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
+
255
201
return nil
256
202
}
0 commit comments