mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-28 19:02:07 +03:00
for and foreach demo
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
provider "aws" {
|
||||
region = var.AWS_REGION
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
resource "aws_security_group" "example" {
|
||||
name = "example" # can use expressions here
|
||||
|
||||
dynamic "ingress" {
|
||||
for_each = var.ports
|
||||
content {
|
||||
from_port = ingress.key
|
||||
to_port = ingress.key
|
||||
cidr_blocks = ingress.value
|
||||
protocol = "tcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
variable "AWS_REGION" {
|
||||
type = string
|
||||
default = "eu-west-1"
|
||||
}
|
||||
|
||||
variable "ports" {
|
||||
type = map(list(string))
|
||||
default = {
|
||||
"22" = [ "127.0.0.1/32", "192.168.0.0/24" ]
|
||||
"443" = [ "0.0.0.0/0" ]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user