Skip to content

Commit 6df5107

Browse files
committed
project_allowed_load_zones resource - project_id as str
1 parent d7f7061 commit 6df5107

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

internal/resources/k6/data_source_k6_project_allowed_load_zones.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package k6
22

33
import (
44
"context"
5+
"strconv"
56

67
"github.com/hashicorp/terraform-plugin-framework/attr"
78
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -30,8 +31,9 @@ func dataSourceProjectAllowedLoadZones() *common.DataSource {
3031

3132
// projectAllowedLoadZonesDataSourceModel maps the data source schema data.
3233
type projectAllowedLoadZonesDataSourceModel struct {
33-
ProjectID types.Int32 `tfsdk:"project_id"`
34-
AllowedLoadZones types.List `tfsdk:"allowed_load_zones"`
34+
ID types.String `tfsdk:"id"`
35+
ProjectID types.String `tfsdk:"project_id"`
36+
AllowedLoadZones types.List `tfsdk:"allowed_load_zones"`
3537
}
3638

3739
// projectAllowedLoadZonesDataSource is the data source implementation.
@@ -49,7 +51,11 @@ func (d *projectAllowedLoadZonesDataSource) Schema(_ context.Context, _ datasour
4951
resp.Schema = schema.Schema{
5052
Description: "Retrieves allowed load zones for a k6 project.",
5153
Attributes: map[string]schema.Attribute{
52-
"project_id": schema.Int32Attribute{
54+
"id": schema.StringAttribute{
55+
Description: "The identifier of the project allowed load zones. This is set to the same as the project_id.",
56+
Computed: true,
57+
},
58+
"project_id": schema.StringAttribute{
5359
Description: "The identifier of the project to retrieve allowed load zones for.",
5460
Required: true,
5561
},
@@ -71,7 +77,15 @@ func (d *projectAllowedLoadZonesDataSource) Read(ctx context.Context, req dataso
7177
return
7278
}
7379

74-
projectID := state.ProjectID.ValueInt32()
80+
intID, err := strconv.ParseInt(state.ProjectID.ValueString(), 10, 32)
81+
if err != nil {
82+
resp.Diagnostics.AddError(
83+
"Error parsing project ID",
84+
"Could not parse project ID '"+state.ProjectID.ValueString()+"': "+err.Error(),
85+
)
86+
return
87+
}
88+
projectID := int32(intID)
7589

7690
// Get allowed load zones
7791
allowedZones, err := getProjectAllowedLoadZones(ctx, d.client, d.config, projectID)
@@ -83,6 +97,9 @@ func (d *projectAllowedLoadZonesDataSource) Read(ctx context.Context, req dataso
8397
return
8498
}
8599

100+
// Set ID to match project_id
101+
state.ID = state.ProjectID
102+
86103
// Convert to types.List
87104
var zoneValues []attr.Value
88105
for _, zone := range allowedZones {

0 commit comments

Comments
 (0)