Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Cognitoユーザープール用のリソースを作成する #6

Merged
merged 3 commits into from
Jun 4, 2020
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
46 changes: 46 additions & 0 deletions modules/aws/cognito/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
resource "aws_cognito_user_pool" "pool" {
name = var.user_pool_name
auto_verified_attributes = ["email"]

admin_create_user_config {
allow_admin_create_user_only = false
}

password_policy {
minimum_length = 8
require_lowercase = true
require_numbers = true
require_symbols = true
require_uppercase = true
temporary_password_validity_days = 7
}

verification_message_template {
default_email_option = "CONFIRM_WITH_CODE"
email_message = "検証コードは {####} です。"
email_subject = "検証コード"
sms_message = "検証コードは {####} です。"
}

schema {
attribute_data_type = "String"
developer_only_attribute = false
mutable = true
name = "email"
required = true

string_attribute_constraints {
min_length = 0
max_length = 2048
}
}
}

resource "aws_cognito_user_pool_client" "client" {
name = var.user_pool_name
user_pool_id = aws_cognito_user_pool.pool.id
generate_secret = false
prevent_user_existence_errors = "ENABLED"
refresh_token_validity = 30
explicit_auth_flows = ["ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Gatewayで Cognito User Poolをオーソライザーとして設定することを想定している。
ドキュメントを読んでもこの設定でいいのかがわからなかったので、今後開発を進める中で変更するかもしれない。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基本これで良いと思った🐱

ALLOW_ADMIN_USER_PASSWORD_AUTH

Next.jsはBFF層持てるし、基本的にこれで問題なさそうだなって思った🐱

ALLOW_REFRESH_TOKEN_AUTH

これはユーザーの再認証減らしたいから設定しておいて良さそう!

今後開発を進める中で変更するかもしれない。

そうだね!やってみて問題あれば変更で良さそうだね!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
3 changes: 3 additions & 0 deletions modules/aws/cognito/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "user_pool_name" {
type = string
}
9 changes: 9 additions & 0 deletions providers/aws/environments/stg/13-cognito/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
backend "s3" {
bucket = "stg-kimono-app-tfstate"
key = "cognito/terraform.tfstate"
region = "ap-northeast-1"
profile = "kimono-app-stg"
}
}

5 changes: 5 additions & 0 deletions providers/aws/environments/stg/13-cognito/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "api" {
source = "../../../../../modules/aws/cognito"

user_pool_name = local.user_pool_name
}
4 changes: 4 additions & 0 deletions providers/aws/environments/stg/13-cognito/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = "ap-northeast-1"
profile = "kimono-app-stg"
}
6 changes: 6 additions & 0 deletions providers/aws/environments/stg/13-cognito/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locals {
name = "kimono-app"
env = "stg"

user_pool_name = "${local.env}-${local.name}"
}
7 changes: 7 additions & 0 deletions providers/aws/environments/stg/13-cognito/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_version = "0.12.24"

required_providers {
aws = "2.57.0"
}
}