@@ -33,11 +33,11 @@ func dataSourceLoadTest() *common.DataSource {
3333
3434// loadTestDataSourceModel maps the data source schema data.
3535type loadTestDataSourceModel struct {
36- ID types.Int32 `tfsdk:"id"`
37- ProjectID types.Int32 `tfsdk:"project_id"`
36+ ID types.String `tfsdk:"id"`
37+ ProjectID types.String `tfsdk:"project_id"`
3838 Name types.String `tfsdk:"name"`
3939 Script types.String `tfsdk:"script"`
40- BaselineTestRunID types.Int32 `tfsdk:"baseline_test_run_id"`
40+ BaselineTestRunID types.String `tfsdk:"baseline_test_run_id"`
4141 Created types.String `tfsdk:"created"`
4242 Updated types.String `tfsdk:"updated"`
4343}
@@ -57,11 +57,11 @@ func (d *loadTestDataSource) Schema(_ context.Context, _ datasource.SchemaReques
5757 resp .Schema = schema.Schema {
5858 Description : "Retrieves a k6 load test." ,
5959 Attributes : map [string ]schema.Attribute {
60- "id" : schema.Int32Attribute {
60+ "id" : schema.StringAttribute {
6161 Description : "Numeric identifier of the load test." ,
6262 Required : true ,
6363 },
64- "project_id" : schema.Int32Attribute {
64+ "project_id" : schema.StringAttribute {
6565 Description : "The identifier of the project this load test belongs to." ,
6666 Computed : true ,
6767 },
@@ -73,7 +73,7 @@ func (d *loadTestDataSource) Schema(_ context.Context, _ datasource.SchemaReques
7373 Description : "The k6 test script content." ,
7474 Computed : true ,
7575 },
76- "baseline_test_run_id" : schema.Int32Attribute {
76+ "baseline_test_run_id" : schema.StringAttribute {
7777 Description : "Identifier of a baseline test run used for results comparison." ,
7878 Computed : true ,
7979 },
@@ -98,35 +98,45 @@ func (d *loadTestDataSource) Read(ctx context.Context, req datasource.ReadReques
9898 return
9999 }
100100
101+ intID , err := strconv .ParseInt (state .ID .ValueString (), 10 , 32 )
102+ if err != nil {
103+ resp .Diagnostics .AddError (
104+ "Error parsing load test ID" ,
105+ "Could not parse load test ID '" + state .ID .ValueString ()+ "': " + err .Error (),
106+ )
107+ return
108+ }
109+ loadTestID := int32 (intID )
110+
101111 // Retrieve the load test attributes
102112 ctx = context .WithValue (ctx , k6 .ContextAccessToken , d .config .Token )
103- k6Req := d .client .LoadTestsAPI .LoadTestsRetrieve (ctx , state . ID . ValueInt32 () ).
113+ k6Req := d .client .LoadTestsAPI .LoadTestsRetrieve (ctx , loadTestID ).
104114 XStackId (d .config .StackID )
105115
106116 lt , _ , err := k6Req .Execute ()
107117 if err != nil {
108118 resp .Diagnostics .AddError (
109119 "Error reading k6 load test" ,
110- "Could not read k6 load test with id " + strconv . Itoa ( int ( state .ID .ValueInt32 ()) )+ ": " + err .Error (),
120+ "Could not read k6 load test with id " + state .ID .ValueString ( )+ ": " + err .Error (),
111121 )
112122 return
113123 }
114124
115125 // Retrieve the load test script content
116- scriptReq := d .client .LoadTestsAPI .LoadTestsScriptRetrieve (ctx , state . ID . ValueInt32 () ).
126+ scriptReq := d .client .LoadTestsAPI .LoadTestsScriptRetrieve (ctx , loadTestID ).
117127 XStackId (d .config .StackID )
118128
119129 script , _ , err := scriptReq .Execute ()
120130 if err != nil {
121131 resp .Diagnostics .AddError (
122132 "Error reading k6 load test script" ,
123- "Could not read k6 load test script with id " + strconv . Itoa ( int ( state .ID .ValueInt32 ()) )+ ": " + err .Error (),
133+ "Could not read k6 load test script with id " + state .ID .ValueString ( )+ ": " + err .Error (),
124134 )
125135 return
126136 }
127137
128138 state .Name = types .StringValue (lt .GetName ())
129- state .ProjectID = types .Int32Value ( lt .GetProjectId ())
139+ state .ProjectID = types .StringValue ( strconv . Itoa ( int ( lt .GetProjectId ()) ))
130140 state .BaselineTestRunID = handleBaselineTestRunID (lt .GetBaselineTestRunId ())
131141 state .Script = types .StringValue (script )
132142 state .Created = types .StringValue (lt .GetCreated ().Format (time .RFC3339Nano ))
@@ -136,10 +146,10 @@ func (d *loadTestDataSource) Read(ctx context.Context, req datasource.ReadReques
136146 resp .Diagnostics .Append (diags ... )
137147}
138148
139- func handleBaselineTestRunID (baselineTestRunID int32 ) types.Int32 {
149+ func handleBaselineTestRunID (baselineTestRunID int32 ) types.String {
140150 if baselineTestRunID == 0 {
141151 // If the API returned 0, set it as null
142- return types .Int32Null ()
152+ return types .StringNull ()
143153 }
144- return types .Int32Value ( baselineTestRunID )
154+ return types .StringValue ( strconv . Itoa ( int ( baselineTestRunID )) )
145155}
0 commit comments