Skip to content
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

fix issue of cannot create new custom_otp authenticator #1947

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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