Skip to content

Commit 0a28599

Browse files
committed
2 parents 8a2bb89 + bbfa0f5 commit 0a28599

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

terraform-for-each-example/main.tf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variable "vpc_id" {
2+
description = "ID for the AWS VPC where a security group is to be created."
3+
}
4+
5+
variable "subnet_numbers" {
6+
description = "List of 8-bit numbers of subnets of base_cidr_block that should be granted access."
7+
default = [1, 2, 3, 4, 5, 6]
8+
}
9+
10+
data "aws_vpc" "example" {
11+
id = var.vpc_id
12+
}
13+
14+
15+
resource "aws_security_group" "example" {
16+
name = "for_each_example"
17+
description = "Allows access from friendly subnets"
18+
vpc_id = var.vpc_id
19+
20+
ingress {
21+
from_port = 0
22+
to_port = 0
23+
protocol = -1
24+
25+
cidr_blocks = [
26+
for num in var.subnet_numbers:
27+
cidrsubnet(data.aws_vpc.example.cidr_block, 8, num)
28+
]
29+
}
30+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}

0 commit comments

Comments
 (0)