-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package aws | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAWSCognitoResourceServer_basic(t *testing.T) { | ||
identifier := fmt.Sprintf("tf-acc-test-resource-server-id-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
name := fmt.Sprintf("tf-acc-test-resource-server-name-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
poolName := fmt.Sprintf("tf-acc-test-pool-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSCognitoResourceServerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSCognitoResourceServerConfig_basic(identifier, name, poolName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSCognitoResourceServerExists("aws_cognito_resource_server.main"), | ||
resource.TestCheckResourceAttr("aws_cognito_resource_server.main", "identifier", identifier), | ||
resource.TestCheckResourceAttr("aws_cognito_resource_server.main", "name", name), | ||
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "name", poolName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSCognitoResourceServer_full(t *testing.T) { | ||
identifier := fmt.Sprintf("tf-acc-test-resource-server-id-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
name := fmt.Sprintf("tf-acc-test-resource-server-name-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
scopeName := fmt.Sprintf("tf-acc-test-resource-server-scope-name-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
scopeDescription := fmt.Sprintf("tf-acc-test-resource-server-scope-description-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
poolName := fmt.Sprintf("tf-acc-test-pool-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSCognitoResourceServerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSCognitoResourceServerConfig_full(identifier, name, scopeName, scopeDescription, poolName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSCognitoResourceServerExists("aws_cognito_resource_server.main"), | ||
resource.TestCheckResourceAttr("aws_cognito_resource_server.main", "identifier", identifier), | ||
resource.TestCheckResourceAttr("aws_cognito_resource_server.main", "name", name), | ||
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "name", poolName), | ||
resource.TestCheckResourceAttrSet("aws_cognito_resource_server.main", "scope_identifiers"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSCognitoResourceServerExists(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return errors.New("No Cognito Resource Server ID is set") | ||
} | ||
|
||
conn := testAccProvider.Meta().(*AWSClient).cognitoidpconn | ||
|
||
_, err := conn.DescribeResourceServer(&cognitoidentityprovider.DescribeResourceServerInput{ | ||
Identifier: aws.String(rs.Primary.ID), | ||
UserPoolId: aws.String(rs.Primary.Attributes["user_pool_id"]), | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSCognitoResourceServerDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).cognitoidpconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_cognito_resource_server" { | ||
continue | ||
} | ||
|
||
_, err := conn.DescribeResourceServer(&cognitoidentityprovider.DescribeResourceServerInput{ | ||
Identifier: aws.String(rs.Primary.ID), | ||
UserPoolId: aws.String(rs.Primary.Attributes["user_pool_id"]), | ||
}) | ||
|
||
if err != nil { | ||
if isAWSErr(err, "ResourceNotFoundException", "") { | ||
return nil | ||
} | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccAWSCognitoResourceServerConfig_basic(identifier string, name string, poolName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_cognito_resource_server" "main" { | ||
identifier = "%s" | ||
name = "%s" | ||
user_pool_id = "${aws_cognito_user_pool.main.id}" | ||
} | ||
resource "aws_cognito_user_pool" "main" { | ||
name = "%s" | ||
} | ||
`, identifier, name, poolName) | ||
} | ||
|
||
func testAccAWSCognitoResourceServerConfig_full(identifier string, name string, scopeName string, scopeDescription string, poolName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_cognito_resource_server" "main" { | ||
identifier = "%s" | ||
name = "%s" | ||
scope = { | ||
scope_name = "%s" | ||
scope_description = "%s" | ||
} | ||
user_pool_id = "${aws_cognito_user_pool.main.id}" | ||
} | ||
resource "aws_cognito_user_pool" "main" { | ||
name = "%s" | ||
} | ||
`, identifier, name, scopeName, scopeDescription, poolName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_cognito_resource_server" | ||
side_bar_current: "docs-aws-resource-cognito-resource-server" | ||
description: |- | ||
Provides a Cognito Resource Server. | ||
--- | ||
|
||
# aws_cognito_resource_server | ||
|
||
Provides a Cognito Resource Server. | ||
|
||
## Example Usage | ||
|
||
### Create a basic resource server | ||
|
||
```hcl | ||
resource "aws_cognito_user_pool" "pool" { | ||
name = "pool" | ||
} | ||
resource "aws_cognito_resource_server" "resource" { | ||
identifier = "res" | ||
name = "resource" | ||
user_pool_id = "${aws_cognito_user_pool.pool.id}" | ||
} | ||
``` | ||
|
||
### Create a resource server with sample-scope | ||
|
||
```hcl | ||
resource "aws_cognito_user_pool" "pool" { | ||
name = "pool" | ||
} | ||
resource "aws_cognito_resource_server" "resource" { | ||
identifier = "res" | ||
name = "resource" | ||
scope = { | ||
scope_name = "sample-scope" | ||
scope_description = "a Sample Scope Description" | ||
} | ||
user_pool_id = "${aws_cognito_user_pool.pool.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `identifier` - (Required) An identifier for the resource server. | ||
* `name` - (Required) A name for the resource server. | ||
* `scope` - (Optional) The configuration for an [Authorization Scope](#authorization_scope). | ||
|
||
### Authorization Scope | ||
|
||
* `scope_name` - (Required) The scope name. | ||
* `scope_description` - (Required) The scope description. | ||
|
||
## Attribute Reference | ||
|
||
In addition to the arguments, which are exported, the following attributes are exported: | ||
|
||
* `scope_identifiers` - A list of all scopes configured for this resource server in the format identifier/scope_name. |