Skip to content

Commit d2b7b07

Browse files
authored
fix(cockpit): deprecated data source plan (#3007)
1 parent bdb8724 commit d2b7b07

File tree

4 files changed

+265
-1079
lines changed

4 files changed

+265
-1079
lines changed

internal/services/cockpit/plan_data_source.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
"github.com/scaleway/scaleway-sdk-go/api/cockpit/v1"
9-
"github.com/scaleway/scaleway-sdk-go/scw"
108
)
119

1210
func DataSourcePlan() *schema.Resource {
@@ -15,43 +13,24 @@ func DataSourcePlan() *schema.Resource {
1513
Schema: map[string]*schema.Schema{
1614
"name": {
1715
Type: schema.TypeString,
18-
Description: "The name of the plan",
1916
Required: true,
17+
Description: "[DEPRECATED] The plan field is deprecated.",
18+
Deprecated: "The 'plan' attribute is deprecated and no longer has any effect. Future updates will remove this attribute entirely.",
2019
},
2120
},
22-
DeprecationMessage: "The 'Plan' data source is deprecated because it duplicates the functionality of the 'scaleway_cockpit' resource. Please use the 'scaleway_cockpit' resource instead.",
21+
DeprecationMessage: "This data source is deprecated and will be removed in the next major version. Use `my_new_data_source` instead.",
2322
}
2423
}
2524

26-
func DataSourceCockpitPlanRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
27-
api, err := NewGlobalAPI(m)
28-
if err != nil {
29-
return diag.FromErr(err)
30-
}
31-
32-
name := d.Get("name").(string)
33-
34-
res, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages()) //nolint:staticcheck
35-
if err != nil {
36-
return diag.FromErr(err)
37-
}
38-
39-
var plan *cockpit.Plan
40-
41-
for _, p := range res.Plans {
42-
if p.Name.String() == name {
43-
plan = p
25+
func DataSourceCockpitPlanRead(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
26+
d.SetId("free")
27+
_ = d.Set("name", "free")
4428

45-
break
46-
}
47-
}
48-
49-
if plan == nil {
50-
return diag.Errorf("could not find plan with name %s", name)
29+
return diag.Diagnostics{
30+
diag.Diagnostic{
31+
Severity: diag.Warning,
32+
Summary: "Data source 'cockpit_plan' has been removed",
33+
Detail: "The 'cockpit_plan' data source has been deprecated and is no longer available.",
34+
},
5135
}
52-
53-
d.SetId(plan.Name.String())
54-
_ = d.Set("name", plan.Name.String())
55-
56-
return nil
5736
}

internal/services/cockpit/plan_data_source_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cockpit_test
22

33
import (
4-
"regexp"
54
"testing"
65

76
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -36,14 +35,6 @@ func TestAccDataSourceCockpitPlan_Basic(t *testing.T) {
3635
resource.TestCheckResourceAttrSet("data.scaleway_cockpit_plan.custom", "id"),
3736
),
3837
},
39-
{
40-
Config: `
41-
data "scaleway_cockpit_plan" "random" {
42-
name = "plan? there ain't no plan"
43-
}
44-
`,
45-
ExpectError: regexp.MustCompile("could not find plan"),
46-
},
4738
},
4839
})
4940
}

0 commit comments

Comments
 (0)