Skip to content

Commit 4734f8b

Browse files
author
Nick Hammond
committed
feat(cognito): Make cognito association optional
Signed-off-by: Nick Hammond <[email protected]>
1 parent 76028fe commit 4734f8b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ No modules.
6060

6161
| Name | Description | Type | Default | Required |
6262
|------|-------------|------|---------|:--------:|
63-
| <a name="input_cognito_user_pool_arn"></a> [cognito\_user\_pool\_arn](#input\_cognito\_user\_pool\_arn) | The ARN of the User Pool to grant the Postman user access to | `string` | n/a | yes |
63+
| <a name="input_cognito_user_pool_arn"></a> [cognito\_user\_pool\_arn](#input\_cognito\_user\_pool\_arn) | [Optional] The ARN of the User Pool to grant the Postman user access to | `string` | `""` | no |
6464
| <a name="input_username"></a> [username](#input\_username) | [Optional] The username to assign to the IAM user to be created | `string` | `"postman-user"` | no |
6565

6666
## Outputs

main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ data "aws_iam_policy_document" "cloudwatch_policy_document" {
3737

3838
# IAM Policy statements for accessing the Cognito permissions
3939
data "aws_iam_policy_document" "cognito_policy_document" {
40+
count = var.cognito_user_pool_arn != "" ? 1 : 0
41+
4042
statement {
4143
actions = [
4244
"cognito-idp:AdminInitiateAuth"
@@ -65,7 +67,8 @@ resource "aws_iam_policy" "cloudwatch_policy" {
6567

6668
# IAM Policy for accessing the Cognito userpools
6769
resource "aws_iam_policy" "cognito_policy" {
68-
policy = data.aws_iam_policy_document.cognito_policy_document.json
70+
count = var.cognito_user_pool_arn != "" ? 1 : 0
71+
policy = data.aws_iam_policy_document.cognito_policy_document[0].json
6972
}
7073

7174
# Attach the API Gateway policy to the User
@@ -82,7 +85,8 @@ resource "aws_iam_user_policy_attachment" "cloudwatch_user_policy_attachment" {
8285

8386
# Attach the Cognito policy to the User
8487
resource "aws_iam_user_policy_attachment" "cognito_user_policy_attachment" {
85-
policy_arn = aws_iam_policy.cognito_policy.arn
88+
count = var.cognito_user_pool_arn != "" ? 1 : 0
89+
policy_arn = aws_iam_policy.cognito_policy[0].arn
8690
user = aws_iam_user.user.name
8791
}
8892

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Variables: General
33
# -----------------------------------------------------------------------------
44
variable "cognito_user_pool_arn" {
5-
description = "The ARN of the User Pool to grant the Postman user access to"
5+
description = "[Optional] The ARN of the User Pool to grant the Postman user access to"
66
type = string
7+
default = ""
78
}
89

910
variable "username" {

0 commit comments

Comments
 (0)