Even though an RDS instance supposedly can be set up as single-AZ,
it requires to be related to a DB Subnet Group resource, which in turn
requires at least 2 subnets from different AZs.
So, when enabling 'use_rds' this code creates a new subnet on a different
AZ from the one that private_subnet is in.
It also supports specifying a custom additional subnet id.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>
private_subnet_id = one(aws_subnet.private_subnet[*]) != null ? one(aws_subnet.private_subnet[*]).id : var.private_subnet_id
public_subnet_id = one(aws_subnet.public_subnet[*]) != null ? one(aws_subnet.public_subnet[*]).id : var.public_subnet_id
private_subnet_id = one(aws_subnet.private_subnet[*]) != null ? one(aws_subnet.private_subnet[*]).id : var.private_subnet_id
public_subnet_id = one(aws_subnet.public_subnet[*]) != null ? one(aws_subnet.public_subnet[*]).id : var.public_subnet_id
+ additional_rds_subnet_id = one(aws_subnet.additional_rds_subnet[*]) != null ? one(aws_subnet.additional_rds_subnet[*]).id : var.additional_rds_subnet_id
public_hosts = var.private_only ? [] : var.user_facing_hosts
private_hosts = concat(
public_hosts = var.private_only ? [] : var.user_facing_hosts
private_hosts = concat(
+#
+# Additional subnet on a different AZ is required if RDS is enabled
+#
+resource "aws_subnet" "additional_rds_subnet" {
+ count = (var.additional_rds_subnet_id == "" && local.use_rds) ? 1 : 0
+ vpc_id = local.arvados_vpc_id
+ availability_zone = data.aws_availability_zones.available.names[1]
+ cidr_block = "10.1.3.0/24"
+
+ lifecycle {
+ precondition {
+ condition = (var.vpc_id == "")
+ error_message = "additional_rds_subnet_id should be set if vpc_id is also set"
+ }
+ }
+}
+
value = local.arvados_sg_id
}
value = local.arvados_sg_id
}
+output "additional_rds_subnet_id" {
+ value = local.use_rds ? local.additional_rds_subnet_id : ""
+}
+
output "eip_id" {
value = { for k, v in aws_eip.arvados_eip: k => v.id }
}
output "eip_id" {
value = { for k, v in aws_eip.arvados_eip: k => v.id }
}
output "custom_tags" {
value = var.custom_tags
}
output "custom_tags" {
value = var.custom_tags
}
+
+output "use_rds" {
+ value = var.use_rds
+}
# Optional networking options. Set existing resources to be used instead of
# creating new ones.
# NOTE: We only support fully managed or fully custom networking, not a mix of both.
# Optional networking options. Set existing resources to be used instead of
# creating new ones.
# NOTE: We only support fully managed or fully custom networking, not a mix of both.
# vpc_id = "vpc-aaaa"
# sg_id = "sg-bbbb"
# public_subnet_id = "subnet-cccc"
# private_subnet_id = "subnet-dddd"
# vpc_id = "vpc-aaaa"
# sg_id = "sg-bbbb"
# public_subnet_id = "subnet-cccc"
# private_subnet_id = "subnet-dddd"
+#
+# RDS related parameters:
+# use_rds = true
+# additional_rds_subnet_id = "subnet-eeee"
# Optional custom tags to add to every resource. Default: {}
# custom_tags = {
# Optional custom tags to add to every resource. Default: {}
# custom_tags = {
+variable "additional_rds_subnet_id" {
+ description = "Use existing subnet for RDS instead of creating one for the cluster"
+ type = string
+ default = ""
+}
+
variable "private_subnet_id" {
description = "Use existing private subnet instead of creating one for the cluster"
type = string
variable "private_subnet_id" {
description = "Use existing private subnet instead of creating one for the cluster"
type = string
description = "Apply customized tags to every resource on the cluster"
type = map(string)
default = {}
description = "Apply customized tags to every resource on the cluster"
type = map(string)
default = {}
+}
+
+variable "use_rds" {
+ description = "Enable this to create an RDS instance as the cluster's database service"
+ type = bool
+ default = false
}
\ No newline at end of file
}
\ No newline at end of file