Skip to content
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions internal/service/cloud/zone_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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`.",
Expand All @@ -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
}

Expand All @@ -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)
Expand Down
39 changes: 10 additions & 29 deletions upcloud/datasource_upcloud_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}`
)

Expand All @@ -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),
),
},
},
})
}
Loading