Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/unlock-user
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumew committed Jul 29, 2019
2 parents b680d6f + b8f9ea0 commit 5d2b2a1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ For Release v3.0.9
For Release v3.0.10

* Add okta_network_zone resource

For Release v3.0.11

* Fix ocassional panic when creating a user schema see https://github.com/articulate/terraform-provider-okta/issues/144
2 changes: 1 addition & 1 deletion examples/okta_user/all_attributes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "okta_user" "testAcc_replace_with_uuid" {
first_name = "TestAcc"
last_name = "Smith"
login = "[email protected]"
email = "test1[email protected]"
email = "test-acc[email protected]"
city = "New York"
cost_center = "10"
country_code = "US"
Expand Down
48 changes: 31 additions & 17 deletions okta/resource_user_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package okta

import (
"fmt"
"time"

articulateOkta "github.com/articulate/oktasdk-go/okta"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -122,26 +123,28 @@ func resourceUserSchemaCreate(d *schema.ResourceData, m interface{}) error {
}

func resourceUserSchemaExists(d *schema.ResourceData, m interface{}) (bool, error) {
client := getClientFromMetadata(m)
schema, _, err := client.Schemas.GetUserSchema()
if err != nil {
return false, err
}

subschema := getSubSchema(schema.Definitions.Custom.Properties, d.Id())
subschema, err := getSubSchema(d, m)

return subschema != nil, nil
return subschema != nil, err
}

func resourceUserSchemaRead(d *schema.ResourceData, m interface{}) error {
client := getClientFromMetadata(m)
schema, _, err := client.Schemas.GetUserSchema()
subschema, err := getSubSchema(d, m)
if err != nil {
return err
} else if subschema == nil {
// See https://github.com/articulate/terraform-provider-okta/issues/144
// Occassionally a schema prop would be created and the read would not find it.
// There appears to be a delay of availability on the Okta side, thus the backoff.
fmt.Println("Could not find an existence subschema property, backing off and retrying. Known timing issue")
time.Sleep(time.Second * 3)

subschema, err = getSubSchema(d, m)
if err != nil {
return err
}
}

subschema := getSubSchema(schema.Definitions.Custom.Properties, d.Id())

d.Set("array_type", subschema.Items.Type)
d.Set("title", subschema.Title)
d.Set("type", subschema.Type)
Expand Down Expand Up @@ -171,13 +174,24 @@ func resourceUserSchemaRead(d *schema.ResourceData, m interface{}) error {
})
}

func getSubSchema(props []articulateOkta.CustomSubSchema, id string) *articulateOkta.CustomSubSchema {
for _, schema := range props {
if schema.Index == id {
return &schema
func getSubSchema(d *schema.ResourceData, m interface{}) (subschema *articulateOkta.CustomSubSchema, err error) {
var schema *articulateOkta.Schema
id := d.Id()

client := getClientFromMetadata(m)
schema, _, err = client.Schemas.GetUserSchema()
if err != nil {
return
}

for _, part := range schema.Definitions.Custom.Properties {
if part.Index == id {
subschema = &part
return
}
}
return nil

return
}

func resourceUserSchemaUpdate(d *schema.ResourceData, m interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion okta/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestAccOktaUser_updateAllAttributes(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "first_name", "TestAcc"),
resource.TestCheckResourceAttr(resourceName, "last_name", "Smith"),
resource.TestCheckResourceAttr(resourceName, "login", email),
resource.TestCheckResourceAttr(resourceName, "email", fmt.Sprintf("test1-%[email protected]", ri)),
resource.TestCheckResourceAttr(resourceName, "email", email),
resource.TestCheckResourceAttr(resourceName, "admin_roles.#", "1"),
resource.TestCheckResourceAttr(resourceName, "city", "New York"),
resource.TestCheckResourceAttr(resourceName, "cost_center", "10"),
Expand Down

0 comments on commit 5d2b2a1

Please sign in to comment.