Skip to content

Commit 3e6e7dd

Browse files
committed
Added code for RDS modules
1 parent 3d4a26f commit 3e6e7dd

File tree

18 files changed

+858
-2
lines changed

18 files changed

+858
-2
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.terraform
2+
terraform.tfstate
3+
*.tfstate*
4+
terraform.tfvars

LICENSE

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Licensed under the Apache License, Version 2.0 (the "License");
2+
you may not use this file except in compliance with the License.
3+
You may obtain a copy of the License at
4+
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.

README.md

+79-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
1-
# terraform-aws-rds
2-
Terraform module which creates RDS instance on AWS
1+
AWS RDS Terraform module
2+
========================
3+
4+
Terraform module which creates RDS resources on AWS.
5+
6+
These types of resources are supported:
7+
8+
* [DB Instance](https://www.terraform.io/docs/providers/aws/r/db_instance.html)
9+
* [DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
10+
* [DB Parameter Group](https://www.terraform.io/docs/providers/aws/r/db_parameter_group.html)
11+
12+
Root module calls these modules which can also be used separately to create independent resources:
13+
14+
* [db_instance](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_instance) - creates RDS DB instance
15+
* [db_subnet_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_subnet_group) - creates RDS DB subnet group
16+
* [db_parameter_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_parameter_group) - creates RDS DB group
17+
18+
Usage
19+
-----
20+
21+
```hcl
22+
module "db" {
23+
source = "terraform-aws-modules/rds/aws"
24+
25+
identifier = "demodb"
26+
27+
engine = "mysql"
28+
engine_version = "5.7.11"
29+
instance_class = "db.t2.large"
30+
allocated_storage = 5
31+
32+
name = "demodb"
33+
username = "user"
34+
password = "YourPwdShouldBeLongAndSecure!"
35+
port = "3306"
36+
37+
vpc_security_group_ids = ["sg-12345678"]
38+
39+
maintenance_window = "Mon:00:00-Mon:03:00"
40+
backup_window = "03:00-06:00"
41+
42+
tags = {
43+
Owner = "user"
44+
Environment = "dev"
45+
}
46+
47+
# DB subnet group
48+
subnet_ids = ["subnet-12345678", "subnet-87654321"]
49+
50+
# DB parameter group
51+
family = "mysql5.7"
52+
}
53+
```
54+
55+
Examples
56+
--------
57+
58+
* [Complete RDS example](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/complete)
59+
60+
Limitations
61+
-----------
62+
63+
* [module db_parameter_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_parameter_group) does not implement setting of parameters
64+
65+
Notes
66+
-----
67+
68+
1. This module does not create RDS security group. Use [terraform-aws-sg](https://github.com/terraform-aws-modules/terraform-aws-sg) module for this.
69+
70+
Authors
71+
-------
72+
73+
Migrated from `terraform-community-modules/tf_aws_rds`, where it was maintained by [these awesome contributors](https://github.com/terraform-community-modules/tf_aws_rds/graphs/contributors).
74+
Module managed by [Anton Babenko](https://github.com/antonbabenko).
75+
76+
License
77+
-------
78+
79+
Apache 2 Licensed. See LICENSE for full details.

examples/complete/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Complete RDS example
2+
====================
3+
4+
Configuration in this directory creates set of RDS resources including DB instance, DB subnet group and DB parameter group.
5+
6+
Data sources are used to discover existing VPC resources (VPC, subnet and security group).
7+
8+
Usage
9+
=====
10+
11+
To run this example you need to execute:
12+
13+
```bash
14+
$ terraform init
15+
$ terraform plan
16+
$ terraform apply
17+
```
18+
19+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

examples/complete/main.tf

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
##############################################################
6+
# Data sources to get VPC, subnets and security group details
7+
##############################################################
8+
data "aws_vpc" "default" {
9+
default = true
10+
}
11+
12+
data "aws_subnet_ids" "all" {
13+
vpc_id = "${data.aws_vpc.default.id}"
14+
}
15+
16+
data "aws_security_group" "default" {
17+
vpc_id = "${data.aws_vpc.default.id}"
18+
name = "default"
19+
}
20+
21+
#####
22+
# DB
23+
#####
24+
module "db" {
25+
source = "../../"
26+
27+
identifier = "demodb"
28+
29+
engine = "mysql"
30+
engine_version = "5.7.11"
31+
instance_class = "db.t2.large"
32+
allocated_storage = 5
33+
34+
name = "demodb"
35+
username = "user"
36+
password = "YourPwdShouldBeLongAndSecure!"
37+
port = "3306"
38+
39+
vpc_security_group_ids = ["${data.aws_security_group.default.id}"]
40+
41+
maintenance_window = "Mon:00:00-Mon:03:00"
42+
backup_window = "03:00-06:00"
43+
backup_retention_period = 0 // disable backups to create DB faster
44+
45+
tags = {
46+
Owner = "user"
47+
Environment = "dev"
48+
}
49+
50+
# DB subnet group
51+
subnet_ids = ["${data.aws_subnet_ids.all.ids}"]
52+
53+
# DB parameter group
54+
family = "mysql5.7"
55+
}

examples/complete/outputs.tf

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# DB instance
2+
output "this_db_instance_address" {
3+
description = "The address of the RDS instance"
4+
value = "${module.db.this_db_instance_address}"
5+
}
6+
7+
output "this_db_instance_arn" {
8+
description = "The ARN of the RDS instance"
9+
value = "${module.db.this_db_instance_arn}"
10+
}
11+
12+
output "this_db_instance_availability_zone" {
13+
description = "The availability zone of the RDS instance"
14+
value = "${module.db.this_db_instance_availability_zone}"
15+
}
16+
17+
output "this_db_instance_endpoint" {
18+
description = "The connection endpoint"
19+
value = "${module.db.this_db_instance_endpoint}"
20+
}
21+
22+
output "this_db_instance_hosted_zone_id" {
23+
description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)"
24+
value = "${module.db.this_db_instance_hosted_zone_id}"
25+
}
26+
27+
output "this_db_instance_id" {
28+
description = "The RDS instance ID"
29+
value = "${module.db.this_db_instance_id}"
30+
}
31+
32+
output "this_db_instance_resource_id" {
33+
description = "The RDS Resource ID of this instance"
34+
value = "${module.db.this_db_instance_resource_id}"
35+
}
36+
37+
output "this_db_instance_status" {
38+
description = "The RDS instance status"
39+
value = "${module.db.this_db_instance_status}"
40+
}
41+
42+
output "this_db_instance_name" {
43+
description = "The database name"
44+
value = "${module.db.this_db_instance_name}"
45+
}
46+
47+
output "this_db_instance_username" {
48+
description = "The master username for the database"
49+
value = "${module.db.this_db_instance_username}"
50+
}
51+
52+
output "this_db_instance_password" {
53+
description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)"
54+
value = "${module.db.this_db_instance_password}"
55+
}
56+
57+
output "this_db_instance_port" {
58+
description = "The database port"
59+
value = "${module.db.this_db_instance_port}"
60+
}
61+
62+
# DB subnet group
63+
output "this_db_subnet_group_id" {
64+
description = "The db subnet group name"
65+
value = "${module.db.this_db_subnet_group_id}"
66+
}
67+
68+
output "this_db_subnet_group_arn" {
69+
description = "The ARN of the db subnet group"
70+
value = "${module.db.this_db_subnet_group_arn}"
71+
}
72+
73+
# DB parameter group
74+
output "this_db_parameter_group_id" {
75+
description = "The db parameter group id"
76+
value = "${module.db.this_db_parameter_group_id}"
77+
}
78+
79+
output "this_db_parameter_group_arn" {
80+
description = "The ARN of the db parameter group"
81+
value = "${module.db.this_db_parameter_group_arn}"
82+
}

main.tf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
##################
2+
# DB subnet group
3+
##################
4+
module "db_subnet_group" {
5+
source = "./modules/db_subnet_group"
6+
7+
identifier = "${var.identifier}"
8+
name_prefix = "${var.identifier}-"
9+
subnet_ids = ["${var.subnet_ids}"]
10+
11+
tags = "${var.tags}"
12+
}
13+
14+
##################################################
15+
# DB subnet group with all subnets in default VPC
16+
##################################################
17+
module "db_parameter_group" {
18+
source = "./modules/db_parameter_group"
19+
20+
identifier = "${var.identifier}"
21+
name_prefix = "${var.identifier}-"
22+
family = "${var.family}"
23+
24+
// parameter = ["${var.parameters}"]
25+
26+
tags = "${var.tags}"
27+
}
28+
29+
##############
30+
# DB instance
31+
##############
32+
module "db_instance" {
33+
source = "./modules/db_instance"
34+
35+
identifier = "${var.identifier}"
36+
37+
engine = "${var.engine}"
38+
engine_version = "${var.engine_version}"
39+
instance_class = "${var.instance_class}"
40+
allocated_storage = "${var.allocated_storage}"
41+
storage_type = "${var.storage_type}"
42+
43+
name = "${var.name}"
44+
username = "${var.username}"
45+
password = "${var.password}"
46+
port = "${var.port}"
47+
48+
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
49+
db_subnet_group_name = "${module.db_subnet_group.this_db_subnet_group_id}"
50+
parameter_group_name = "${module.db_parameter_group.this_db_parameter_group_id}"
51+
52+
multi_az = "${var.multi_az}"
53+
iops = "${var.iops}"
54+
publicly_accessible = "${var.publicly_accessible}"
55+
56+
allow_major_version_upgrade = "${var.allow_major_version_upgrade}"
57+
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}"
58+
apply_immediately = "${var.apply_immediately}"
59+
maintenance_window = "${var.maintenance_window}"
60+
skip_final_snapshot = "${var.skip_final_snapshot}"
61+
copy_tags_to_snapshot = "${var.copy_tags_to_snapshot}"
62+
63+
backup_retention_period = "${var.backup_retention_period}"
64+
backup_window = "${var.backup_window}"
65+
66+
tags = "${var.tags}"
67+
}

modules/db_instance/main.tf

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
##############
2+
# DB instance
3+
##############
4+
resource "aws_db_instance" "this" {
5+
identifier = "${var.identifier}"
6+
7+
engine = "${var.engine}"
8+
engine_version = "${var.engine_version}"
9+
instance_class = "${var.instance_class}"
10+
allocated_storage = "${var.allocated_storage}"
11+
storage_type = "${var.storage_type}"
12+
13+
name = "${var.name}"
14+
username = "${var.username}"
15+
password = "${var.password}"
16+
port = "${var.port}"
17+
18+
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
19+
db_subnet_group_name = "${var.db_subnet_group_name}"
20+
parameter_group_name = "${var.parameter_group_name}"
21+
22+
multi_az = "${var.multi_az}"
23+
iops = "${var.iops}"
24+
publicly_accessible = "${var.publicly_accessible}"
25+
26+
allow_major_version_upgrade = "${var.allow_major_version_upgrade}"
27+
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}"
28+
apply_immediately = "${var.apply_immediately}"
29+
maintenance_window = "${var.maintenance_window}"
30+
skip_final_snapshot = "${var.skip_final_snapshot}"
31+
copy_tags_to_snapshot = "${var.copy_tags_to_snapshot}"
32+
33+
backup_retention_period = "${var.backup_retention_period}"
34+
backup_window = "${var.backup_window}"
35+
36+
tags = "${merge(var.tags, map("Name", format("%s", var.identifier)))}"
37+
}

0 commit comments

Comments
 (0)