0
votes

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?

1
Can you share your Terraform code to show what you've tried so far and explain how that's not working for you? If you get an error could you also include the full error in your question? - ydaetskcoR

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)}"
}