Skip to content

Commit

Permalink
fix issue of cannot create new custom_otp authenticator
Browse files Browse the repository at this point in the history
Signed-off-by: Tien Nguyen <duytien.nguyen@okta.com>
  • Loading branch information
duytiennguyen-okta committed Mar 28, 2024
1 parent 4d661f0 commit 92e769a
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 @@ -154,7 +154,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 92e769a

Please sign in to comment.