Added postgres option

This commit is contained in:
Sathiya Shunmugasundaram 2015-06-09 12:37:22 -04:00
parent 9b6c0431f9
commit 074f1ed625
7 changed files with 40 additions and 17 deletions

View File

@ -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'

View File

@ -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}"]
}

View File

@ -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}"
}

View File

@ -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"
}

View File

@ -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 {

View File

@ -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"
}

View File

@ -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"
}