diff --git a/examples/aws-rds/README.md b/examples/aws-rds/README.md index e69de29bb..f54cd393f 100644 --- a/examples/aws-rds/README.md +++ b/examples/aws-rds/README.md @@ -0,0 +1,15 @@ +## Creating an RDS insatnce 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 + +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' \ No newline at end of file diff --git a/examples/aws-rds/main.tf b/examples/aws-rds/main.tf index 87a7f8030..d292a38af 100644 --- a/examples/aws-rds/main.tf +++ b/examples/aws-rds/main.tf @@ -1,17 +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 = "${var.engine}" - instance_class = "${var.engine_version}" + 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"] + 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" + 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 index eca564b84..0a3214ff3 100644 --- a/examples/aws-rds/outputs.tf +++ b/examples/aws-rds/outputs.tf @@ -1,6 +1,9 @@ output "subnet_group" { value = "${aws_db_subnet_group.default.name}" } -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}" } \ No newline at end of file diff --git a/examples/aws-rds/sg-variables.tf b/examples/aws-rds/sg-variables.tf index 9c1e5b719..8e8cb3172 100644 --- a/examples/aws-rds/sg-variables.tf +++ b/examples/aws-rds/sg-variables.tf @@ -1,9 +1,9 @@ variable "cidr_blocks" { - default = ""0.0.0.0/0"" + default = "0.0.0.0/0" description = "CIDR for sg" } variable "sg_name" { - default = ""rds_sg"" + 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 index c1e81b5b9..c55b0799d 100644 --- a/examples/aws-rds/sg.tf +++ b/examples/aws-rds/sg.tf @@ -1,6 +1,7 @@ resource "aws_security_group" "default" { name = "main_rds_sg" description = "Allow all inbound traffic" + vpc_id = "${var.vpc_id}" ingress { from_port = 0 @@ -13,7 +14,7 @@ resource "aws_security_group" "default" { from_port = 0 to_port = 0 protocol = "-1" - cidr_blocks = "0.0.0.0/0" + cidr_blocks = ["0.0.0.0/0"] } tags { diff --git a/examples/aws-rds/subnet-variables.tf b/examples/aws-rds/subnet-variables.tf index 00fe950df..07512d9ae 100644 --- a/examples/aws-rds/subnet-variables.tf +++ b/examples/aws-rds/subnet-variables.tf @@ -10,15 +10,14 @@ variable "subnet_2_cidr" { variable "az_1" { default = "us-east-1b" - description = "Your AZ" + description = "Your Az1, use AWS CLI to find your account specific" } variable "az_2" { default = "us-east-1c" - description = "Your AZ" + description = "Your Az2, use AWS CLI to find your account specific" } variable "vpc_id" { - default = "vpc-b6090dd3" description = "Your VPC ID" } \ No newline at end of file diff --git a/examples/aws-rds/variables.tf b/examples/aws-rds/variables.tf index 62f3432ec..af15eb857 100644 --- a/examples/aws-rds/variables.tf +++ b/examples/aws-rds/variables.tf @@ -9,17 +9,20 @@ variable "storage" { } variable "engine" { - default = "mysql" - description = "Engine type, supported values mysql" + default = "postgres" + description = "Engine type, example values mysql, postgres" } variable "engine_version" { - default = "5.6.17" description = "Engine version" + default = { + mysql = "5.6.22" + postgres = "9.4.1" + } } variable "instance_class" { - default = "db.t1.micro" + default = "db.t2.micro" description = "Instance class" } @@ -29,7 +32,7 @@ variable "db_name" { } variable "username" { - default = "user" + default = "myuser" description = "User name" }