Created
April 14, 2017 13:44
-
-
Save nisshiee/eba5260dcaa79061433dae7a97a4d2ee to your computer and use it in GitHub Desktop.
TerraformでAuroraを立てる
This file contains hidden or 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
resource "aws_rds_cluster" "default" { | |
cluster_identifier = "${var.service}-${var.name}-${var.env}" | |
master_username = "${var.username}" | |
master_password = "${var.password}" | |
backup_retention_period = 5 | |
preferred_backup_window = "19:30-20:00" | |
preferred_maintenance_window = "wed:20:15-wed:20:45" | |
port = 3306 | |
vpc_security_group_ids = ["${var.security_group_ids}"] | |
db_subnet_group_name = "${var.subnet_group_name}" | |
storage_encrypted = "${var.storage_encrypted}" | |
db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.default.name}" | |
tags { | |
Name = "${var.service}_${var.name}_${var.env}" | |
Service = "${var.service}" | |
Env = "${var.env}" | |
} | |
} | |
resource "aws_rds_cluster_instance" "default" { | |
count = "${var.cluster_instance_count}" | |
identifier = "${var.service}-${var.name}-${var.env}-${count.index}" | |
cluster_identifier = "${aws_rds_cluster.default.id}" | |
instance_class = "${var.cluster_instance_class}" | |
db_subnet_group_name = "${var.subnet_group_name}" | |
db_parameter_group_name = "${aws_db_parameter_group.default.name}" | |
monitoring_role_arn = "${aws_iam_role.monitoring.arn}" | |
monitoring_interval = 60 | |
tags { | |
Name = "${var.service}_${var.name}_${var.env}" | |
Service = "${var.service}" | |
Env = "${var.env}" | |
} | |
} |
This file contains hidden or 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
resource "aws_iam_role" "monitoring" { | |
name = "${var.service}_rds_monitoring_${var.env}" | |
path = "/" | |
assume_role_policy = <<POLICY | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "monitoring.rds.amazonaws.com" | |
}, | |
"Effect": "Allow" | |
} | |
] | |
} | |
POLICY | |
} | |
resource "aws_iam_role_policy_attachment" "monitoring" { | |
role = "${aws_iam_role.monitoring.name}" | |
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole" | |
} |
This file contains hidden or 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
resource "aws_db_parameter_group" "default" { | |
name = "${var.service}-${var.name}-${var.env}" | |
family = "aurora5.6" | |
tags { | |
Name = "${var.service}_${var.name}_${var.env}" | |
Service = "${var.service}" | |
Env = "${var.env}" | |
} | |
} | |
resource "aws_rds_cluster_parameter_group" "default" { | |
name = "${var.service}-${var.name}-${var.env}" | |
family = "aurora5.6" | |
description = "Cluster parameter group for ${var.service}-${var.name}-${var.env}" | |
tags { | |
Name = "${var.service}_${var.name}_${var.env}" | |
Service = "${var.service}" | |
Env = "${var.env}" | |
} | |
parameter { | |
name = "character_set_client" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "character_set_connection" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "character_set_database" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "character_set_filesystem" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "character_set_results" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "character_set_server" | |
value = "utf8mb4" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "collation_connection" | |
value = "utf8mb4_general_ci" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "collation_server" | |
value = "utf8mb4_general_ci" | |
apply_method = "immediate" | |
} | |
parameter { | |
name = "time_zone" | |
value = "Asia/Tokyo" | |
apply_method = "immediate" | |
} | |
} |
This file contains hidden or 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
variable "service" { } | |
variable "name" { } | |
variable "env" { } | |
variable "username" { } | |
variable "password" { } | |
variable "security_group_ids" { type = "list" } | |
variable "subnet_group_name" { } | |
variable "storage_encrypted" { } | |
variable "cluster_instance_count" { } | |
variable "cluster_instance_class" { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment