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

Update resource okta_auth_server_scope #1112

Merged
merged 1 commit into from
May 17, 2022
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
13 changes: 13 additions & 0 deletions examples/okta_auth_server_scope/import.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "okta_auth_server_scope" "test" {
consent = "REQUIRED"
description = "test"
name = "test:something"
display_name = "test"
auth_server_id = okta_auth_server.test.id
}

resource "okta_auth_server" "test" {
name = "testAcc_replace_with_uuid"
description = "test"
audiences = ["whatever.rise.zone"]
}
6 changes: 6 additions & 0 deletions okta/resource_okta_auth_server_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func resourceAuthServerScope() *schema.Resource {
Default: false,
Description: "A default scope will be returned in an access token when the client omits the scope parameter in a token request, provided this scope is allowed as part of the access policy rule.",
},
"system": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether Okta created the Scope",
},
},
}
}
Expand Down Expand Up @@ -82,6 +87,7 @@ func resourceAuthServerScopeRead(ctx context.Context, d *schema.ResourceData, m
_ = d.Set("display_name", scope.DisplayName)
_ = d.Set("metadata_publish", scope.MetadataPublish)
_ = d.Set("default", scope.Default)
_ = d.Set("system", scope.System)
if scope.Consent != "" {
_ = d.Set("consent", scope.Consent)
}
Expand Down
33 changes: 33 additions & 0 deletions okta/resource_okta_auth_server_scope_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package okta

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

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

func TestAccOktaAuthServerScope_crud(t *testing.T) {
Expand All @@ -14,6 +17,7 @@ func TestAccOktaAuthServerScope_crud(t *testing.T) {
mgr := newFixtureManager(authServerScope)
config := mgr.GetFixtures("basic.tf", ri, t)
updatedConfig := mgr.GetFixtures("basic_updated.tf", ri, t)
importConfig := mgr.GetFixtures("import.tf", ri, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -27,6 +31,7 @@ func TestAccOktaAuthServerScope_crud(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", "test:something"),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "display_name", "test"),
resource.TestCheckResourceAttr(resourceName, "system", "false"),
),
},
{
Expand All @@ -36,8 +41,36 @@ func TestAccOktaAuthServerScope_crud(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", "test:something"),
resource.TestCheckResourceAttr(resourceName, "description", "test_updated"),
resource.TestCheckResourceAttr(resourceName, "display_name", "test_updated"),
resource.TestCheckResourceAttr(resourceName, "system", "false"),
),
},
{
Config: importConfig,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("failed to find %s", resourceName)
}
return fmt.Sprintf("%s/%s", rs.Primary.Attributes["auth_server_id"], rs.Primary.Attributes["id"]), nil
},
ImportStateCheck: func(s []*terraform.InstanceState) (err error) {
if len(s) != 1 {
err = errors.New("failed to import into resource into state")
return
}

id := s[0].Attributes["id"]

if strings.Contains(id, "@") {
err = fmt.Errorf("user resource id incorrectly set, %s", id)
}
return
},
},
},
})
}
2 changes: 2 additions & 0 deletions website/docs/r/auth_server_scope.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The following arguments are supported:

- `auth_server_id` - The ID of the Auth Server.

- `system` - Whether Okta created the Scope

## Import

Okta Auth Server Scope can be imported via the Auth Server ID and Scope ID.
Expand Down