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

Add 'app_settings_json' to the 'okta_app_auto_login' resource #602

Merged
merged 1 commit into from
Aug 20, 2021
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
33 changes: 29 additions & 4 deletions okta/resource_okta_app_auto_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package okta

import (
"context"
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -66,6 +67,16 @@ func resourceAppAutoLogin() *schema.Resource {
Optional: true,
Description: "Shared password, required for certain schemes.",
},
"app_settings_json": {
Type: schema.TypeString,
Optional: true,
Description: "Application settings in JSON format",
ValidateDiagFunc: stringIsJSON,
StateFunc: normalizeDataJSON,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return new == ""
},
},
}),
}
}
Expand Down Expand Up @@ -100,9 +111,15 @@ func resourceAppAutoLoginRead(ctx context.Context, d *schema.ResourceData, m int
d.SetId("")
return nil
}
if app.Settings.SignOn != nil {
_ = d.Set("sign_on_url", app.Settings.SignOn.LoginUrl)
_ = d.Set("sign_on_redirect_url", app.Settings.SignOn.RedirectUrl)
if app.Settings != nil {
if app.Settings.SignOn != nil {
_ = d.Set("sign_on_url", app.Settings.SignOn.LoginUrl)
_ = d.Set("sign_on_redirect_url", app.Settings.SignOn.RedirectUrl)
}
err = setAppSettings(d, app.Settings.App)
if err != nil {
return diag.Errorf("failed to set auto login application settings: %v", err)
}
}
_ = d.Set("credentials_scheme", app.Credentials.Scheme)
_ = d.Set("reveal_password", app.Credentials.RevealPassword)
Expand Down Expand Up @@ -162,14 +179,22 @@ func buildAppAutoLogin(d *schema.ResourceData) *okta.AutoLoginApplication {
if name != "" {
app.Name = name
}

app.Settings = &okta.AutoLoginApplicationSettings{
SignOn: &okta.AutoLoginApplicationSettingsSignOn{
LoginUrl: d.Get("sign_on_url").(string),
RedirectUrl: d.Get("sign_on_redirect_url").(string),
},
Notes: buildAppNotes(d),
}
if appSettings, ok := d.GetOk("app_settings_json"); ok {
payload := map[string]interface{}{}
_ = json.Unmarshal([]byte(appSettings.(string)), &payload)
settings := okta.ApplicationSettingsApplication(payload)
app.Settings.App = &settings
} else {
settings := okta.ApplicationSettingsApplication(map[string]interface{}{})
app.Settings.App = &settings
}
app.Visibility = buildAppVisibility(d)
app.Credentials = buildSchemeAppCreds(d)

Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/app_auto_login.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ resource "okta_app_auto_login" "example" {
}
```

#### Pre-configured application
```hcl
resource "okta_app_auto_login" "example" {
label = "Google Example App"
status = "ACTIVE"
preconfigured_app = "google"
app_settings_json = <<JSON
{
"domain": "okta",
"afwOnly": false
}
JSON
}
```

## Argument Reference

The following arguments are supported:
Expand Down Expand Up @@ -72,6 +87,8 @@ The following arguments are supported:

- `enduser_note` - (Optional) Application notes for end users.

- `app_settings_json` - (Optional) Application settings in JSON format.

## Attributes Reference

- `name` - Name assigned to the application by Okta.
Expand Down