Created
November 24, 2020 03:23
-
-
Save managedkaos/d7c1d4e4a34920927ad57d7698ccd9e4 to your computer and use it in GitHub Desktop.
Import an AWS VPC using just the VPC ID. Public and Private subnets are imported dynamically using filtering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "vpc_id" { | |
type = string | |
default = "vpc-12345678" | |
} | |
data "aws_vpc" "vpc" { | |
id = var.vpc_id | |
} | |
data "aws_subnet_ids" "public" { | |
vpc_id = data.aws_vpc.vpc.id | |
filter { | |
name = "tag:Name" | |
values = ["*public*"] | |
} | |
} | |
data "aws_subnet" "public" { | |
for_each = data.aws_subnet_ids.public.ids | |
id = each.value | |
} | |
data "aws_subnet_ids" "private" { | |
vpc_id = data.aws_vpc.vpc.id | |
filter { | |
name = "tag:Name" | |
values = ["*private*"] | |
} | |
} | |
data "aws_subnet" "private" { | |
for_each = data.aws_subnet_ids.private.ids | |
id = each.value | |
} | |
locals { | |
private = [for i in data.aws_subnet.private : i] | |
} | |
output "private" { | |
value = local.private[0].availability_zone | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment