diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fdf07a77..26fe52025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Fixed + +- remove name field from upcloud_zone data source + ## [5.20.3] - 2025-03-06 ### Fixed diff --git a/internal/service/cloud/zone_data_source.go b/internal/service/cloud/zone_data_source.go index aaefe1162..281617a10 100644 --- a/internal/service/cloud/zone_data_source.go +++ b/internal/service/cloud/zone_data_source.go @@ -34,7 +34,6 @@ func (d *zoneDataSource) Configure(_ context.Context, req datasource.ConfigureRe type zoneModel struct { ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` Public types.Bool `tfsdk:"public"` ParentZone types.String `tfsdk:"parent_zone"` @@ -45,17 +44,9 @@ func (d *zoneDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r Description: "Provides details on given zone.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Optional: true, // TODO: Make required when removing name field - Computed: true, + Required: true, Description: "Identifier of the zone.", }, - // TODO: Remove name field on next major release - "name": schema.StringAttribute{ - Optional: true, - Computed: true, - DeprecationMessage: "Contains the same value as `id`. Use `id` instead.", - Description: "Identifier of the zone. Contains the same value as `id`. If both `id` and `name` are set, `id` takes precedence.", - }, "description": schema.StringAttribute{ Computed: true, Description: "Identifier of the zone. Contains the same value as `id`.", @@ -78,11 +69,7 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r id := data.ID.ValueString() if id == "" { - id = data.Name.ValueString() - data.ID = types.StringValue(id) - } - if id == "" { - resp.Diagnostics.AddError("Either `id` or `name` must be set", "Both `id` and `name` are empty.") + resp.Diagnostics.AddError("`id` must be set", "`id` in `upcloud_zone` data source can't be empty.") return } @@ -108,7 +95,6 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r return } - data.Name = types.StringValue(zone.ID) data.Description = types.StringValue(zone.Description) data.Public = types.BoolValue(zone.Public.Bool()) data.ParentZone = types.StringValue(zone.ParentZone) diff --git a/upcloud/datasource_upcloud_zone_test.go b/upcloud/datasource_upcloud_zone_test.go index 62142c6e1..b164a6c88 100644 --- a/upcloud/datasource_upcloud_zone_test.go +++ b/upcloud/datasource_upcloud_zone_test.go @@ -7,18 +7,9 @@ import ( ) const ( - configWithName = ` -data "upcloud_zone" "my_zone" { - name = "uk-lon1" -}` configWithID = ` data "upcloud_zone" "my_zone" { id = "uk-lon1" -}` - configWithNameAndID = ` -data "upcloud_zone" "my_zone" { - id = "uk-lon1" - name = "de-fra1" }` ) @@ -29,28 +20,18 @@ func TestAccDataSourceUpCloudZone_basic(t *testing.T) { expectedDescription := "London #1" expectedPublic := "true" - var steps []resource.TestStep - for _, config := range []string{ - configWithName, - configWithID, - configWithNameAndID, - } { - steps = append(steps, resource.TestStep{ - Config: config, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr( - resourceName, "name", expectedZoneName), - resource.TestCheckResourceAttr( - resourceName, "description", expectedDescription), - resource.TestCheckResourceAttr( - resourceName, "public", expectedPublic), - ), - }) - } - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProviderFactories, - Steps: steps, + Steps: []resource.TestStep{ + { + Config: configWithID, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", expectedZoneName), + resource.TestCheckResourceAttr(resourceName, "description", expectedDescription), + resource.TestCheckResourceAttr(resourceName, "public", expectedPublic), + ), + }, + }, }) }