Unverified Commit efe45974 authored by nownabe's avatar nownabe

Add terraform configurations

parents
export TF_VAR_public_key="$(cat ~/.ssh/id_rsa.pub)"
export TF_VAR_rds_instance_class="db.r4.2xlarge"
export TF_VAR_google_project_id="my-rdbbench-prj"
export TF_VAR_cloud_sql_tier="db-n1-highmem-8"
export TF_VAR_billing_account_name="My Billing Account"
.envrc
.terraform
terraform.tfstate*
variable "public_key" {}
variable "rds_instance_class" {}
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
tags {
Name = "rdbbench"
}
}
resource "aws_security_group" "ssh" {
name = "rdbbench-ssh"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
vpc_id = "${aws_vpc.vpc.id}"
tags {
Name = "rdbbench-ssh"
}
}
resource "aws_security_group" "mysql" {
name = "rdbbench-mysql"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["${aws_vpc.vpc.cidr_block}"]
}
egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
vpc_id = "${aws_vpc.vpc.id}"
tags {
Name = "rdbbench-mysql"
}
}
resource "aws_subnet" "subnet1" {
availability_zone = "ap-northeast-1a"
cidr_block = "10.0.1.0/24"
vpc_id = "${aws_vpc.vpc.id}"
tags {
Name = "rdbbench"
}
}
resource "aws_subnet" "subnet2" {
availability_zone = "ap-northeast-1c"
cidr_block = "10.0.2.0/24"
vpc_id = "${aws_vpc.vpc.id}"
tags {
Name = "rdbbench"
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc.id}"
tags {
Name = "rdbbench"
}
}
resource "aws_route_table" "route_table" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
}
resource "aws_route_table_association" "association1" {
subnet_id = "${aws_subnet.subnet1.id}"
route_table_id = "${aws_route_table.route_table.id}"
}
resource "aws_route_table_association" "association2" {
subnet_id = "${aws_subnet.subnet2.id}"
route_table_id = "${aws_route_table.route_table.id}"
}
resource "aws_db_subnet_group" "db_subnet_group" {
name = "rdbbench"
subnet_ids = ["${aws_subnet.subnet1.id}", "${aws_subnet.subnet2.id}"]
tags {
Name = "rdbbench"
}
}
resource "aws_db_instance" "rds" {
allocated_storage = 10
db_subnet_group_name = "${aws_db_subnet_group.db_subnet_group.name}"
engine = "mysql"
engine_version = "5.7.21"
instance_class = "${var.rds_instance_class}"
multi_az = true
password = "password"
storage_type = "gp2"
username = "user"
vpc_security_group_ids = ["${aws_security_group.mysql.id}"]
}
resource "aws_rds_cluster" "aurora" {
cluster_identifier = "rdbbench"
master_password = "password"
master_username = "user"
skip_final_snapshot = true
vpc_security_group_ids = ["${aws_security_group.mysql.id}"]
db_subnet_group_name = "${aws_db_subnet_group.db_subnet_group.name}"
engine = "aurora-mysql"
engine_version = "5.7.12"
}
resource "aws_rds_cluster_instance" "aurora" {
identifier = "rdbbench"
cluster_identifier = "${aws_rds_cluster.aurora.cluster_identifier}"
instance_class = "${var.rds_instance_class}"
db_subnet_group_name = "${aws_db_subnet_group.db_subnet_group.name}"
engine = "aurora-mysql"
engine_version = "5.7.12"
}
resource "aws_key_pair" "key_pair" {
key_name = "rdbbench"
public_key = "${var.public_key}"
}
resource "aws_instance" "client" {
ami = "ami-e99f4896"
instance_type = "m5.xlarge"
key_name = "${aws_key_pair.key_pair.key_name}"
vpc_security_group_ids = ["${aws_security_group.ssh.id}"]
associate_public_ip_address = true
subnet_id = "${aws_subnet.subnet1.id}"
tags = {
Name = "rdbbench"
}
}
variable "google_project_id" {}
variable "cloud_sql_tier" {}
variable "billing_account_name" {}
data "google_billing_account" "billing" {
display_name = "${var.billing_account_name}"
open = true
}
resource "google_project" "project" {
name = "rdbbench"
project_id = "${var.google_project_id}"
billing_account = "${data.google_billing_account.billing.id}"
}
resource "google_project_service" "compute" {
service = "compute.googleapis.com"
project = "${google_project.project.id}"
}
resource "google_compute_address" "address" {
name = "rdbbench"
region = "asia-northeast1"
project = "${google_project.project.id}"
}
resource "google_sql_database_instance" "master" {
region = "asia-northeast1"
settings {
tier = "${var.cloud_sql_tier}"
disk_autoresize = true
disk_size = 100
disk_type = "PD_SSD"
replication_type = "SYNCHRONOUS"
backup_configuration {
binary_log_enabled = true
enabled = true
}
ip_configuration {
ipv4_enabled = true
authorized_networks {
name = "rdbbench"
value = "${google_compute_address.address.address}"
}
}
}
database_version = "MYSQL_5_7"
name = "master"
project = "${google_project.project.id}"
}
resource "google_sql_database_instance" "failover" {
region = "${google_sql_database_instance.master.region}"
settings {
tier = "${google_sql_database_instance.master.settings.0.tier}"
crash_safe_replication = true
disk_autoresize = true
disk_size = "${google_sql_database_instance.master.settings.0.disk_size}"
disk_type = "PD_SSD"
replication_type = "SYNCHRONOUS"
}
database_version = "MYSQL_5_7"
name = "failover"
master_instance_name = "${google_sql_database_instance.master.name}"
project = "${google_project.project.id}"
replica_configuration {
failover_target = true
}
}
resource "google_sql_user" "user" {
name = "user"
instance = "${google_sql_database_instance.master.name}"
password = "password"
host = "%"
project = "${google_project.project.id}"
}
resource "google_compute_instance" "client" {
boot_disk {
auto_delete = true
initialize_params {
size = 20
type = "pd-standard"
image = "centos-cloud/centos-7"
}
}
machine_type = "n1-standard-4"
name = "rdbbench"
zone = "asia-northeast1-a"
network_interface {
network = "default"
access_config {
nat_ip = "${google_compute_address.address.address}"
}
}
project = "${google_project.project.id}"
}
provider "aws" {
version = "~>1.25"
region = "ap-northeast-1"
}
provider "google" {
version = "~>1.15"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment