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

Missing attributes in okta_idp_saml resource not getting set in read context #1796

Merged
merged 1 commit into from
Nov 1, 2023
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
1 change: 0 additions & 1 deletion okta/resource_okta_app_oauth_redirect_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func resourceAppOAuthRedirectURIRead(kind string) func(ctx context.Context, d *s
aid, ok := d.GetOk("app_id")
if !ok || aid.(string) == "" {
return diag.Errorf("app_id not set on resource")

}
appID := aid.(string)

Expand Down
8 changes: 8 additions & 0 deletions okta/resource_okta_idp_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func resourceIdpSamlRead(ctx context.Context, d *schema.ResourceData, m interfac
_ = d.Set("name", idp.Name)
_ = d.Set("acs_binding", idp.Protocol.Endpoints.Acs.Binding)
_ = d.Set("acs_type", idp.Protocol.Endpoints.Acs.Type)
if idp.Protocol.Endpoints.Sso != nil {
_ = d.Set("sso_binding", idp.Protocol.Endpoints.Sso.Binding)
_ = d.Set("sso_destination", idp.Protocol.Endpoints.Sso.Destination)
_ = d.Set("sso_url", idp.Protocol.Endpoints.Sso.Url)
}
if idp.Policy.MaxClockSkewPtr != nil {
_ = d.Set("max_clock_skew", *idp.Policy.MaxClockSkewPtr)
}
Expand All @@ -139,6 +144,9 @@ func resourceIdpSamlRead(ctx context.Context, d *schema.ResourceData, m interfac
if idp.IssuerMode != "" {
_ = d.Set("issuer_mode", idp.IssuerMode)
}
if idp.Status != "" {
_ = d.Set("status", idp.Status)
}
mapping, resp, err := getProfileMappingBySourceID(ctx, idp.Id, "", m)
if err := suppressErrorOn401("resource okta_idp_saml.user_type_id", m, resp, err); err != nil {
return diag.Errorf("failed to get SAML identity provider profile mapping: %v", err)
Expand Down
57 changes: 53 additions & 4 deletions okta/resource_okta_idp_saml_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package okta

import (
"errors"
"fmt"
"strings"
"testing"

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

func TestAccResourceOktaIdpSaml_crud(t *testing.T) {
Expand All @@ -14,10 +17,10 @@ func TestAccResourceOktaIdpSaml_crud(t *testing.T) {
resourceName := fmt.Sprintf("%s.test", idpSaml)

oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProviderFactories: testAccProvidersFactories,
CheckDestroy: checkResourceDestroy(idpSaml, createDoesIdpExist),
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProtoV5ProviderFactories: testAccMergeProvidersFactories,
CheckDestroy: checkResourceDestroy(idpSaml, createDoesIdpExist),
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -56,6 +59,52 @@ func TestAccResourceOktaIdpSaml_crud(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "kid"),
),
},
{
// Before fixing
// https://github.com/okta/terraform-provider-okta/issues/1558
// Not all settable arguments that were from API values were
// being set on the read like sso_url.
ResourceName: resourceName,
ImportState: true,
ImportStateCheck: func(s []*terraform.InstanceState) error {
if len(s) != 1 {
return errors.New("failed to import resource into state")
}
expectedAttrs := []string{
"acs_binding",
"acs_type",
"audience",
"deprovisioned_action",
"issuer",
// "issuer_mode", not set during test
"kid",
"max_clock_skew",
"name",
"profile_master",
"provisioning_action",
"sso_binding",
"sso_destination",
"sso_url",
"status",
// "subject_filter", not set during test
// "subject_match_attribute", not set durting test
"subject_match_type",
"suspended_action",
"user_type_id",
"username_template",
}
notFound := []string{}
for _, attr := range expectedAttrs {
if s[0].Attributes[attr] == "" {
notFound = append(notFound, attr)
}
}
if len(notFound) > 0 {
return fmt.Errorf("expected attributes %s to be set during import read", strings.Join(notFound, ", "))
}
return nil
},
},
},
})
}
Expand Down
Loading