Skip to content

Commit

Permalink
Merge pull request #1831 from okta/1824_okta_brand_email_domain_id
Browse files Browse the repository at this point in the history
resource `okta_brand`'s `email_domain_id` is an attribute, not an argument
  • Loading branch information
monde authored Nov 28, 2023
2 parents b10b003 + 30669ee commit 90fe8a0
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 30 deletions.
3 changes: 1 addition & 2 deletions okta/resource_okta_brand.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *brandResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
},
"email_domain_id": schema.StringAttribute{
Description: "Email Domain ID tied to this brand",
Optional: true,
Computed: true,
},
"locale": schema.StringAttribute{
Description: "The language specified as an IETF BCP 47 language tag",
Expand Down Expand Up @@ -334,7 +334,6 @@ func buildUpdateBrandRequest(model brandResourceModel) (okta.BrandRequest, error
AgreeToCustomPrivacyPolicy: model.AgreeToCustomPrivacyPolicy.ValueBoolPointer(),
CustomPrivacyPolicyUrl: model.CustomPrivacyPolicyURL.ValueStringPointer(),
DefaultApp: defaultApp,
EmailDomainId: model.EmailDomainID.ValueStringPointer(),
Locale: model.Locale.ValueStringPointer(),
RemovePoweredByOkta: model.RemovePoweredByOkta.ValueBoolPointer(),
}, nil
Expand Down
131 changes: 105 additions & 26 deletions okta/resource_okta_brand_test.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,128 @@
package okta

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccResourceOktaBrandCRUD(t *testing.T) {
mgr := newFixtureManager("resources", brand, t.Name())
resourceName := fmt.Sprintf("%s.test", brand)
step1 := `
resource okta_brand test{
name = "testAcc-replace_with_uuid"
locale = "en"
}`
step2 := `
resource okta_brand test{
name = "testAcc-changed-replace_with_uuid"
agree_to_custom_privacy_policy = true
custom_privacy_policy_url = "https://example.com"
locale = "es"
remove_powered_by_okta = true
}`
oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProtoV5ProviderFactories: testAccMergeProvidersFactories,
Steps: []resource.TestStep{
{
Config: `resource okta_brand test{
name = "test"
locale = "en"
}`,
Config: mgr.ConfigReplace(step1),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("okta_brand.test", "name", "test"),
resource.TestCheckResourceAttr("okta_brand.test", "agree_to_custom_privacy_policy", "false"),
resource.TestCheckNoResourceAttr("okta_brand.test", "custom_privacy_policy_url"),
resource.TestCheckNoResourceAttr("okta_brand.test", "email_domain_id"),
resource.TestCheckResourceAttr("okta_brand.test", "is_default", "false"),
resource.TestCheckResourceAttr("okta_brand.test", "locale", "en"),
resource.TestCheckResourceAttr("okta_brand.test", "remove_powered_by_okta", "false"),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAcc-%d", mgr.Seed)),
resource.TestCheckResourceAttr(resourceName, "agree_to_custom_privacy_policy", "false"),
resource.TestCheckNoResourceAttr(resourceName, "custom_privacy_policy_url"),
resource.TestCheckNoResourceAttr(resourceName, "email_domain_id"),
resource.TestCheckResourceAttr(resourceName, "is_default", "false"),
resource.TestCheckResourceAttr(resourceName, "locale", "en"),
resource.TestCheckResourceAttr(resourceName, "remove_powered_by_okta", "false"),
),
},
{
Config: `
resource okta_brand test{
name = "test2"
agree_to_custom_privacy_policy = true
custom_privacy_policy_url = "https://example.com"
locale = "es"
remove_powered_by_okta = true
}`,
Config: mgr.ConfigReplace(step2),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("okta_brand.test", "name", "test2"),
resource.TestCheckResourceAttr("okta_brand.test", "agree_to_custom_privacy_policy", "true"),
resource.TestCheckResourceAttr("okta_brand.test", "custom_privacy_policy_url", "https://example.com"),
resource.TestCheckResourceAttr("okta_brand.test", "locale", "es"),
resource.TestCheckNoResourceAttr("okta_brand.test", "email_domain_id"),
resource.TestCheckResourceAttr("okta_brand.test", "remove_powered_by_okta", "true"),
resource.TestCheckNoResourceAttr("okta_brand.test", "default_app_app_instance_id"),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAcc-changed-%d", mgr.Seed)),
resource.TestCheckResourceAttr(resourceName, "agree_to_custom_privacy_policy", "true"),
resource.TestCheckResourceAttr(resourceName, "custom_privacy_policy_url", "https://example.com"),
resource.TestCheckResourceAttr(resourceName, "locale", "es"),
resource.TestCheckNoResourceAttr(resourceName, "email_domain_id"),
resource.TestCheckResourceAttr(resourceName, "remove_powered_by_okta", "true"),
resource.TestCheckNoResourceAttr(resourceName, "default_app_app_instance_id"),
),
},
},
})
}

// TestAccResourceOktaBrand_Issue_1824_with_email_domain addresses issue
// https://github.com/okta/terraform-provider-okta/issues/1824 . This test was
// broken, then the brand resource was fixed to make the test pass.
func TestAccResourceOktaBrand_Issue_1824_with_email_domain(t *testing.T) {
mgr := newFixtureManager("resources", brand, t.Name())
resourceName := fmt.Sprintf("%s.test", brand)
step1 := `
resource okta_brand test{
name = "testAcc-replace_with_uuid"
locale = "en"
}`
step2 := `
resource okta_brand test{
name = "testAcc-replace_with_uuid"
locale = "en"
}
resource "okta_email_domain" "test" {
brand_id = okta_brand.test.id
domain = "testAcc-replace_with_uuid.example.com"
display_name = "test"
user_name = "fff"
}`
oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProtoV5ProviderFactories: testAccMergeProvidersFactories,
Steps: []resource.TestStep{
{
// Step 1
// Create okta_brand.test
Config: mgr.ConfigReplace(step1),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckNoResourceAttr(resourceName, "email_domain_id"),
),
},
{
// Step 2
// Create okta_email_domain.test with a brand_id from okta_brand.test.id.
// okta_brand.test will have not have a computed email_domain_id value until it is refreshed.
Config: mgr.ConfigReplace(step2),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckNoResourceAttr(resourceName, "email_domain_id"),
),
},
{
RefreshState: true,
// Step 3
// Upon refresh, okta_brand.test will have computed email_domain_id value.
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "email_domain_id"),
),
},
{
// Step 4
// Even though okta_email_domain.test was destroyed, okta_brand.test will have an email_domain_id
// until the resource is refreshed.
Config: mgr.ConfigReplace(step1),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "email_domain_id"),
),
},
{
// Step 5
// okta_brand.test resource shouldn't have an email_domain_id after refresh
Config: mgr.ConfigReplace(step1),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckNoResourceAttr(resourceName, "email_domain_id"),
),
},
},
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/brand.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ resource "okta_brand" "example" {

- `name` - (Required) Name of the brand

- `email_domain_id` - (Optional) Email Domain ID tied to this brand

- `locale` - (Optional) The language specified as an IETF BCP 47 language tag


Expand All @@ -46,6 +44,8 @@ resource "okta_brand" "example" {

## Attributes Reference

- `email_domain_id` - (Read-only) Email Domain ID tied to this brand

- `id` - (Read-only) Brand ID

- `is_default` - (Read-only) Is this the default brand
Expand Down

0 comments on commit 90fe8a0

Please sign in to comment.