diff --git a/internal/services/users/user_data_source.go b/internal/services/users/user_data_source.go index 54c9b3b188..3e2ed8840f 100644 --- a/internal/services/users/user_data_source.go +++ b/internal/services/users/user_data_source.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/hashicorp/terraform-provider-azuread/internal/validate" ) @@ -316,7 +317,7 @@ func userDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interf if upn, ok := d.Get("user_principal_name").(string); ok && upn != "" { query := odata.Query{ - Filter: fmt.Sprintf("userPrincipalName eq '%s'", upn), + Filter: fmt.Sprintf("userPrincipalName eq '%s'", utils.EscapeSingleQuote(upn)), } users, _, err := client.List(ctx, query) if err != nil { diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index d0a4169880..fee72eff0e 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/hashicorp/terraform-provider-azuread/internal/validate" ) @@ -179,7 +180,7 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter expectedCount = len(upns) for _, v := range upns { query := odata.Query{ - Filter: fmt.Sprintf("userPrincipalName eq '%s'", v), + Filter: fmt.Sprintf("userPrincipalName eq '%s'", utils.EscapeSingleQuote(v.(string))), } result, _, err := client.List(ctx, query) if err != nil {