Skip to content

Commit

Permalink
Merge pull request #1947 from okta/OKTA-712619-cannot-create-custom-o…
Browse files Browse the repository at this point in the history
…tp-authenticator

fix issue of cannot create new custom_otp authenticator
  • Loading branch information
duytiennguyen-okta authored Mar 28, 2024
2 parents 3234c84 + 92e769a commit ab08b1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
18 changes: 13 additions & 5 deletions okta/data_source_okta_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,19 @@ func findAuthenticator(ctx context.Context, m interface{}, name, key string) (*s
return nil, err
}
for _, authenticator := range authenticators {
if authenticator.Name == name {
return authenticator, nil
}
if authenticator.Key == key {
return authenticator, nil
if key != "custom_otp" {
if authenticator.Name == name {
return authenticator, nil
}
if authenticator.Key == key {
return authenticator, nil
}
} else {
if authenticator.Name == name && authenticator.Key == key {
return authenticator, nil
} else {
return nil, fmt.Errorf("authenticator with name '%s' and/or key '%s' does not exist", name, key)
}
}
}
if key != "" {
Expand Down
2 changes: 1 addition & 1 deletion okta/resource_okta_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func resourceAuthenticatorCreate(ctx context.Context, d *schema.ResourceData, m

var err error
// soft create if the authenticator already exists
authenticator, _ := findAuthenticator(ctx, m, "", d.Get("key").(string))
authenticator, _ := findAuthenticator(ctx, m, d.Get("name").(string), d.Get("key").(string))
if authenticator == nil {
// otherwise hard create
authenticator, err = buildAuthenticator(d)
Expand Down
3 changes: 1 addition & 2 deletions okta/resource_okta_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func TestAccResourceOktaAuthenticatorOTP(t *testing.T) {
"algorithm" : "HMacSHA256",
"passCodeLength" : 6
})
}
`
}`
resourceName := fmt.Sprintf("%s.otp", authenticator)

oktaResourceTest(t, resource.TestCase{
Expand Down

0 comments on commit ab08b1a

Please sign in to comment.