Skip to content

Fix context and defer issues in Configure methods #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 3 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
5 changes: 5 additions & 0 deletions .changes/unreleased/fixed-20250605-093625.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: fixed
body: Fix context and defer issues in Configure methods to avoid unnecessary resource allocation when ProviderData is nil
time: 2025-06-05T09:36:25.40303494Z
custom:
Issue: "819"
Original file line number Diff line number Diff line change
@@ -64,13 +64,12 @@
}

func (r *AdminManagementApplicationResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -93,12 +93,12 @@
}

func (r *EnvironmentApplicationAdminResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -75,12 +75,12 @@
}

func (r *EnvironmentApplicationPackageInstallResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
4 changes: 2 additions & 2 deletions internal/services/authorization/resource_user.go
Original file line number Diff line number Diff line change
@@ -135,12 +135,12 @@
}

func (r *UserResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
4 changes: 2 additions & 2 deletions internal/services/connection/resource_connection.go
Original file line number Diff line number Diff line change
@@ -122,12 +122,12 @@
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
5 changes: 2 additions & 3 deletions internal/services/connection/resource_connection_share.go
Original file line number Diff line number Diff line change
@@ -118,13 +118,12 @@
}

func (r *ShareResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
resp.Diagnostics.AddError(
Original file line number Diff line number Diff line change
@@ -109,13 +109,12 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
5 changes: 2 additions & 3 deletions internal/services/data_record/resource_data_record.go
Original file line number Diff line number Diff line change
@@ -104,13 +104,12 @@
}

func (r *DataRecordResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

clientApi := req.ProviderData.(*api.ProviderClient).Api
if clientApi == nil {
4 changes: 2 additions & 2 deletions internal/services/dlp_policy/resource_dlp_policy.go
Original file line number Diff line number Diff line change
@@ -215,12 +215,12 @@
}

func (r *DataLossPreventionPolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
resp.Diagnostics.AddError(
Original file line number Diff line number Diff line change
@@ -45,13 +45,12 @@ func (r *Resource) Metadata(ctx context.Context, req resource.MetadataRequest, r
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
5 changes: 2 additions & 3 deletions internal/services/environment/resource_environment.go
Original file line number Diff line number Diff line change
@@ -375,13 +375,12 @@ func (d *Resource) ConfigValidators(ctx context.Context) []resource.ConfigValida
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -262,12 +262,12 @@
}

func (r *environmentGroupRuleSetResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client := req.ProviderData.(*api.ProviderClient).Api
if client == nil {
Original file line number Diff line number Diff line change
@@ -70,12 +70,12 @@
}

func (r *EnvironmentGroupResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -291,12 +291,12 @@
}

func (r *EnvironmentSettingsResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client := req.ProviderData.(*api.ProviderClient).Api

Original file line number Diff line number Diff line change
@@ -82,12 +82,11 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
4 changes: 2 additions & 2 deletions internal/services/licensing/resource_billing_policy.go
Original file line number Diff line number Diff line change
@@ -115,12 +115,12 @@
}

func (r *BillingPolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -72,12 +72,12 @@
}

func (r *BillingPolicyEnvironmentResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -52,12 +52,12 @@
}

func (r *ManagedEnvironmentResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
5 changes: 2 additions & 3 deletions internal/services/rest/resource_rest.go
Original file line number Diff line number Diff line change
@@ -182,13 +182,12 @@
}

func (r *DataverseWebApiResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
4 changes: 2 additions & 2 deletions internal/services/solution/resource_solution.go
Original file line number Diff line number Diff line change
@@ -123,12 +123,12 @@
}

func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
Original file line number Diff line number Diff line change
@@ -100,13 +100,12 @@

// Configure configures the resource with the provider client.
func (r *Resource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client, ok := req.ProviderData.(*api.ProviderClient)
if !ok {
4 changes: 2 additions & 2 deletions internal/services/tenant_settings/resource_tenant_settings.go
Original file line number Diff line number Diff line change
@@ -337,12 +337,12 @@
}

func (r *TenantSettingsResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()
if req.ProviderData == nil {
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
return
}
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
defer exitContext()

client := req.ProviderData.(*api.ProviderClient).Api

Loading
Oops, something went wrong.