-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
657 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This example is part of the test harness. The okta_theme resource state has | ||
# already been imported via import.tf | ||
|
||
data "okta_brands" "test" { | ||
} | ||
|
||
resource "okta_theme" "example" { | ||
brand_id = tolist(data.okta_brands.test.brands)[0].id | ||
|
||
logo = "../examples/okta_theme/okta_logo.png" | ||
favicon = "../examples/okta_theme/okta_favicon.png" | ||
background_image = "../examples/okta_theme/okta_background_image.png" | ||
primary_color_hex = "#1662dd" | ||
primary_color_contrast_hex = "#ffffff" | ||
secondary_color_hex = "#ebebed" | ||
secondary_color_contrast_hex = "#000000" | ||
sign_in_page_touch_point_variant = "OKTA_DEFAULT" | ||
end_user_dashboard_touch_point_variant = "OKTA_DEFAULT" | ||
error_page_touch_point_variant = "OKTA_DEFAULT" | ||
email_template_touch_point_variant = "OKTA_DEFAULT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This example is part of the test harness. The okta_theme resource state has | ||
# already been imported via import.tf | ||
|
||
data "okta_brands" "test" { | ||
} | ||
|
||
resource "okta_theme" "example" { | ||
brand_id = tolist(data.okta_brands.test.brands)[0].id | ||
|
||
logo = "" | ||
favicon = "" | ||
background_image = "" | ||
|
||
primary_color_hex = "#1662ff" | ||
primary_color_contrast_hex = "#ffffff" | ||
secondary_color_hex = "#fbfbfd" | ||
secondary_color_contrast_hex = "#000000" | ||
sign_in_page_touch_point_variant = "OKTA_DEFAULT" | ||
end_user_dashboard_touch_point_variant = "OKTA_DEFAULT" | ||
error_page_touch_point_variant = "OKTA_DEFAULT" | ||
email_template_touch_point_variant = "OKTA_DEFAULT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
data "okta_brands" "test" { | ||
} | ||
|
||
data "okta_themes" "test" { | ||
brand_id = tolist(data.okta_brands.test.brands)[0].id | ||
} | ||
|
||
resource "okta_theme" "example" { | ||
brand_id = tolist(data.okta_brands.test.brands)[0].id | ||
theme_id = tolist(data.okta_themes.test.themes)[0].id | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This example is part of the test harness. The okta_theme resource state has | ||
# already been imported via import.tf | ||
|
||
data "okta_brands" "test" { | ||
} | ||
|
||
resource "okta_theme" "example" { | ||
brand_id = tolist(data.okta_brands.test.brands)[0].id | ||
|
||
primary_color_hex = "#1662ff" | ||
primary_color_contrast_hex = "#ffffff" | ||
secondary_color_hex = "#fbfbfd" | ||
secondary_color_contrast_hex = "#000000" | ||
sign_in_page_touch_point_variant = "OKTA_DEFAULT" | ||
end_user_dashboard_touch_point_variant = "OKTA_DEFAULT" | ||
error_page_touch_point_variant = "OKTA_DEFAULT" | ||
email_template_touch_point_variant = "OKTA_DEFAULT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
package okta | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/okta/okta-sdk-golang/v2/okta" | ||
) | ||
|
||
func resourceTheme() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceThemeCreate, | ||
ReadContext: resourceThemeRead, | ||
UpdateContext: resourceThemeUpdate, | ||
DeleteContext: resourceThemeDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: resourceThemeImportStateContext, | ||
}, | ||
Schema: themeResourceSchema, | ||
} | ||
} | ||
|
||
func resourceThemeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
bid, ok := d.GetOk("brand_id") | ||
if !ok { | ||
return diag.Errorf("brand_id required to create theme") | ||
} | ||
brandID := bid.(string) | ||
|
||
var themeID string | ||
if d.Id() != "" { | ||
themeID = d.Id() | ||
} | ||
if themeID == "" { | ||
if tid, ok := d.GetOk("theme_id"); ok { | ||
themeID = tid.(string) | ||
} | ||
} | ||
if themeID == "" { | ||
return diag.Errorf("brand_id required to create theme") | ||
} | ||
|
||
theme, _, err := getOktaClientFromMetadata(m).Brand.GetBrandTheme(ctx, brandID, themeID) | ||
if err != nil { | ||
return diag.Errorf("failed to get theme: %v", err) | ||
} | ||
|
||
d.SetId(theme.Id) | ||
rawMap := flattenTheme(brandID, theme) | ||
err = setNonPrimitives(d, rawMap) | ||
if err != nil { | ||
return diag.Errorf("failed to set theme properties: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceThemeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
logger(m).Info("reading theme", "id", d.Id()) | ||
|
||
bid, ok := d.GetOk("brand_id") | ||
if !ok { | ||
return diag.Errorf("brand_id required to import theme") | ||
} | ||
brandID := bid.(string) | ||
|
||
theme, _, err := getOktaClientFromMetadata(m).Brand.GetBrandTheme(ctx, brandID, d.Id()) | ||
if err != nil { | ||
return diag.Errorf("failed to get theme: %v", err) | ||
} | ||
|
||
rawMap := flattenTheme(brandID, theme) | ||
err = setNonPrimitives(d, rawMap) | ||
if err != nil { | ||
return diag.Errorf("failed to set theme properties: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceThemeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
logger(m).Info("updating theme", "id", d.Id()) | ||
|
||
bid, ok := d.GetOk("brand_id") | ||
if !ok { | ||
return diag.Errorf("brand_id required to update theme") | ||
} | ||
brandID := bid.(string) | ||
|
||
// peform delete/upload on the logo/favicon/background_image first so any | ||
// errors there will interrupt apply on the theme itself | ||
if d.HasChange("logo") { | ||
err := handleThemeLogo(ctx, d, m, brandID, d.Id()) | ||
if err != nil { | ||
return diag.Errorf("failed to handle logo for theme: %v", err) | ||
} | ||
} | ||
if d.HasChange("favicon") { | ||
err := handleThemeFavicon(ctx, d, m, brandID, d.Id()) | ||
if err != nil { | ||
return diag.Errorf("failed to handle favicon for theme: %v", err) | ||
} | ||
} | ||
if d.HasChange("background_image") { | ||
err := handleThemeBackgroundImage(ctx, d, m, brandID, d.Id()) | ||
if err != nil { | ||
return diag.Errorf("failed to handle background_image for theme: %v", err) | ||
} | ||
} | ||
|
||
theme := okta.Theme{} | ||
|
||
if val, ok := d.GetOk("primary_color_hex"); ok { | ||
theme.PrimaryColorHex = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("primary_color_contrast_hex"); ok { | ||
theme.PrimaryColorContrastHex = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("secondary_color_hex"); ok { | ||
theme.SecondaryColorHex = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("secondary_color_contrast_hex"); ok { | ||
theme.SecondaryColorContrastHex = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("sign_in_page_touch_point_variant"); ok { | ||
theme.SignInPageTouchPointVariant = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("end_user_dashboard_touch_point_variant"); ok { | ||
theme.EndUserDashboardTouchPointVariant = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("error_page_touch_point_variant"); ok { | ||
theme.ErrorPageTouchPointVariant = val.(string) | ||
} | ||
|
||
if val, ok := d.GetOk("email_template_touch_point_variant"); ok { | ||
theme.EmailTemplateTouchPointVariant = val.(string) | ||
} | ||
|
||
themeResp, _, err := getOktaClientFromMetadata(m).Brand.UpdateBrandTheme(ctx, brandID, d.Id(), theme) | ||
if err != nil { | ||
return diag.Errorf("failed to update theme: %v", err) | ||
} | ||
|
||
rawMap := flattenTheme(brandID, themeResp) | ||
err = setNonPrimitives(d, rawMap) | ||
if err != nil { | ||
return diag.Errorf("failed to set theme properties: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceThemeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
// fake delete | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
func resourceThemeImportStateContext(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { | ||
parts := strings.Split(d.Id(), "/") | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("invalid resource import specifier, expecting the following format: <brand_id>/<theme_id>") | ||
} | ||
brandID := parts[0] | ||
themeID := parts[1] | ||
|
||
theme, _, err := getOktaClientFromMetadata(m).Brand.GetBrandTheme(ctx, brandID, themeID) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get theme: %v", err) | ||
} | ||
|
||
d.SetId(theme.Id) | ||
rawMap := flattenTheme(brandID, theme) | ||
err = setNonPrimitives(d, rawMap) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to set theme properties: %v", err) | ||
} | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func handleThemeLogo(ctx context.Context, d *schema.ResourceData, m interface{}, brandID, themeID string) error { | ||
_, newPath := d.GetChange("logo") | ||
if newPath == "" { | ||
_, err := getOktaClientFromMetadata(m).Brand.DeleteBrandThemeLogo(ctx, brandID, themeID) | ||
return err | ||
} | ||
_, _, err := getOktaClientFromMetadata(m).Brand.UploadBrandThemeLogo(ctx, brandID, themeID, newPath.(string)) | ||
return err | ||
} | ||
|
||
func handleThemeFavicon(ctx context.Context, d *schema.ResourceData, m interface{}, brandID, themeID string) error { | ||
_, newPath := d.GetChange("favicon") | ||
if newPath == "" { | ||
_, err := getOktaClientFromMetadata(m).Brand.DeleteBrandThemeFavicon(ctx, brandID, themeID) | ||
return err | ||
} | ||
_, _, err := getOktaClientFromMetadata(m).Brand.UploadBrandThemeFavicon(ctx, brandID, themeID, newPath.(string)) | ||
return err | ||
} | ||
|
||
func handleThemeBackgroundImage(ctx context.Context, d *schema.ResourceData, m interface{}, brandID, themeID string) error { | ||
_, newPath := d.GetChange("background_image") | ||
if newPath == "" { | ||
_, err := getOktaClientFromMetadata(m).Brand.DeleteBrandThemeBackgroundImage(ctx, brandID, themeID) | ||
return err | ||
} | ||
_, _, err := getOktaClientFromMetadata(m).Brand.UploadBrandThemeBackgroundImage(ctx, brandID, themeID, newPath.(string)) | ||
return err | ||
} |
Oops, something went wrong.