Skip to content

Commit 5884803

Browse files
authored
chore: update example projects (#298)
1 parent 8bae97d commit 5884803

File tree

16 files changed

+654
-417
lines changed

16 files changed

+654
-417
lines changed

examples/complete-mssql/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Note that this example may create resources which cost money. Run `terraform des
3535
| Name | Source | Version |
3636
|------|--------|---------|
3737
| db | ../../ | |
38+
| security_group | terraform-aws-modules/security-group/aws | ~> 3 |
39+
| vpc | terraform-aws-modules/vpc/aws | ~> 2 |
3840

3941
## Resources
4042

@@ -44,9 +46,6 @@ Note that this example may create resources which cost money. Run `terraform des
4446
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
4547
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
4648
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |
47-
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) |
48-
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) |
49-
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) |
5049

5150
## Inputs
5251

examples/complete-mssql/main.tf

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,62 @@
11
provider "aws" {
2-
region = "us-east-1"
2+
region = local.region
33
}
44

55
locals {
6+
name = "complete-mssql"
7+
region = "eu-west-1"
68
tags = {
79
Owner = "user"
810
Environment = "dev"
911
}
1012
}
1113

12-
##############################################################
13-
# Data sources to get VPC, subnets and security group details
14-
##############################################################
15-
data "aws_vpc" "default" {
16-
default = true
17-
}
14+
################################################################################
15+
# Supporting Resources
16+
################################################################################
17+
18+
module "vpc" {
19+
source = "terraform-aws-modules/vpc/aws"
20+
version = "~> 2"
21+
22+
name = local.name
23+
cidr = "10.99.0.0/18"
24+
25+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
26+
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
27+
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
28+
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
1829

19-
data "aws_subnet_ids" "all" {
20-
vpc_id = data.aws_vpc.default.id
30+
create_database_subnet_group = true
31+
32+
tags = local.tags
2133
}
2234

23-
data "aws_security_group" "default" {
24-
vpc_id = data.aws_vpc.default.id
25-
name = "default"
35+
module "security_group" {
36+
source = "terraform-aws-modules/security-group/aws"
37+
version = "~> 3"
38+
39+
name = local.name
40+
description = "Complete SqlServer example security group"
41+
vpc_id = module.vpc.vpc_id
42+
43+
# ingress
44+
ingress_with_cidr_blocks = [
45+
{
46+
from_port = 1433
47+
to_port = 1433
48+
protocol = "tcp"
49+
description = "SqlServer access from within VPC"
50+
cidr_blocks = module.vpc.vpc_cidr_block
51+
},
52+
]
53+
54+
tags = local.tags
2655
}
2756

28-
#####################################
57+
################################################################################
2958
# IAM Role for Windows Authentication
30-
#####################################
59+
################################################################################
3160

3261
data "aws_iam_policy_document" "rds_assume_role" {
3362
statement {
@@ -58,9 +87,9 @@ resource "aws_iam_role_policy_attachment" "rds_directory_services" {
5887
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess"
5988
}
6089

61-
##########################################
90+
################################################################################
6291
# AWS Directory Service (Acitve Directory)
63-
##########################################
92+
################################################################################
6493

6594
resource "aws_directory_service_directory" "demo" {
6695
name = "corp.demo.com"
@@ -69,63 +98,61 @@ resource "aws_directory_service_directory" "demo" {
6998
type = "MicrosoftAD"
7099

71100
vpc_settings {
72-
vpc_id = data.aws_vpc.default.id
101+
vpc_id = module.vpc.vpc_id
73102
# Only 2 subnets, must be in different AZs
74-
subnet_ids = slice(tolist(data.aws_subnet_ids.all.ids), 0, 2)
103+
subnet_ids = slice(tolist(module.vpc.database_subnets), 0, 2)
75104
}
76105

77106
tags = local.tags
78107
}
79108

80-
#####
81-
# DB
82-
#####
109+
################################################################################
110+
# RDS Module
111+
################################################################################
83112

84113
module "db" {
85114
source = "../../"
86115

87-
identifier = "demodb"
116+
identifier = local.name
88117

89-
engine = "sqlserver-ex"
90-
engine_version = "14.00.1000.169.v1"
91-
instance_class = "db.t2.medium"
92-
allocated_storage = 20
93-
storage_encrypted = false
118+
engine = "sqlserver-ex"
119+
engine_version = "15.00.4073.23.v1"
120+
family = "sqlserver-ex-15.0" # DB parameter group
121+
major_engine_version = "15.00" # DB option group
122+
instance_class = "db.t3.large"
94123

95-
name = null # "demodb"
96-
username = "demouser"
124+
allocated_storage = 20
125+
max_allocated_storage = 100
126+
storage_encrypted = false
127+
128+
name = null
129+
username = "complete_mssql"
97130
password = "YourPwdShouldBeLongAndSecure!"
98-
port = "1433"
131+
port = 1433
99132

100133
domain = aws_directory_service_directory.demo.id
101134
domain_iam_role_name = aws_iam_role.rds_ad_auth.name
102135

103-
vpc_security_group_ids = [data.aws_security_group.default.id]
104-
105-
maintenance_window = "Mon:00:00-Mon:03:00"
106-
backup_window = "03:00-06:00"
136+
multi_az = false
137+
subnet_ids = module.vpc.database_subnets
138+
vpc_security_group_ids = [module.security_group.this_security_group_id]
107139

108-
# disable backups to create DB faster
109-
backup_retention_period = 0
110-
111-
tags = local.tags
140+
maintenance_window = "Mon:00:00-Mon:03:00"
141+
backup_window = "03:00-06:00"
142+
enabled_cloudwatch_logs_exports = ["error"]
112143

113-
# DB subnet group
114-
subnet_ids = data.aws_subnet_ids.all.ids
144+
backup_retention_period = 0
145+
final_snapshot_identifier = local.name
146+
deletion_protection = false
115147

116-
# Snapshot name upon DB deletion
117-
final_snapshot_identifier = "demodb"
148+
performance_insights_enabled = true
149+
performance_insights_retention_period = 7
150+
create_monitoring_role = true
118151

152+
options = []
119153
create_db_parameter_group = false
120154
license_model = "license-included"
155+
timezone = "GMT Standard Time"
121156

122-
timezone = "Central Standard Time"
123-
124-
# Database Deletion Protection
125-
deletion_protection = false
126-
127-
# DB options
128-
major_engine_version = "14.00"
129-
130-
options = []
157+
tags = local.tags
131158
}

examples/complete-mysql/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,19 @@ Note that this example may create resources which cost money. Run `terraform des
2626

2727
## Providers
2828

29-
| Name | Version |
30-
|------|---------|
31-
| aws | >= 2.49 |
29+
No provider.
3230

3331
## Modules
3432

3533
| Name | Source | Version |
3634
|------|--------|---------|
3735
| db | ../../ | |
36+
| security_group | terraform-aws-modules/security-group/aws | ~> 3 |
37+
| vpc | terraform-aws-modules/vpc/aws | ~> 2 |
3838

3939
## Resources
4040

41-
| Name |
42-
|------|
43-
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) |
44-
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) |
45-
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) |
41+
No resources.
4642

4743
## Inputs
4844

examples/complete-mysql/main.tf

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,99 @@
11
provider "aws" {
2-
region = "eu-west-1"
2+
region = local.region
33
}
44

5-
##############################################################
6-
# Data sources to get VPC, subnets and security group details
7-
##############################################################
8-
data "aws_vpc" "default" {
9-
default = true
5+
locals {
6+
name = "complete-mysql"
7+
region = "eu-west-1"
8+
tags = {
9+
Owner = "user"
10+
Environment = "dev"
11+
}
1012
}
1113

12-
data "aws_subnet_ids" "all" {
13-
vpc_id = data.aws_vpc.default.id
14-
}
14+
################################################################################
15+
# Supporting Resources
16+
################################################################################
1517

16-
data "aws_security_group" "default" {
17-
vpc_id = data.aws_vpc.default.id
18-
name = "default"
19-
}
18+
module "vpc" {
19+
source = "terraform-aws-modules/vpc/aws"
20+
version = "~> 2"
2021

21-
#####
22-
# DB
23-
#####
24-
module "db" {
25-
source = "../../"
22+
name = local.name
23+
cidr = "10.99.0.0/18"
2624

27-
identifier = "demodb"
25+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
26+
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
27+
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
28+
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
2829

29-
# All available versions: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html#MySQL.Concepts.VersionMgmt
30-
engine = "mysql"
31-
engine_version = "5.7.19"
32-
instance_class = "db.t2.large"
33-
allocated_storage = 5
34-
storage_encrypted = false
35-
36-
# kms_key_id = "arm:aws:kms:<region>:<account id>:key/<kms key id>"
37-
name = "demodb"
38-
username = "user"
39-
password = "YourPwdShouldBeLongAndSecure!"
40-
port = "3306"
30+
create_database_subnet_group = true
31+
32+
tags = local.tags
33+
}
4134

42-
vpc_security_group_ids = [data.aws_security_group.default.id]
35+
module "security_group" {
36+
source = "terraform-aws-modules/security-group/aws"
37+
version = "~> 3"
4338

44-
maintenance_window = "Mon:00:00-Mon:03:00"
45-
backup_window = "03:00-06:00"
39+
name = local.name
40+
description = "Complete MySQL example security group"
41+
vpc_id = module.vpc.vpc_id
4642

47-
multi_az = true
43+
# ingress
44+
ingress_with_cidr_blocks = [
45+
{
46+
from_port = 3306
47+
to_port = 3306
48+
protocol = "tcp"
49+
description = "MySQL access from within VPC"
50+
cidr_blocks = module.vpc.vpc_cidr_block
51+
},
52+
]
4853

49-
# disable backups to create DB faster
50-
backup_retention_period = 0
54+
tags = local.tags
55+
}
5156

52-
tags = {
53-
Owner = "user"
54-
Environment = "dev"
55-
}
57+
################################################################################
58+
# RDS Module
59+
################################################################################
5660

57-
enabled_cloudwatch_logs_exports = ["audit", "general"]
61+
module "db" {
62+
source = "../../"
5863

59-
# DB subnet group
60-
subnet_ids = data.aws_subnet_ids.all.ids
64+
identifier = local.name
6165

62-
# DB parameter group
63-
family = "mysql5.7"
66+
# All available versions: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html#MySQL.Concepts.VersionMgmt
67+
engine = "mysql"
68+
engine_version = "8.0.20"
69+
family = "mysql8.0" # DB parameter group
70+
major_engine_version = "8.0" # DB option group
71+
instance_class = "db.t3.large"
72+
73+
allocated_storage = 20
74+
max_allocated_storage = 100
75+
storage_encrypted = false
76+
77+
name = "completeMysql"
78+
username = "complete_mysql"
79+
password = "YourPwdShouldBeLongAndSecure!"
80+
port = 3306
81+
82+
multi_az = true
83+
subnet_ids = module.vpc.database_subnets
84+
vpc_security_group_ids = [module.security_group.this_security_group_id]
6485

65-
# DB option group
66-
major_engine_version = "5.7"
86+
maintenance_window = "Mon:00:00-Mon:03:00"
87+
backup_window = "03:00-06:00"
88+
enabled_cloudwatch_logs_exports = ["general"]
6789

68-
# Snapshot name upon DB deletion
69-
final_snapshot_identifier = "demodb"
90+
backup_retention_period = 0
91+
final_snapshot_identifier = local.name
92+
deletion_protection = false
7093

71-
# Database Deletion Protection
72-
deletion_protection = false
94+
performance_insights_enabled = true
95+
performance_insights_retention_period = 7
96+
create_monitoring_role = true
7397

7498
parameters = [
7599
{
@@ -98,4 +122,6 @@ module "db" {
98122
]
99123
},
100124
]
125+
126+
tags = local.tags
101127
}

0 commit comments

Comments
 (0)