Skip to content

Commit

Permalink
Update custom VPC config to accept a list of private and public subne…
Browse files Browse the repository at this point in the history
…ts (#339)
  • Loading branch information
dkatzz authored Jul 5, 2024
1 parent cae3db5 commit 903e103
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
14 changes: 10 additions & 4 deletions cloud/aws/templates/aws_oidc/external_vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ data "aws_db_subnet_group" "external" {
name = var.external_vpc_database_subnet_group_name
}

data "aws_subnet" "external_private" {
data "aws_subnets" "external_private_subnets" {
count = local.enable_managed_vpc ? 0 : 1
id = var.external_vpc_private_subnet_id
filter {
name = "subnet-id"
values = var.external_vpc_private_subnet_ids
}
}

data "aws_subnet" "external_public" {
data "aws_subnets" "external_public_subnets" {
count = local.enable_managed_vpc ? 0 : 1
id = var.external_vpc_public_subnet_id
filter {
name = "subnet-id"
values = var.external_vpc_public_subnet_ids
}
}
10 changes: 6 additions & 4 deletions cloud/aws/templates/aws_oidc/variable_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,19 @@
"tfvar": true,
"type": "string"
},
"EXTERNAL_VPC_PRIVATE_SUBNET_ID": {
"EXTERNAL_VPC_PRIVATE_SUBNET_IDS": {
"required": false,
"secret": false,
"tfvar": true,
"type": "string"
"type": "list",
"list_type": "string"
},
"EXTERNAL_VPC_PUBLIC_SUBNET_ID": {
"EXTERNAL_VPC_PUBLIC_SUBNET_IDS": {
"required": false,
"secret": false,
"tfvar": true,
"type": "string"
"type": "list",
"list_type": "string"
},
"APPLY_DATABASE_CHANGES_IMMEDIATELY": {
"required": false,
Expand Down
12 changes: 6 additions & 6 deletions cloud/aws/templates/aws_oidc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,14 @@ variable "external_vpc_id" {
default = ""
}

variable "external_vpc_private_subnet_id" {
type = string
variable "external_vpc_private_subnet_ids" {
type = list(string)
description = "The externally managed VPC's private subnet ID."
default = ""
default = []
}

variable "external_vpc_public_subnet_id" {
type = string
variable "external_vpc_public_subnet_ids" {
type = list(string)
description = "The externally managed VPC's public subnet ID."
default = ""
default = []
}
8 changes: 4 additions & 4 deletions cloud/aws/templates/aws_oidc/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ locals {
enable_managed_vpc = anytrue([
var.external_vpc_database_subnet_group_name == "",
var.external_vpc_id == "",
var.external_vpc_private_subnet_id == "",
var.external_vpc_public_subnet_id == "",
length(var.external_vpc_private_subnet_ids) > 0,
length(var.external_vpc_public_subnet_ids) > 0,
])
}

locals {
vpc_id = local.enable_managed_vpc ? module.vpc[0].vpc_id : data.aws_vpc.external[0].id
vpc_private_subnets = local.enable_managed_vpc ? module.vpc[0].private_subnets : data.aws_subnet.external_private[*].id
vpc_public_subnets = local.enable_managed_vpc ? module.vpc[0].public_subnets : data.aws_subnet.external_public[*].id
vpc_private_subnets = local.enable_managed_vpc ? module.vpc[0].private_subnets : data.aws_subnets.external_private_subnets
vpc_public_subnets = local.enable_managed_vpc ? module.vpc[0].public_subnets : data.aws_subnets.external_public_subnets
vpc_database_subnet_group_name = local.enable_managed_vpc ? module.vpc[0].database_subnet_group_name : data.aws_db_subnet_group.external[0].name
}

Expand Down

0 comments on commit 903e103

Please sign in to comment.