I'd like to create security group which allow me to communicate between instances within subnet and don't expose some ports outside. Of course I can explicite specify my CIDR, but how create data source which give me CIDR block for my subnet in default VPC?
0
votes
1 Answers
0
votes
with terraform data source aws_vpc, you can get what you need.
The example shows what you need.
variable "vpc_id" {}
data "aws_vpc" "selected" {
id = "${var.vpc_id}"
}
resource "aws_subnet" "example" {
vpc_id = "${data.aws_vpc.selected.id}"
availability_zone = "us-west-2a"
cidr_block = "${cidrsubnet(data.aws_vpc.selected.cidr_block, 4, 1)}"
}