Skip to content

Commit 8d8efdf

Browse files
author
Yago Carlos Fernandez Gou
committed
Reintroduce region as optional field in data resource
1 parent 8a9bbab commit 8d8efdf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

stackit/internal/services/intake/runner/data_source.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func NewRunnerDataSource() datasource.DataSource {
3131
}
3232

3333
type runnerDataSource struct {
34-
client *intake.APIClient
34+
client *intake.APIClient
35+
providerData core.ProviderData
3536
}
3637

3738
func (r *runnerDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
@@ -40,12 +41,13 @@ func (r *runnerDataSource) Metadata(_ context.Context, req datasource.MetadataRe
4041

4142
// Configure adds the provider configured client to the data source
4243
func (r *runnerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
43-
providerData, ok := conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
44+
var ok bool
45+
r.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
4446
if !ok {
4547
return
4648
}
4749

48-
apiClient := intakeUtils.ConfigureClient(ctx, &providerData, &resp.Diagnostics)
50+
apiClient := intakeUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
4951
if resp.Diagnostics.HasError() {
5052
return
5153
}
@@ -65,6 +67,7 @@ func (r *runnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
6567
"labels": "User-defined labels.",
6668
"max_message_size_kib": "The maximum message size in KiB.",
6769
"max_messages_per_hour": "The maximum number of messages per hour.",
70+
"region": "The resource region. If not defined, the provider region is used.",
6871
}
6972

7073
resp.Schema = schema.Schema{
@@ -111,6 +114,10 @@ func (r *runnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
111114
Description: descriptions["max_messages_per_hour"],
112115
Computed: true,
113116
},
117+
"region": schema.StringAttribute{
118+
Optional: true,
119+
Description: descriptions["region"],
120+
},
114121
},
115122
}
116123
}
@@ -126,7 +133,7 @@ func (r *runnerDataSource) Read(ctx context.Context, req datasource.ReadRequest,
126133
ctx = core.InitProviderContext(ctx)
127134

128135
projectId := model.ProjectId.ValueString()
129-
region := model.Region.ValueString()
136+
region := r.providerData.GetRegionWithOverride(model.Region)
130137
runnerId := model.RunnerId.ValueString()
131138
ctx = tflog.SetField(ctx, "project_id", projectId)
132139
ctx = tflog.SetField(ctx, "region", region)
@@ -147,7 +154,7 @@ func (r *runnerDataSource) Read(ctx context.Context, req datasource.ReadRequest,
147154

148155
ctx = core.LogResponse(ctx)
149156

150-
err = mapFields(runnerResp, &model)
157+
err = mapFields(runnerResp, &model, region)
151158
if err != nil {
152159
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading runner", fmt.Sprintf("Processing API payload: %v", err))
153160
return

0 commit comments

Comments
 (0)