forked from azeezsalu/terraform-tutorial-reference-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds-refference.tf
111 lines (90 loc) · 2.33 KB
/
rds-refference.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
107
108
109
110
111
# configured aws provider with proper credentials
provider "aws" {
region =
profile =
}
# create default vpc if one does not exit
resource "aws_default_vpc" "default_vpc" {
tags = {
Name = "default vpc"
}
}
# use data source to get all avalablility zones in region
data "aws_availability_zones" "available_zones" {}
# create a default subnet in the first az if one does not exit
resource "aws_default_subnet" "subnet_az1" {
availability_zone =
}
# create a default subnet in the second az if one does not exit
resource "aws_default_subnet" "subnet_az2" {
availability_zone =
}
# create security group for the web server
resource "aws_security_group" "webserver_security_group" {
name = "webserver security group"
description = "enable http access on port 80"
vpc_id =
ingress {
description = "http access"
from_port =
to_port =
protocol =
cidr_blocks =
}
egress {
from_port =
to_port =
protocol =
cidr_blocks =
}
tags = {
Name =
}
}
# create security group for the database
resource "aws_security_group" "database_security_group" {
name = "database security group"
description = "enable mysql/aurora access on port 3306"
vpc_id =
ingress {
description = "mysql/aurora access"
from_port =
to_port =
protocol =
security_groups =
}
egress {
from_port =
to_port =
protocol =
cidr_blocks =
}
tags = {
Name =
}
}
# create the subnet group for the rds instance
resource "aws_db_subnet_group" "database_subnet_group" {
name =
subnet_ids =
description =
tags = {
Name =
}
}
# create the rds instance
resource "aws_db_instance" "db_instance" {
engine =
engine_version =
multi_az =
identifier =
username =
password =
instance_class =
allocated_storage =
db_subnet_group_name =
vpc_security_group_ids =
availability_zone =
db_name =
skip_final_snapshot =
}