Skip to content

Commit f423111

Browse files
Merge pull request #60 from mineiros-io/soerenmartius/resource-server
Add support for resource server
2 parents 66cb8b1 + 9b0beee commit f423111

File tree

6 files changed

+104
-3
lines changed

6 files changed

+104
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.1]
11+
1012
### Added
1113

1214
- Add support for `module_tags`
15+
- Implement support for resource servers through the
16+
`aws_cognito_resource_server` resource
1317

1418
## [0.9.0]
1519

@@ -150,11 +154,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
150154

151155
<!-- markdown-link-check-disable -->
152156

153-
[unreleased]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.9.0...HEAD
154-
[0.9.0]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.8.0...v0.9.0
157+
[unreleased]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.9.1...HEAD
158+
[0.9.1]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.9.0...v0.9.1
155159

156160
<!-- markdown-link-check-enable -->
157161

162+
[0.9.0]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.8.0...v0.9.0
158163
[0.8.0]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.7.0...v0.8.0
159164
[0.7.0]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.6.0...v0.7.0
160165
[0.6.0]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/compare/v0.5.0...v0.6.0

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ pre-configured.
5555
Create a Cognito User Pool with pre-configured best practices.
5656
Create Cognito User Pool Clients.
5757
Create a Cognito User Pool Domain.
58+
Create Cognito User Pool Resource Servers as associated scopes.
5859

5960
- *Features not yet implemented*:
6061
[`cognito_user_group`](https://www.terraform.io/docs/providers/aws/r/cognito_user_group.html)
61-
[`cognito_resource_server`](https://www.terraform.io/docs/providers/aws/r/cognito_resource_server.html)
6262

6363
## Getting Started
6464

@@ -424,6 +424,36 @@ for details and use-cases.
424424
The ARN of an ISSUED ACM certificate in us-east-1 for a custom domain.
425425
Default is not to use a custom domain.
426426

427+
#### Cognito User Pool Resource Servers
428+
429+
- **`resource_servers`**: *(Optional `list(resource_server)`)
430+
431+
A list of objects with resource server declarations.
432+
Default is []
433+
434+
**Example:**
435+
436+
A resource server declaration with scopes. For details see the [Terraform AWS Cognito Resource Server Docs]
437+
438+
```hcl
439+
resource_servers = [
440+
{
441+
identifier = "https://api.resourceserver.com"
442+
name = "API"
443+
scopes = [
444+
{
445+
scope_name = "users:read"
446+
scope_description = "Read user data"
447+
},
448+
{
449+
scope_name = "users:write"
450+
scope_description = "Write user data"
451+
}
452+
]
453+
}
454+
]
455+
```
456+
427457
#### Cognito User Pool Clients
428458

429459
- **`clients`**: *(Optional `list(client)`)*
@@ -660,3 +690,4 @@ Copyright &copy; 2020 [Mineiros GmbH][homepage]
660690
[Cognito User Pools]: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.html
661691
[attributes docs]: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
662692
[Terraform AWS Cognito User Pool Client Docs]: https://www.terraform.io/docs/providers/aws/r/cognito_user_pool_client.html
693+
[Terraform AWS Cognito Resource Server Docs]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_resource_server

main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ resource "aws_cognito_user_pool_client" "client" {
243243
}
244244

245245
enable_token_revocation = each.value.enable_token_revocation
246+
247+
depends_on = [
248+
aws_cognito_resource_server.resource_server
249+
]
246250
}
247251

248252
resource "aws_cognito_user_pool_domain" "domain" {

resource-server.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "aws_cognito_resource_server" "resource_server" {
2+
for_each = var.module_enabled ? { for resource in var.resource_servers : resource.identifier => resource } : {}
3+
identifier = each.value.identifier
4+
name = try(each.value.name, null)
5+
user_pool_id = aws_cognito_user_pool.user_pool[0].id
6+
7+
dynamic "scope" {
8+
for_each = try(each.value.scopes, [])
9+
10+
content {
11+
scope_name = scope.value.scope_name
12+
scope_description = scope.value.scope_description
13+
}
14+
}
15+
}

test/unit-complete/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ module "test" {
4545
}
4646
]
4747

48+
resource_servers = [
49+
{
50+
identifier = "https://api.resourceserver.com"
51+
name = "API"
52+
scopes = [
53+
{
54+
scope_name = "users:read",
55+
scope_description = "Read user data"
56+
},
57+
{
58+
scope_name = "users:write"
59+
scope_description = "Write user data"
60+
}
61+
]
62+
}
63+
]
64+
4865
# add most/all other optional arguments
4966

5067
enable_username_case_sensitivity = false

variables.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,35 @@ variable "allow_admin_create_user_only" {
4545
default = true
4646
}
4747

48+
variable "resource_servers" {
49+
description = "(Optional) A list of objects with resource server definitions."
50+
type = any
51+
52+
# Declare resource servers and associated custom scopes
53+
# For details please see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_resource_server
54+
#
55+
# Example:
56+
#
57+
# resource_servers = [
58+
# {
59+
# identifier = "https://api.resourceserver.com"
60+
# name = "API"
61+
# scopes = [
62+
# {
63+
# scope_name = "users:read"
64+
# scope_description = "Read user data"
65+
# },
66+
# {
67+
# scope_name = "users:write"
68+
# scope_description = "Write user data"
69+
# }
70+
# ]
71+
# }
72+
# ]
73+
74+
default = []
75+
}
76+
4877
variable "clients" {
4978
description = "(Optional) A list of objects with the clients definitions."
5079
type = any

0 commit comments

Comments
 (0)