Skip to content

Commit ab39f6a

Browse files
amitkarpejoe-nilandactions-bot
authored
Added Microsoft SQL Server example (#79)
Co-authored-by: Joe Niland <joe@originalmind.com.au> Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com>
1 parent b1e02e4 commit ab39f6a

4 files changed

Lines changed: 280 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
region = "us-east-2"
2+
3+
availability_zones = ["us-east-2a","us-east-2b"]
4+
5+
namespace = "eg"
6+
7+
stage = "test"
8+
9+
name = "rds-mssql"
10+
11+
deletion_protection = false
12+
13+
database_name = null
14+
15+
database_user = "admin"
16+
17+
database_password = "admin_password"
18+
19+
database_port = 1433
20+
21+
multi_az = false
22+
23+
storage_type = "standard"
24+
25+
storage_encrypted = false
26+
27+
allocated_storage = 20
28+
29+
# Microsoft SQL Server on Amazon RDS
30+
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html
31+
engine = "sqlserver-ex"
32+
33+
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.VersionSupport
34+
engine_version = "14.00.1000.169.v1"
35+
36+
#major_engine_version = "5.7"
37+
major_engine_version = "14.00.1000.169.v1"
38+
39+
instance_class = "db.t2.small"
40+
41+
#db_parameter_group = "mysql5.7"
42+
db_parameter_group = "sqlserver-ex-14.0"
43+
44+
publicly_accessible = false
45+
46+
apply_immediately = true

examples/mssql/main.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "vpc" {
6+
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.7.0"
7+
namespace = var.namespace
8+
stage = var.stage
9+
name = var.name
10+
cidr_block = "172.16.0.0/16"
11+
}
12+
13+
module "subnets" {
14+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.0"
15+
availability_zones = var.availability_zones
16+
namespace = var.namespace
17+
stage = var.stage
18+
name = var.name
19+
vpc_id = module.vpc.vpc_id
20+
igw_id = module.vpc.igw_id
21+
cidr_block = module.vpc.vpc_cidr_block
22+
nat_gateway_enabled = false
23+
nat_instance_enabled = false
24+
}
25+
26+
module "rds_instance" {
27+
source = "../../"
28+
namespace = var.namespace
29+
stage = var.stage
30+
name = var.name
31+
database_name = var.database_name
32+
database_user = var.database_user
33+
database_password = var.database_password
34+
database_port = var.database_port
35+
multi_az = var.multi_az
36+
storage_type = var.storage_type
37+
allocated_storage = var.allocated_storage
38+
storage_encrypted = var.storage_encrypted
39+
engine = var.engine
40+
engine_version = var.engine_version
41+
instance_class = var.instance_class
42+
db_parameter_group = var.db_parameter_group
43+
44+
publicly_accessible = var.publicly_accessible
45+
allowed_cidr_blocks = ["172.16.0.0/16"]
46+
vpc_id = module.vpc.vpc_id
47+
subnet_ids = module.subnets.private_subnet_ids
48+
security_group_ids = [module.vpc.vpc_default_security_group_id]
49+
apply_immediately = var.apply_immediately
50+
51+
}

examples/mssql/outputs.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
output "instance_id" {
2+
value = module.rds_instance.instance_id
3+
description = "ID of the instance"
4+
}
5+
6+
output "instance_address" {
7+
value = module.rds_instance.instance_address
8+
description = "Address of the instance"
9+
}
10+
11+
output "instance_endpoint" {
12+
value = module.rds_instance.instance_endpoint
13+
description = "DNS Endpoint of the instance"
14+
}
15+
16+
output "subnet_group_id" {
17+
value = module.rds_instance.subnet_group_id
18+
description = "ID of the Subnet Group"
19+
}
20+
21+
output "security_group_id" {
22+
value = module.rds_instance.security_group_id
23+
description = "ID of the Security Group"
24+
}
25+
26+
output "parameter_group_id" {
27+
value = module.rds_instance.parameter_group_id
28+
description = "ID of the Parameter Group"
29+
}
30+
31+
output "option_group_id" {
32+
value = module.rds_instance.option_group_id
33+
description = "ID of the Option Group"
34+
}
35+
36+
output "hostname" {
37+
value = module.rds_instance.hostname
38+
description = "DNS host name of the instance"
39+
}
40+
41+
output "public_subnet_cidrs" {
42+
value = module.subnets.public_subnet_cidrs
43+
}
44+
45+
output "private_subnet_cidrs" {
46+
value = module.subnets.private_subnet_cidrs
47+
}
48+
49+
output "vpc_cidr" {
50+
value = module.vpc.vpc_cidr_block
51+
}

examples/mssql/variables.tf

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
variable "region" {
2+
type = string
3+
description = "AWS region"
4+
}
5+
6+
variable "availability_zones" {
7+
type = list(string)
8+
}
9+
10+
variable "namespace" {
11+
type = string
12+
description = "Namespace (e.g. `eg` or `cp`)"
13+
}
14+
15+
variable "stage" {
16+
type = string
17+
description = "Stage (e.g. `prod`, `dev`, `staging`, `infra`)"
18+
}
19+
20+
variable "name" {
21+
type = string
22+
description = "Name (e.g. `app` or `cluster`)"
23+
}
24+
25+
variable "database_name" {
26+
type = string
27+
description = "The name of the database to create when the DB instance is created"
28+
}
29+
30+
variable "database_user" {
31+
type = string
32+
description = "Username for the master DB user"
33+
}
34+
35+
variable "database_password" {
36+
type = string
37+
description = "Password for the master DB user"
38+
}
39+
40+
variable "database_port" {
41+
type = number
42+
description = "Database port (_e.g._ `3306` for `MySQL`). Used in the DB Security Group to allow access to the DB instance from the provided `security_group_ids`"
43+
}
44+
45+
variable "deletion_protection" {
46+
type = bool
47+
description = "Set to true to enable deletion protection on the RDS instance"
48+
}
49+
50+
variable "multi_az" {
51+
type = bool
52+
description = "Set to true if multi AZ deployment must be supported"
53+
}
54+
55+
variable "storage_type" {
56+
type = string
57+
description = "One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD)"
58+
}
59+
60+
variable "storage_encrypted" {
61+
type = bool
62+
description = "(Optional) Specifies whether the DB instance is encrypted. The default is false if not specified"
63+
}
64+
65+
variable "allocated_storage" {
66+
type = number
67+
description = "The allocated storage in GBs"
68+
}
69+
70+
variable "engine" {
71+
type = string
72+
description = "Database engine type"
73+
# http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html
74+
# - mysql
75+
# - postgres
76+
# - oracle-*
77+
# - sqlserver-*
78+
}
79+
80+
variable "engine_version" {
81+
type = string
82+
description = "Database engine version, depends on engine type"
83+
# http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html
84+
}
85+
86+
variable "major_engine_version" {
87+
type = string
88+
description = "Database MAJOR engine version, depends on engine type"
89+
# https://docs.aws.amazon.com/cli/latest/reference/rds/create-option-group.html
90+
}
91+
92+
variable "instance_class" {
93+
type = string
94+
description = "Class of RDS instance"
95+
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html
96+
}
97+
98+
variable "db_parameter_group" {
99+
type = string
100+
description = "Parameter group, depends on DB engine used"
101+
# "mysql5.6"
102+
# "postgres9.5"
103+
}
104+
105+
variable "publicly_accessible" {
106+
type = bool
107+
description = "Determines if database can be publicly available (NOT recommended)"
108+
}
109+
110+
variable "apply_immediately" {
111+
type = bool
112+
description = "Specifies whether any database modifications are applied immediately, or during the next maintenance window"
113+
}
114+
115+
variable "subnet_ids" {
116+
description = "A list of VPC subnet IDs"
117+
default = []
118+
type = list(string)
119+
}
120+
121+
variable "security_group_ids" {
122+
description = "List of VPC security groups to associate"
123+
default = []
124+
type = list(string)
125+
}
126+
127+
variable "vpc_id" {
128+
type = string
129+
default = ""
130+
description = "VPC ID the DB instance will be created in"
131+
}
132+

0 commit comments

Comments
 (0)