-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrds_mysql.tf
106 lines (91 loc) · 2.35 KB
/
rds_mysql.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//RDS CONFIGURATIONS//
//fetching subnet group ids from vpc section//
data "aws_vpc" "vpc_available" {
filter {
name = "tag:Name"
values = ["myvpc"]
}
}
data "aws_subnet_ids" "available_db_subnet" {
vpc_id = data.aws_vpc.vpc_available.id
filter {
name = "tag:Name"
values = ["private-subnet*"]
}
}
data "aws_security_group" "mysg" {
filter {
name = "tag:Name"
values = ["mysg"]
}
}
//creation of db subnet group//
resource "aws_db_subnet_group" "db_sub_group" {
name = "db_sub_group"
subnet_ids = data.aws_subnet_ids.available_db_subnet.ids
tags = {
Name = "My DB subnet group"
}
}
//creation of db instance//
resource "aws_db_instance" "db_instance" {
engine = var.engine_name
name = var.db_name
username = var.user_name
password = var.pass
skip_final_snapshot = var.skip_finalSnapshot
db_subnet_group_name = aws_db_subnet_group.db_sub_group.id
delete_automated_backups = var.delete_automated_backup
multi_az = var.multi_az_deployment
publicly_accessible = var.public_access
vpc_security_group_ids = [data.aws_security_group.mysg.id]
instance_class = var.instance_class
allocated_storage = 20
}
//variable creation//
variable "engine_name" {
description = "Enter the DB engine"
type = string
default = "mysql"
}
variable "db_name" {
description = "Enter the name of the database to be created inside DB Instance"
type = string
default = "mydatabase"
}
variable "user_name" {
description = "Enter the username for DB"
type = string
default = "vijaydb"
}
variable "pass" {
description = "Enter the username for DB"
type = string
default = "Vijaygawate.1999"
}
variable "skip_finalSnapshot" {
type = bool
default = true
}
variable "delete_automated_backup" {
type = bool
default = true
}
variable "multi_az_deployment" {
description = "Enable or disable multi-az deployment"
type = bool
default = false
}
variable "public_access" {
description = "Whether public access needed"
type = bool
default = false
}
variable "instance_class" {
type = string
default = "db.t2.micro"
}
//output required//
output "rds_address" {
value = aws_db_instance.db_instance.address
}