This repository was archived by the owner on Jul 11, 2023. It is now read-only.
File tree 5 files changed +126
-0
lines changed
5 files changed +126
-0
lines changed Original file line number Diff line number Diff line change
1
+ # RDS
2
+
3
+ Setup basic DB instance and subnet group resources for using RDS.
4
+
5
+ Checkout example/rds-test for usage.
Original file line number Diff line number Diff line change
1
+ resource "aws_iam_role" "rds_enhanced_monitoring" {
2
+ name_prefix = var. name_prefix
3
+ assume_role_policy = data. aws_iam_policy_document . rds_enhanced_monitoring . json
4
+ }
5
+
6
+ resource "aws_iam_role_policy_attachment" "rds_enhanced_monitoring" {
7
+ role = aws_iam_role. rds_enhanced_monitoring . name
8
+ policy_arn = " arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
9
+ }
10
+
11
+ data "aws_iam_policy_document" "rds_enhanced_monitoring" {
12
+ statement {
13
+ actions = [" sts:AssumeRole" ]
14
+ principals {
15
+ type = " Service"
16
+ identifiers = [" monitoring.rds.amazonaws.com" ]
17
+ }
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ resource "aws_db_subnet_group" "rds_private_subnet" {
2
+ subnet_ids = var. subnet_ids
3
+ }
4
+
5
+ resource "aws_db_instance" "default" {
6
+ identifier_prefix = var. name_prefix
7
+ allocated_storage = var. db_storage_size
8
+ storage_type = var. db_storage_type
9
+ engine = var. db_engine
10
+ engine_version = var. engine_version
11
+ instance_class = var. db_instance_type
12
+ db_subnet_group_name = aws_db_subnet_group. rds_private_subnet . name
13
+ multi_az = var. multi_az
14
+ backup_retention_period = var. backup_retention_period
15
+ monitoring_interval = var. monitoring_interval
16
+ monitoring_role_arn = aws_iam_role. rds_enhanced_monitoring . arn
17
+ vpc_security_group_ids = [var . security_group_id ]
18
+ name = var. db_name
19
+ username = var. db_username
20
+ password = var. db_password
21
+ tags = var. tags
22
+ }
Original file line number Diff line number Diff line change
1
+ output "endpoint" {
2
+ value = aws_db_instance. default . endpoint
3
+ }
4
+
5
+ output "db_id" {
6
+ value = aws_db_instance. default . id
7
+ }
Original file line number Diff line number Diff line change
1
+ variable "subnet_ids" {
2
+ type = list (string )
3
+ description = " Subnets (should be private) to host RDS instances."
4
+ }
5
+
6
+ variable "name_prefix" {
7
+ type = string
8
+ }
9
+
10
+ variable "db_storage_size" {
11
+ type = number
12
+ description = " The allocated storage in gibibytes."
13
+ }
14
+
15
+ variable "db_storage_type" {
16
+ type = string
17
+ description = " One of \" standard\" (magnetic), \" gp2\" (general purpose SSD), or \" io1\" (provisioned IOPS SSD)."
18
+ }
19
+
20
+ variable "db_engine" {
21
+ type = string
22
+ description = " The database engine to use."
23
+ }
24
+
25
+ variable "db_instance_type" {
26
+ type = string
27
+ description = " The instance type of the RDS instance."
28
+ }
29
+
30
+ variable "security_group_id" {
31
+ type = string
32
+ description = " The security group grants the access to database."
33
+ }
34
+
35
+ variable "db_name" {
36
+ type = string
37
+ description = " The name of the database to create when the DB instance is created."
38
+ }
39
+
40
+ variable "db_username" {
41
+ type = string
42
+ description = " Username for the master DB user."
43
+ }
44
+
45
+ variable "db_password" {
46
+ type = string
47
+ description = " Password for the master DB user."
48
+ }
49
+
50
+ variable "tags" {
51
+ type = map (string )
52
+ default = {}
53
+ }
54
+
55
+ variable "engine_version" {
56
+ type = string
57
+ description = " The engine version to use."
58
+ }
59
+
60
+ variable "backup_retention_period" {
61
+ description = " The days to retain backups for."
62
+ default = 7
63
+ }
64
+
65
+ variable "monitoring_interval" {
66
+ description = " The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance."
67
+ default = 30
68
+ }
69
+
70
+ variable "multi_az" {
71
+ description = " Specifies if the RDS instance is multi-AZ"
72
+ default = true
73
+ }
You can’t perform that action at this time.
0 commit comments