Skip to content

Commit

Permalink
Merge pull request #53 from DNXLabs/feature/new_private_and_public_su…
Browse files Browse the repository at this point in the history
…bnetgroup

Adding creation of db Subnet Groups
  • Loading branch information
alandavid authored Jul 29, 2024
2 parents 9fbda14 + bcd4387 commit 540956b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 15 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module "network" {
| attachInternetGateway | To attach or not the internet gateway within the public subnet. | `bool` | `true` | no |
| byoip | Enable module to use your own Elastic IPs (Bring Your Own IP) | `bool` | `false` | no |
| cf\_export\_name | Name prefix for the export resources of the cloud formation output | `string` | `""` | no |
| create\_dbsubgroup\_private | Create Private Subgroup | `bool` | `false` | no |
| create\_dbsubgroup\_public | Create Public Subgroup | `bool` | `false` | no |
| create\_dbsubgroup\_secure | Create Secure Subgroup | `bool` | `true` | no |
| eip\_allocation\_ids | User-specified primary or secondary private IP address to associate with the Elastic IP address | `list(string)` | `[]` | no |
| enable\_firewall\_default\_rule | Enable or disable the default stateful rule. | `bool` | `true` | no |
| firewall\_custom\_rule\_arn | The stateful rule group arn created outside the module | `list(string)` | `[]` | no |
Expand Down Expand Up @@ -112,7 +115,9 @@ module "network" {
| Name | Description |
|------|-------------|
| cidr\_block | CIDR for VPC created |
| db\_subnet\_group\_id | n/a |
| db\_subnet\_group\_private\_id | n/a |
| db\_subnet\_group\_public\_id | n/a |
| db\_subnet\_group\_secure\_id | n/a |
| firewall\_subnet\_cidrs | List of firewall subnet CIDRs |
| firewall\_subnet\_ids | List of firewall subnet IDs |
| internet\_gateway\_id | ID of Internet Gateway created |
Expand Down
12 changes: 10 additions & 2 deletions _outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ output "nat_gateway_ids" {
description = "List of NAT Gateway IDs"
}

output "db_subnet_group_id" {
value = aws_db_subnet_group.secure.id
output "db_subnet_group_secure_id" {
value = aws_db_subnet_group.secure[0].id
}

output "db_subnet_group_private_id" {
value = aws_db_subnet_group.private[0].id
}

output "db_subnet_group_public_id" {
value = aws_db_subnet_group.public[0].id
}

output "public_route_table_id" {
Expand Down
18 changes: 18 additions & 0 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ variable "enable_firewall_default_rule" {
description = "Enable or disable the default stateful rule."
}

variable "create_dbsubgroup_secure" {
type = bool
default = true
description = "Create Secure Subgroup"
}

variable "create_dbsubgroup_public" {
type = bool
default = false
description = "Create Public Subgroup"
}

variable "create_dbsubgroup_private" {
type = bool
default = false
description = "Create Private Subgroup"
}

locals {
kubernetes_clusters = zipmap(
formatlist("kubernetes.io/cluster/%s", var.kubernetes_clusters),
Expand Down
20 changes: 11 additions & 9 deletions cf-exports.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ resource "aws_cloudformation_stack" "tf_exports" {
"VpcId" = aws_vpc.default.id,
"CidrBlock" = aws_vpc.default.cidr_block,
"InternetGatewayId" = aws_internet_gateway.default.id,
"PublicSubnetIds" = join(",", aws_subnet.public[*].id),
"PublicSubnetCidrs" = join(",", aws_subnet.public[*].cidr_block),
"PrivateSubnetIds" = join(",", aws_subnet.private[*].id),
"PrivateSubnetCidrs" = join(",", aws_subnet.private[*].cidr_block),
"SecureSubnetIds" = join(",", aws_subnet.secure[*].id),
"SecureSubnetCidrs" = join(",", aws_subnet.secure[*].cidr_block),
"NatGatewayIds" = var.nat ? join(",", aws_nat_gateway.nat_gw[*].id) : "undefined",
"DbSubnetGroupId" = aws_db_subnet_group.secure.id
"PublicSubnetIds" = join(",", aws_subnet.public.*.id),

Check warning on line 9 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 9 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 9 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"PublicSubnetCidrs" = join(",", aws_subnet.public.*.cidr_block),

Check warning on line 10 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 10 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 10 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"PrivateSubnetIds" = join(",", aws_subnet.private.*.id),

Check warning on line 11 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 11 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 11 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"PrivateSubnetCidrs" = join(",", aws_subnet.private.*.cidr_block),

Check warning on line 12 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 12 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 12 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"SecureSubnetIds" = join(",", aws_subnet.secure.*.id),

Check warning on line 13 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 13 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 13 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"SecureSubnetCidrs" = join(",", aws_subnet.secure.*.cidr_block),

Check warning on line 14 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 14 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 14 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"NatGatewayIds" = var.nat ? join(",", aws_nat_gateway.nat_gw.*.id) : "undefined",

Check warning on line 15 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 15 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 15 in cf-exports.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets
"DbSubnetGroupId" = aws_db_subnet_group.secure[0].id,
"DbSubnetPrivateGroupId" = try(aws_db_subnet_group.private[0].id,"")
"DbSubnetPublicGroupId" = try(aws_db_subnet_group.public[0].id,"")
}
})
}
}
38 changes: 35 additions & 3 deletions db-subnet.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
resource "aws_db_subnet_group" "secure" {
name = lower(format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix))
subnet_ids = aws_subnet.secure[*].id
count = var.create_dbsubgroup_secure ? 1 : 0
name = lower("${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-secure")
subnet_ids = aws_subnet.secure.*.id

Check warning on line 4 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 4 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 4 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)
"Name" = "${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-secure"
"Scheme" = "secure"
"EnvName" = var.name
},
)
}

resource "aws_db_subnet_group" "private" {
count = var.create_dbsubgroup_private ? 1 : 0
name = lower("${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-private")
subnet_ids = aws_subnet.private.*.id

Check warning on line 19 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 19 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 19 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

tags = merge(
var.tags,
{
"Name" = "${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-private"
"Scheme" = "private"
"EnvName" = var.name
},
)
}

resource "aws_db_subnet_group" "public" {
count = var.create_dbsubgroup_public ? 1 : 0
name = lower("${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-public")
subnet_ids = aws_subnet.public.*.id

Check warning on line 34 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 34 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

Check warning on line 34 in db-subnet.tf

View workflow job for this annotation

GitHub Actions / Lint

List items should be accessed using square brackets

tags = merge(
var.tags,
{
"Name" = "${format(local.names[var.name_pattern].db_subnet, var.name, local.name_suffix)}-public"
"Scheme" = "public"
"EnvName" = var.name
},
)
}

0 comments on commit 540956b

Please sign in to comment.