@@ -2,6 +2,7 @@ package k6
2
2
3
3
import (
4
4
"context"
5
+ "strconv"
5
6
6
7
"github.com/hashicorp/terraform-plugin-framework/attr"
7
8
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -30,8 +31,9 @@ func dataSourceProjectAllowedLoadZones() *common.DataSource {
30
31
31
32
// projectAllowedLoadZonesDataSourceModel maps the data source schema data.
32
33
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"`
35
37
}
36
38
37
39
// projectAllowedLoadZonesDataSource is the data source implementation.
@@ -49,7 +51,11 @@ func (d *projectAllowedLoadZonesDataSource) Schema(_ context.Context, _ datasour
49
51
resp .Schema = schema.Schema {
50
52
Description : "Retrieves allowed load zones for a k6 project." ,
51
53
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 {
53
59
Description : "The identifier of the project to retrieve allowed load zones for." ,
54
60
Required : true ,
55
61
},
@@ -71,7 +77,15 @@ func (d *projectAllowedLoadZonesDataSource) Read(ctx context.Context, req dataso
71
77
return
72
78
}
73
79
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 )
75
89
76
90
// Get allowed load zones
77
91
allowedZones , err := getProjectAllowedLoadZones (ctx , d .client , d .config , projectID )
@@ -83,6 +97,9 @@ func (d *projectAllowedLoadZonesDataSource) Read(ctx context.Context, req dataso
83
97
return
84
98
}
85
99
100
+ // Set ID to match project_id
101
+ state .ID = state .ProjectID
102
+
86
103
// Convert to types.List
87
104
var zoneValues []attr.Value
88
105
for _ , zone := range allowedZones {
0 commit comments