Skip to content

Commit

Permalink
for and foreach demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Oct 30, 2019
1 parent 5d9eeb6 commit a83f766
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 0 deletions.
7 changes: 7 additions & 0 deletions for-demo-2/ebs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

resource "aws_ebs_volume" "example" {
availability_zone = "eu-west-1a"
size = 8

tags = {for k, v in merge({ Name = "Myvolume" }, var.project_tags): k => lower(v)}
}
4 changes: 4 additions & 0 deletions for-demo-2/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}

12 changes: 12 additions & 0 deletions for-demo-2/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "AWS_REGION" {
type = string
default = "eu-west-1"
}
variable "project_tags" {
type = map(string)
default = {
Component = "Frontend"
Environment = "Production"
}
}

17 changes: 17 additions & 0 deletions for-demo/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "list1" {
type = list(string)
default = [1, 10, 9, 101, 3]
}
variable "list2" {
type = list(string)
default = ["apple", "pear", "banana", "mango"]
}
variable "map1" {
type = map(number)
default = {
"apple" = 5
"pear" = 3
"banana" = 10
"mango" = 0
}
}
4 changes: 4 additions & 0 deletions foreach-demo-2/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}

13 changes: 13 additions & 0 deletions foreach-demo-2/securitygroup.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
12 changes: 12 additions & 0 deletions foreach-demo-2/vars.tf
Original file line number Diff line number Diff line change
@@ -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" ]
}
}
4 changes: 4 additions & 0 deletions foreach-demo/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}

12 changes: 12 additions & 0 deletions foreach-demo/securitygroup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "aws_security_group" "example" {
name = "example" # can use expressions here

dynamic "ingress" {
for_each = [22, 443]
content {
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
}
}
}
4 changes: 4 additions & 0 deletions foreach-demo/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "AWS_REGION" {
type = string
default = "eu-west-1"
}

0 comments on commit a83f766

Please sign in to comment.