Skip to content

Commit

Permalink
Merge pull request #1001 from okta/update_okta_sdk_golang
Browse files Browse the repository at this point in the history
Update okta-sdk-golang to v2.12.1
  • Loading branch information
monde authored Apr 25, 2022
2 parents 9ca8c49 + 2906d07 commit cef7a30
Show file tree
Hide file tree
Showing 57 changed files with 366 additions and 859 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 3.25.0 (April 21, 2022)

ENHANCEMENTS:
* Upgrade okta-sdk-golang to v2.12.1. [#1001](https://github.com/okta/terraform-provider-okta/pull/1001). Thanks, [@monde](https://github.com/monde)!
* Removing/Updating local sdk code
* Application.UploadApplicationLogo
* Authenticator
* EnrollFactor
* LinkedObjects
* PasswordPolicy
* ProfileMapping
* Subscription
* UserFactor
* Fixed ACC tests
* TestAccOktaAppSignOnPolicyRule
* TestAccOktaDataSourceIdpSocial_read
* TestAccOktaDefaultPasswordPolicy
* TestAccOktaIdpSocial_crud
* TestAccOktaPolicyPassword_crud
* TestAccOktaPolicySignOn_crud
* TestAccAppOAuthApplication_postLogoutRedirectCrud
* Backoff/retry on application delete
* Update okta_app_saml resource documentation. [#1076](https://github.com/okta/terraform-provider-okta/pull/1076). Thanks, [@jphuynh](https://github.com/jphuynh)!

## 3.24.0 (April 15, 2022)

ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_app_oauth_post_logout_redirect_uri/basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resource "okta_app_oauth" "test" {

// Since Okta forces us to create it with a redirect URI we have to ignore future changes, they will be detected as config drift.
lifecycle {
ignore_changes = [redirect_uris]
ignore_changes = [post_logout_redirect_uris]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "okta_app_oauth" "test" {

// Since Okta forces us to create it with a redirect URI we have to ignore future changes, they will be detected as config drift.
lifecycle {
ignore_changes = [redirect_uris]
ignore_changes = [post_logout_redirect_uris]
}
}

Expand Down
20 changes: 12 additions & 8 deletions examples/okta_app_signon_policy_rule/basic_updated.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ resource "okta_app_signon_policy_rule" "test" {
os_type = "MACOS"
type = "DESKTOP"
}
platform_include {
os_type = "OTHER"
type = "DESKTOP"
}
platform_include {
os_type = "OTHER"
type = "MOBILE"
}
# FIXME Okta API for /api/v1/policies/{policyId}/rules/{ruleId}
# is not returning os_expression even when it has been set throwing off the TF state.
# platform_include {
# os_expression = ".*"
# os_type = "OTHER"
# type = "DESKTOP"
# }
# platform_include {
# os_expression = ".*"
# os_type = "OTHER"
# type = "MOBILE"
# }
platform_include {
os_type = "WINDOWS"
type = "DESKTOP"
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_idp_social/auto_provision_disabled.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"
provisioning_action = "DISABLED"

Expand Down
2 changes: 1 addition & 1 deletion examples/okta_idp_social/basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "okta_user_schema_property" "schema_custom" {

resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"

scopes = [
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_idp_social/datasource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "okta_idp_social" "facebook" {

resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"

scopes = [
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_profile_mapping/basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resource "okta_profile_mapping" "test" {

resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"

scopes = [
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_profile_mapping/prevent_delete.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "okta_profile_mapping" "test" {

resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"

scopes = [
Expand Down
2 changes: 1 addition & 1 deletion examples/okta_profile_mapping/updated.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "okta_profile_mapping" "test" {

resource "okta_idp_social" "google" {
type = "GOOGLE"
protocol_type = "OAUTH2"
protocol_type = "OIDC"
name = "testAcc_google_replace_with_uuid"

scopes = [
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module github.com/okta/terraform-provider-okta
go 1.17

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v4 v4.1.3
github.com/crewjam/saml v0.4.6
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-hclog v1.2.0
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0
github.com/okta/okta-sdk-golang/v2 v2.9.3-0.20211209083930-a123a8c6e20d
github.com/okta/okta-sdk-golang/v2 v2.12.1-0.20220418232441-a4b5722f6e4f
)

require (
Expand Down
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkE
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -163,7 +165,7 @@ github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 h1:xixZ2bWeofWV68J
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jarcoal/httpmock v1.0.7/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
Expand Down Expand Up @@ -220,8 +222,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/okta/okta-sdk-golang/v2 v2.9.3-0.20211209083930-a123a8c6e20d h1:eXkHa6fD88r12g1xQskQ7pDxBx4dW6jU8FMWlMuutCw=
github.com/okta/okta-sdk-golang/v2 v2.9.3-0.20211209083930-a123a8c6e20d/go.mod h1:UhdEFuTLCIJirz6x4zGjsuwQl1xhCLKizNyj/h14tFA=
github.com/okta/okta-sdk-golang/v2 v2.12.1-0.20220418232441-a4b5722f6e4f h1:sI7Kn1I17DoJbZEd6zQMmEZ2RR4Ek40siBvgS+CmFZQ=
github.com/okta/okta-sdk-golang/v2 v2.12.1-0.20220418232441-a4b5722f6e4f/go.mod h1:KRoAArk1H216oiRnQT77UN6JAhBOnOWkK27yA1SM7FQ=
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 h1:pSCLCl6joCFRnjpeojzOpEYs4q7Vditq8fySFG5ap3Y=
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down Expand Up @@ -407,6 +409,7 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
Expand Down
16 changes: 14 additions & 2 deletions okta/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"os"
"strings"
"sync"
"time"

"github.com/cenkalti/backoff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/okta/okta-sdk-golang/v2/okta"
"github.com/okta/okta-sdk-golang/v2/okta/query"
Expand Down Expand Up @@ -435,7 +437,7 @@ func handleAppLogo(ctx context.Context, d *schema.ResourceData, m interface{}, a
if !ok {
return nil
}
_, err := getSupplementFromMetadata(m).UploadAppLogo(ctx, appID, l.(string))
_, err := getOktaClientFromMetadata(m).Application.UploadApplicationLogo(ctx, appID, l.(string))
return err
}

Expand Down Expand Up @@ -683,7 +685,17 @@ func deleteApplication(ctx context.Context, d *schema.ResourceData, m interface{
return err
}
}
_, err := client.Application.DeleteApplication(ctx, d.Id())

// Okta Core can have eventual consistency issues when deactivating an app
// which is required before deleting the app.
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = 5 * time.Second

err := backoff.Retry(func() error {
_, err := client.Application.DeleteApplication(ctx, d.Id())
return err
}, b)

return err
}

Expand Down
2 changes: 1 addition & 1 deletion okta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Config) loadAndValidate(ctx context.Context) error {
okta.WithRateLimitMaxBackOff(int64(c.maxWait)),
okta.WithRequestTimeout(int64(c.requestTimeout)),
okta.WithRateLimitMaxRetries(int32(c.retryCount)),
okta.WithUserAgentExtra("okta-terraform/3.23.0"),
okta.WithUserAgentExtra("okta-terraform/3.25.0"),
}
if c.apiToken == "" {
setters = append(setters, okta.WithAuthorizationMode("PrivateKey"))
Expand Down
4 changes: 3 additions & 1 deletion okta/data_source_okta_app_signon_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ func dataSourceAppSignOnPolicyRead(ctx context.Context, d *schema.ResourceData,
if accessPolicy == "" {
return diag.Errorf("app does not support sign-on policy or this feature is not available")
}
policy, _, err := getOktaClientFromMetadata(m).Policy.GetPolicy(ctx, path.Base(accessPolicy), nil)
policy := &okta.Policy{}
_policy, _, err := getOktaClientFromMetadata(m).Policy.GetPolicy(ctx, path.Base(accessPolicy), policy, nil)
if err != nil {
return diag.Errorf("failed get policy by ID: %v", err)
}
policy = _policy.(*okta.Policy)
d.SetId(policy.Id)
_ = d.Set("name", policy.Name)
return nil
Expand Down
14 changes: 7 additions & 7 deletions okta/data_source_okta_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/okta/terraform-provider-okta/sdk"
"github.com/okta/okta-sdk-golang/v2/okta"
)

func dataSourceAuthenticator() *schema.Resource {
Expand Down Expand Up @@ -78,18 +78,18 @@ func dataSourceAuthenticatorRead(ctx context.Context, d *schema.ResourceData, m
return diag.Errorf("config must provide either 'id', 'name' or 'key' to retrieve the authenticator")
}
var (
authenticator *sdk.Authenticator
authenticator *okta.Authenticator
err error
)
if id != "" {
authenticator, _, err = getSupplementFromMetadata(m).GetAuthenticator(ctx, id)
authenticator, _, err = getOktaClientFromMetadata(m).Authenticator.GetAuthenticator(ctx, id)
} else {
authenticator, err = findAuthenticator(ctx, m, name, key)
}
if err != nil {
return diag.FromErr(err)
}
d.SetId(authenticator.ID)
d.SetId(authenticator.Id)
_ = d.Set("key", authenticator.Key)
_ = d.Set("name", authenticator.Name)
_ = d.Set("status", authenticator.Status)
Expand All @@ -102,16 +102,16 @@ func dataSourceAuthenticatorRead(ctx context.Context, d *schema.ResourceData, m
_ = d.Set("provider_type", authenticator.Provider.Type)
_ = d.Set("provider_hostname", authenticator.Provider.Configuration.HostName)
_ = d.Set("provider_auth_port", authenticator.Provider.Configuration.AuthPort)
_ = d.Set("provider_instance_id", authenticator.Provider.Configuration.InstanceID)
_ = d.Set("provider_instance_id", authenticator.Provider.Configuration.InstanceId)
if authenticator.Provider.Configuration.UserNameTemplate != nil {
_ = d.Set("provider_user_name_template", authenticator.Provider.Configuration.UserNameTemplate.Template)
}
}
return nil
}

func findAuthenticator(ctx context.Context, m interface{}, name, key string) (*sdk.Authenticator, error) {
authenticators, _, err := getSupplementFromMetadata(m).ListAuthenticators(ctx)
func findAuthenticator(ctx context.Context, m interface{}, name, key string) (*okta.Authenticator, error) {
authenticators, _, err := getOktaClientFromMetadata(m).Authenticator.ListAuthenticators(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion okta/data_source_okta_role_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dataSourceRoleSubscription() *schema.Resource {
}

func dataSourceRoleSubscriptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
subscription, _, err := getSupplementFromMetadata(m).GetRoleTypeSubscription(ctx, d.Get("role_type").(string), d.Get("notification_type").(string))
subscription, _, err := getOktaClientFromMetadata(m).Subscription.GetRoleSubscriptionByNotificationType(ctx, d.Get("role_type").(string), d.Get("notification_type").(string))
if err != nil {
return diag.Errorf("failed get subscription: %v", err)
}
Expand Down
36 changes: 31 additions & 5 deletions okta/data_source_okta_user_profile_mapping_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,38 @@ func dataSourceUserProfileMappingSource() *schema.Resource {
}

func dataSourceUserProfileMappingSourceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
mapping, err := getSupplementFromMetadata(m).FindProfileMappingSource(ctx, "user", "user", &query.Params{Limit: defaultPaginationLimit})
mappings, resp, err := getOktaClientFromMetadata(m).ProfileMapping.ListProfileMappings(ctx, &query.Params{Limit: defaultPaginationLimit})
if err != nil {
return diag.Errorf("failed to find profile mapping source: %v", err)
return diag.Errorf("failed to list mappings: %v", err)
}
d.SetId(mapping.ID)
_ = d.Set("type", mapping.Type)
_ = d.Set("name", mapping.Name)
name := "user"
typ := "user"
for {
for _, mapping := range mappings {
target := mapping.Target
source := mapping.Source
if target.Name == name && target.Type == typ {
d.SetId(target.Id)
_ = d.Set("type", target.Type)
_ = d.Set("name", target.Name)
return nil
} else if source.Name == name && source.Type == typ {
d.SetId(source.Id)
_ = d.Set("type", source.Type)
_ = d.Set("name", source.Name)
return nil
}
}
if resp.HasNextPage() {
resp, err = resp.Next(ctx, &mappings)
if err != nil {
return diag.Errorf("failed to find profile mapping source: %v", err)
}
continue
} else {
break
}
}

return nil
}
3 changes: 2 additions & 1 deletion okta/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func findPolicy(ctx context.Context, m interface{}, name, policyType string) (*o
return nil, fmt.Errorf("failed to list policies: %v", err)
}
for {
for _, policy := range policies {
for _, _policy := range policies {
policy := _policy.(*okta.Policy)
if policy.Name == name {
return policy, nil
}
Expand Down
2 changes: 1 addition & 1 deletion okta/resource_okta_admin_role_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func removeAllTargets(ctx context.Context, d *schema.ResourceData, m interface{}
}
ctx = context.WithValue(ctx, retryOnStatusCodes, []int{http.StatusConflict, http.StatusBadRequest})
role, _, err := getOktaClientFromMetadata(m).User.AssignRoleToUser(ctx, d.Get("user_id").(string),
&okta.AssignRoleRequest{Type: d.Get("role_type").(string)}, nil)
okta.AssignRoleRequest{Type: d.Get("role_type").(string)}, nil)
if err != nil {
d.SetId("")
return "", fmt.Errorf("failed to assign '%s' role back to user: %v", d.Get("role_type").(string), err)
Expand Down
3 changes: 1 addition & 2 deletions okta/resource_okta_app_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ func buildAppGroupAssignment(d *schema.ResourceData) okta.ApplicationGroupAssign
}
p, ok := d.GetOk("priority")
if ok {
priority := int64(p.(int))
assignment.Priority = &priority
assignment.Priority = int64(p.(int))
}
return assignment
}
Loading

0 comments on commit cef7a30

Please sign in to comment.