Skip to content

Commit

Permalink
Fixed name matching for okta_auth_server data source (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanprodan-okta committed Nov 2, 2021
1 parent 8912f2b commit 769fe58
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions okta/data_source_okta_auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/okta/okta-sdk-golang/v2/okta"
"github.com/okta/okta-sdk-golang/v2/okta/query"
)

Expand Down Expand Up @@ -59,14 +60,19 @@ func dataSourceAuthServer() *schema.Resource {

func dataSourceAuthServerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
name := d.Get("name").(string)
servers, _, err := getOktaClientFromMetadata(m).AuthorizationServer.ListAuthorizationServers(ctx, &query.Params{Q: name, Limit: 1})
servers, _, err := getOktaClientFromMetadata(m).AuthorizationServer.ListAuthorizationServers(ctx, &query.Params{Q: name, Limit: defaultPaginationLimit})
if err != nil {
return diag.Errorf("failed to find auth server '%s': %v", name, err)
}
if len(servers) < 1 || servers[0].Name != name {
var authServer *okta.AuthorizationServer
for i := range servers {
if servers[i].Name == name {
authServer = servers[i]
}
}
if authServer == nil {
return diag.Errorf("authorization server with name '%s' does not exist", name)
}
authServer := servers[0]
d.SetId(authServer.Id)
_ = d.Set("name", authServer.Name)
_ = d.Set("description", authServer.Description)
Expand Down

0 comments on commit 769fe58

Please sign in to comment.