Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions internal/services/cockpit/plan_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/api/cockpit/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

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

func DataSourceCockpitPlanRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api, err := NewGlobalAPI(m)
if err != nil {
return diag.FromErr(err)
}

name := d.Get("name").(string)

res, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages()) //nolint:staticcheck
if err != nil {
return diag.FromErr(err)
}

var plan *cockpit.Plan

for _, p := range res.Plans {
if p.Name.String() == name {
plan = p
func DataSourceCockpitPlanRead(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
d.SetId("free")
_ = d.Set("name", "free")

break
}
}

if plan == nil {
return diag.Errorf("could not find plan with name %s", name)
return diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Warning,
Summary: "Data source 'cockpit_plan' has been removed",
Detail: "The 'cockpit_plan' data source has been deprecated and is no longer available.",
},
}

d.SetId(plan.Name.String())
_ = d.Set("name", plan.Name.String())

return nil
}
9 changes: 0 additions & 9 deletions internal/services/cockpit/plan_data_source_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cockpit_test

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -36,14 +35,6 @@ func TestAccDataSourceCockpitPlan_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet("data.scaleway_cockpit_plan.custom", "id"),
),
},
{
Config: `
data "scaleway_cockpit_plan" "random" {
name = "plan? there ain't no plan"
}
`,
ExpectError: regexp.MustCompile("could not find plan"),
},
},
})
}
Loading
Loading