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_custom_otp authenticator suppress name #1982

Merged
merged 1 commit into from
Apr 23, 2024
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
16 changes: 16 additions & 0 deletions examples/resources/okta_authenticator/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@ resource "okta_authenticator" "test" {
}
)
}

resource "okta_authenticator" "otp" {
name = "Custom OTP"
key = "custom_otp"
status = "ACTIVE"
settings = jsonencode({
"protocol" : "TOTP",
"acceptableAdjacentIntervals" : 3,
"timeIntervalInSeconds" : 30,
"encoding" : "base32",
"algorithm" : "HMacSHA256",
"passCodeLength" : 6
})
// required to be false for custom_otp
legacy_ignore_name = false
}
28 changes: 20 additions & 8 deletions okta/resource_okta_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ multiple custom_otp authenticator. To create new custom_otp authenticator, a new
name and key = custom_otp is required. If an old name is used, it will simply
reactivate the old custom_otp authenticator

-> **Update:** custom_otp authenticator cannot be updated

-> **Delete:** Authenticators can not be truly deleted therefore delete is soft.
Delete will attempt to deativate the authenticator. An authenticator can only be
deactivated if it's not in use by any other policy.`,
Expand All @@ -49,7 +51,7 @@ deactivated if it's not in use by any other policy.`,
Required: true,
Description: "Display name of the Authenticator",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return true
return d.Get("legacy_ignore_name").(bool)
},
},
"settings": {
Expand Down Expand Up @@ -157,6 +159,12 @@ deactivated if it's not in use by any other policy.`,
Computed: true,
Description: "Provider type. Supported value for Duo: `DUO`. Supported value for Custom App: `PUSH`",
},
"legacy_ignore_name": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Name does not trigger change detection (legacy behavior)",
},
},
}
}
Expand Down Expand Up @@ -358,13 +366,17 @@ func buildOTP(d *schema.ResourceData) (*sdk.OTP, error) {
func validateAuthenticator(d *schema.ResourceData) error {
typ := d.Get("type").(string)
if typ == "security_key" {
h := d.Get("provider_hostname").(string)
_, pok := d.GetOk("provider_auth_port")
s := d.Get("provider_shared_secret").(string)
templ := d.Get("provider_user_name_template").(string)
if h == "" || s == "" || templ == "" || !pok {
return fmt.Errorf("for authenticator type '%s' fields 'provider_hostname', "+
"'provider_auth_port', 'provider_shared_secret' and 'provider_user_name_template' are required", typ)
if d.Get("key").(string) != "custom_otp" {
h := d.Get("provider_hostname").(string)
_, pok := d.GetOk("provider_auth_port")
s := d.Get("provider_shared_secret").(string)
templ := d.Get("provider_user_name_template").(string)
if h == "" || s == "" || templ == "" || !pok {
return fmt.Errorf("for authenticator type '%s' fields 'provider_hostname', "+
"'provider_auth_port', 'provider_shared_secret' and 'provider_user_name_template' are required", typ)
}
} else {
return fmt.Errorf("custom_otp is not updatable")
}
}

Expand Down
1 change: 1 addition & 0 deletions okta/resource_okta_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAccResourceOktaAuthenticatorOTP(t *testing.T) {
"algorithm" : "HMacSHA256",
"passCodeLength" : 6
})
legacy_ignore_name = false
}`
resourceName := fmt.Sprintf("%s.otp", authenticator)

Expand Down