From 9b6c0431f9903a84f50ee91d4ee407ec65929bb3 Mon Sep 17 00:00:00 2001 From: Sathiya Shunmugasundaram Date: Tue, 9 Jun 2015 11:02:19 -0400 Subject: [PATCH] Initial commit for aws-rds example --- examples/aws-rds/README.md | 0 examples/aws-rds/main.tf | 17 ++++++++++++ examples/aws-rds/outputs.tf | 6 +++++ examples/aws-rds/sg-variables.tf | 9 +++++++ examples/aws-rds/sg.tf | 22 ++++++++++++++++ examples/aws-rds/subnet-variables.tf | 24 +++++++++++++++++ examples/aws-rds/subnets.tf | 19 ++++++++++++++ examples/aws-rds/variables.tf | 39 ++++++++++++++++++++++++++++ 8 files changed, 136 insertions(+) create mode 100644 examples/aws-rds/README.md create mode 100644 examples/aws-rds/main.tf create mode 100644 examples/aws-rds/outputs.tf create mode 100644 examples/aws-rds/sg-variables.tf create mode 100644 examples/aws-rds/sg.tf create mode 100644 examples/aws-rds/subnet-variables.tf create mode 100644 examples/aws-rds/subnets.tf create mode 100644 examples/aws-rds/variables.tf diff --git a/examples/aws-rds/README.md b/examples/aws-rds/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/examples/aws-rds/main.tf b/examples/aws-rds/main.tf new file mode 100644 index 000000000..87a7f8030 --- /dev/null +++ b/examples/aws-rds/main.tf @@ -0,0 +1,17 @@ +resource "aws_db_instance" "default" { + identifier = "${var.identifier}" + allocated_storage = "${var.storage}" + engine = "${var.engine}" + engine_version = "${var.engine}" + instance_class = "${var.engine_version}" + name = "${var.db_name}" + username = "${var.username}" + password = "${var.password}" + vpc_security_group_ids = ["aws_security_group.default.id"] +} + +resource "aws_db_subnet_group" "default" { + name = "main" + 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 000000000..eca564b84 --- /dev/null +++ b/examples/aws-rds/outputs.tf @@ -0,0 +1,6 @@ +output "subnet_group" { + value = "${aws_db_subnet_group.default.name}" +} +output "subnet_group" { + value = "${aws_db_subnet_group.default.name}" +} \ No newline at end of file diff --git a/examples/aws-rds/sg-variables.tf b/examples/aws-rds/sg-variables.tf new file mode 100644 index 000000000..9c1e5b719 --- /dev/null +++ b/examples/aws-rds/sg-variables.tf @@ -0,0 +1,9 @@ +variable "cidr_blocks" { + default = ""0.0.0.0/0"" + description = "CIDR for sg" +} + +variable "sg_name" { + default = ""rds_sg"" + description = "Tag Name for sg" +} \ No newline at end of file diff --git a/examples/aws-rds/sg.tf b/examples/aws-rds/sg.tf new file mode 100644 index 000000000..c1e81b5b9 --- /dev/null +++ b/examples/aws-rds/sg.tf @@ -0,0 +1,22 @@ +resource "aws_security_group" "default" { + name = "main_rds_sg" + description = "Allow all inbound traffic" + + 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 000000000..00fe950df --- /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 AZ" +} + +variable "az_2" { + default = "us-east-1c" + description = "Your AZ" +} + +variable "vpc_id" { + default = "vpc-b6090dd3" + description = "Your VPC ID" +} \ No newline at end of file diff --git a/examples/aws-rds/subnets.tf b/examples/aws-rds/subnets.tf new file mode 100644 index 000000000..5de7d0d82 --- /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 000000000..62f3432ec --- /dev/null +++ b/examples/aws-rds/variables.tf @@ -0,0 +1,39 @@ +variable "identifier" { + default = "mydb-rds" + description = "Idnetifier for your DB" +} + +variable "storage" { + default = "10" + description = "Storage size in GB" +} + +variable "engine" { + default = "mysql" + description = "Engine type, supported values mysql" +} + +variable "engine_version" { + default = "5.6.17" + description = "Engine version" +} + +variable "instance_class" { + default = "db.t1.micro" + description = "Instance class" +} + +variable "db_name" { + default = "mydb" + description = "db name" +} + +variable "username" { + default = "user" + description = "User name" +} + +variable "password" { + default = "abcd1234" + description = "password" +}