Skip to content

Commit 176fe47

Browse files
committed
Added data vpc in scenario that VPC is already created for you
1 parent 1d5f04c commit 176fe47

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ locals {
88
nat_gateway_count = var.single_nat_gateway ? 1 : var.one_nat_gateway_per_az ? length(var.azs) : local.max_subnet_length
99

1010
# Use `local.vpc_id` to give a hint to Terraform that subnets should be deleted before secondary CIDR blocks can be free!
11-
vpc_id = element(
11+
vpc_id = var.create_vpc ? element(
1212
concat(
1313
aws_vpc_ipv4_cidr_block_association.this.*.vpc_id,
1414
aws_vpc.this.*.id,
1515
[""],
1616
),
1717
0,
18-
)
18+
) : data.aws_vpc.vpc.id
19+
}
20+
21+
data "aws_vpc" "vpc" {
22+
count = var.create_vpc ? 0 : 1
23+
id = var.vpc_id
1924
}
2025

2126
######

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "create_vpc" {
44
default = true
55
}
66

7+
variable "vpc_id" {
8+
description = "VPC id for use in cases where VPC was already created and you would like to reuse it with this module. Not required if create_vpc = true"
9+
type = string
10+
default = ""
11+
}
12+
713
variable "name" {
814
description = "Name to be used on all the resources as identifier"
915
default = ""

0 commit comments

Comments
 (0)