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

Feature/upgrade db #67

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions aws/app-ms/env/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ module "nautible_aws_app" {
private_zone_id = data.terraform_remote_state.nautible_aws_platform.outputs.route53.private_zone_id
private_zone_name = data.terraform_remote_state.nautible_aws_platform.outputs.route53.private_zone_name
}
eks = local.target_eks
order = var.order
eks = local.target_eks
order = var.order
productdb = var.productdb
}

data "terraform_remote_state" "nautible_aws_platform" {
Expand Down
79 changes: 75 additions & 4 deletions aws/app-ms/env/dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ variable "eks" {
}
}


# ORDER
variable "order" {
description = "ORDER設定"
Expand All @@ -52,13 +51,85 @@ variable "order" {
# elasticache
elasticache = {
# engine version
engine_version = "6.x"
engine_version = "7.1"
# node type
node_type = "cache.t2.micro"
node_type = "cache.t4g.micro"
# parameter group name
parameter_group_name = "default.redis6.x"
parameter_group_name = "default.redis7"
# port
port = 6379
}
}
}

# Product
variable "productdb" {
SaitoMunenori marked this conversation as resolved.
Show resolved Hide resolved
description = "商品DB用RDS設定"
type = object({
mysql = object({
engine_version = string
instance_class = string
option_group_name = string
storage_type = string
allocated_storage = number
})
parameter_group = object({
SaitoMunenori marked this conversation as resolved.
Show resolved Hide resolved
family = string
parameters = list(object({
name = string
value = string
}))
})
})
default = {
mysql = {
engine_version = "8.0.36"
instance_class = "db.t3.micro"
option_group_name = "default:mysql-8-0"
storage_type = "gp2"
allocated_storage = 5
}
parameter_group = {
family = "mysql8.0"
parameters = [
{
name = "character_set_client"
value = "utf8mb4"
},
{
name = "character_set_connection"
value = "utf8mb4"
},
{
name = "character_set_database"
value = "utf8mb4"
},
{
name = "character_set_filesystem"
value = "utf8mb4"
},
{
name = "character_set_results"
value = "utf8mb4"
},
{
name = "character_set_server"
value = "utf8mb4"
},
{
name = "collation_connection"
value = "utf8mb4_general_ci"
},
{
name = "collation_server"
value = "utf8mb4_general_ci"
},
{
name = "time_zone"
value = "Asia/Tokyo"
}
]
}
}
}

33 changes: 20 additions & 13 deletions aws/app-ms/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
module "common" {
source = "./modules/common"
pjname = var.pjname
region = var.region
platform_pjname = var.platform_pjname
eks_oidc_provider_arns = values(var.eks).*.oidc.provider_arn
eks_cluster_name_node_role_name_map = zipmap(values(var.eks).*.cluster.name,values(var.eks).*.node.role_name)
source = "./modules/common"
pjname = var.pjname
region = var.region
platform_pjname = var.platform_pjname
eks_oidc_provider_arns = values(var.eks).*.oidc.provider_arn
eks_cluster_name_node_role_name_map = zipmap(values(var.eks).*.cluster.name, values(var.eks).*.node.role_name)
}

module "product" {
source = "./modules/product"
pjname = var.pjname
platform_pjname = var.platform_pjname
vpc_id = var.vpc.vpc_id
private_subnets = var.vpc.private_subnets
private_zone_id = var.vpc.private_zone_id
private_zone_name = var.vpc.private_zone_name
source = "./modules/product"
pjname = var.pjname
platform_pjname = var.platform_pjname
vpc_id = var.vpc.vpc_id
private_subnets = var.vpc.private_subnets
private_zone_id = var.vpc.private_zone_id
private_zone_name = var.vpc.private_zone_name
eks_node_security_group_ids = values(var.eks).*.node.security_group_id
engine_version = var.productdb.mysql.engine_version
instance_class = var.productdb.mysql.instance_class
option_group_name = var.productdb.mysql.option_group_name
storage_type = var.productdb.mysql.storage_type
allocated_storage = var.productdb.mysql.allocated_storage
parameter_family = var.productdb.parameter_group.family
parameters = var.productdb.parameter_group.parameters
}

module "customer" {
Expand Down
60 changes: 12 additions & 48 deletions aws/app-ms/modules/product/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,52 +42,15 @@ resource "aws_db_subnet_group" "product_db_dbsubnet" {

resource "aws_db_parameter_group" "product_db_dbpg" {
name = "product-db-dbpg"
family = "mysql5.7"
family = var.parameter_family
description = "db parameter group for product-db"

parameter {
name = "character_set_client"
value = "utf8mb4"
}

parameter {
name = "character_set_connection"
value = "utf8mb4"
}

parameter {
name = "character_set_database"
value = "utf8mb4"
}

parameter {
name = "character_set_filesystem"
value = "utf8mb4"
}

parameter {
name = "character_set_results"
value = "utf8mb4"
}

parameter {
name = "character_set_server"
value = "utf8mb4"
}

parameter {
name = "collation_connection"
value = "utf8mb4_general_ci"
}

parameter {
name = "collation_server"
value = "utf8mb4_general_ci"
}

parameter {
name = "time_zone"
value = "Asia/Tokyo"
dynamic "parameter" {
for_each = var.parameters
content {
name = parameter.value.name
value = parameter.value.value
}
}
}

Expand All @@ -101,15 +64,16 @@ data "aws_ssm_parameter" "product_db_password" {

resource "aws_db_instance" "product_db" {
identifier = "product-db"
allocated_storage = 5
storage_type = "gp2"
allocated_storage = var.allocated_storage
storage_type = var.storage_type
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t3.micro"
engine_version = var.engine_version
instance_class = var.instance_class
db_name = "productdb"
username = data.aws_ssm_parameter.product_db_user.value
password = data.aws_ssm_parameter.product_db_password.value
parameter_group_name = aws_db_parameter_group.product_db_dbpg.name
option_group_name = var.option_group_name
backup_retention_period = 1
skip_final_snapshot = false
final_snapshot_identifier = "product-db-final-snapshot"
Expand Down
7 changes: 7 additions & 0 deletions aws/app-ms/modules/product/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ variable "private_subnets" {}
variable "private_zone_id" {}
variable "private_zone_name" {}
variable "eks_node_security_group_ids" {}
variable "engine_version" {}
variable "instance_class" {}
variable "option_group_name" {}
variable "storage_type" {}
variable "allocated_storage" {}
variable "parameter_family" {}
variable "parameters" {}
1 change: 1 addition & 0 deletions aws/app-ms/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ variable "region" {}
variable "vpc" {}
variable "eks" {}
variable "order" {}
variable "productdb" {}
4 changes: 2 additions & 2 deletions aws/plugin/env/dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ variable "auth" {
default = {
# postgresql variables
postgres = {
engine_version = "14.7"
engine_version = "16.3"
instance_class = "db.t3.micro"
parameter_group_name = "default.postgres14"
parameter_group_name = "default.postgres16"
storage_type = "gp2"
allocated_storage = 20
}
Expand Down