diff --git a/examples/aws-rds/README.md b/examples/aws-rds/README.md new file mode 100644 index 0000000000..dfc8e3746b --- /dev/null +++ b/examples/aws-rds/README.md @@ -0,0 +1,17 @@ +## Creating an RDS instance in AWS + +This example provides sample configuration for creating a mysql or postgres insatnce. For Oracle/SQL Servers, replace default values with appropriate values, they are not included in sample since the number of options are high. + +The example creates db subnet groups and a VPC security group as inputs to the instance creation + +For AWS provider, set up your AWS environment as outlined in https://www.terraform.io/docs/providers/aws/index.html + +If you need to use existing security groups and subnets, remove the sg.tf and subnets.tf files and replace the corresponidng sections in main.tf under aws_db_instance + +Pass the password variable through your ENV variable. + +Several paraneters are externalized, review the different variables.tf files and change them to fit your needs. Carefully review the CIDR blocks, egress/ingress rules, availability zones that are very specific to your account. + +Once ready run 'terraform plan' to review. At the minimum, provide the vpc_id as input variable. + +Once satisfied with plan, run 'terraform apply' diff --git a/examples/aws-rds/main.tf b/examples/aws-rds/main.tf new file mode 100644 index 0000000000..d292a38af9 --- /dev/null +++ b/examples/aws-rds/main.tf @@ -0,0 +1,19 @@ +resource "aws_db_instance" "default" { + depends_on = "aws_security_group.default" + identifier = "${var.identifier}" + allocated_storage = "${var.storage}" + engine = "${var.engine}" + engine_version = "${lookup(var.engine_version, var.engine)}" + instance_class = "${var.instance_class}" + name = "${var.db_name}" + username = "${var.username}" + password = "${var.password}" + vpc_security_group_ids = ["${aws_security_group.default.id}"] + db_subnet_group_name = "${aws_db_subnet_group.default.id}" +} + +resource "aws_db_subnet_group" "default" { + name = "main_subnet_group" + description = "Our main group of subnets" + subnet_ids = ["${aws_subnet.subnet_1.id}", "${aws_subnet.subnet_2.id}"] +} diff --git a/examples/aws-rds/outputs.tf b/examples/aws-rds/outputs.tf new file mode 100644 index 0000000000..1bf2b0cb8f --- /dev/null +++ b/examples/aws-rds/outputs.tf @@ -0,0 +1,10 @@ +output "subnet_group" { + value = "${aws_db_subnet_group.default.name}" +} +output "db_instance_id" { + value = "${aws_db_instance.default.id}" +} +output "db_instance_address" { + value = "${aws_db_instance.default.address}" +} + diff --git a/examples/aws-rds/sg-variables.tf b/examples/aws-rds/sg-variables.tf new file mode 100644 index 0000000000..a1fefe4130 --- /dev/null +++ b/examples/aws-rds/sg-variables.tf @@ -0,0 +1,10 @@ +variable "cidr_blocks" { + default = "0.0.0.0/0" + description = "CIDR for sg" +} + +variable "sg_name" { + default = "rds_sg" + description = "Tag Name for sg" +} + diff --git a/examples/aws-rds/sg.tf b/examples/aws-rds/sg.tf new file mode 100644 index 0000000000..c55b0799de --- /dev/null +++ b/examples/aws-rds/sg.tf @@ -0,0 +1,23 @@ +resource "aws_security_group" "default" { + name = "main_rds_sg" + description = "Allow all inbound traffic" + vpc_id = "${var.vpc_id}" + + ingress { + from_port = 0 + to_port = 65535 + protocol = "TCP" + cidr_blocks = ["${var.cidr_blocks}"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags { + Name = "${var.sg_name}" + } +} diff --git a/examples/aws-rds/subnet-variables.tf b/examples/aws-rds/subnet-variables.tf new file mode 100644 index 0000000000..35c695088b --- /dev/null +++ b/examples/aws-rds/subnet-variables.tf @@ -0,0 +1,24 @@ +variable "subnet_1_cidr" { + default = "10.0.1.0/24" + description = "Your AZ" +} + +variable "subnet_2_cidr" { + default = "10.0.2.0/24" + description = "Your AZ" +} + +variable "az_1" { + default = "us-east-1b" + description = "Your Az1, use AWS CLI to find your account specific" +} + +variable "az_2" { + default = "us-east-1c" + description = "Your Az2, use AWS CLI to find your account specific" +} + +variable "vpc_id" { + description = "Your VPC ID" +} + diff --git a/examples/aws-rds/subnets.tf b/examples/aws-rds/subnets.tf new file mode 100644 index 0000000000..5de7d0d82b --- /dev/null +++ b/examples/aws-rds/subnets.tf @@ -0,0 +1,19 @@ +resource "aws_subnet" "subnet_1" { + vpc_id = "${var.vpc_id}" + cidr_block = "${var.subnet_1_cidr}" + availability_zone = "${var.az_1}" + + tags { + Name = "main_subnet1" + } +} + +resource "aws_subnet" "subnet_2" { + vpc_id = "${var.vpc_id}" + cidr_block = "${var.subnet_2_cidr}" + availability_zone = "${var.az_2}" + + tags { + Name = "main_subnet2" + } +} diff --git a/examples/aws-rds/variables.tf b/examples/aws-rds/variables.tf new file mode 100644 index 0000000000..ad3156b1be --- /dev/null +++ b/examples/aws-rds/variables.tf @@ -0,0 +1,41 @@ +variable "identifier" { + default = "mydb-rds" + description = "Identifier for your DB" +} + +variable "storage" { + default = "10" + description = "Storage size in GB" +} + +variable "engine" { + default = "postgres" + description = "Engine type, example values mysql, postgres" +} + +variable "engine_version" { + description = "Engine version" + default = { + mysql = "5.6.22" + postgres = "9.4.1" + } +} + +variable "instance_class" { + default = "db.t2.micro" + description = "Instance class" +} + +variable "db_name" { + default = "mydb" + description = "db name" +} + +variable "username" { + default = "myuser" + description = "User name" +} + +variable "password" { + description = "password, provide through your ENV variables" +}