for and foreach demo

This commit is contained in:
Edward Viaene
2019-10-30 16:05:22 +01:00
parent 5d9eeb6c4c
commit a83f7669ab
10 changed files with 89 additions and 0 deletions
+7
View File
@@ -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
View File
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}
+12
View File
@@ -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
View File
@@ -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
View File
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}
+13
View File
@@ -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
View File
@@ -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
View File
@@ -0,0 +1,4 @@
provider "aws" {
region = var.AWS_REGION
}
+12
View File
@@ -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
View File
@@ -0,0 +1,4 @@
variable "AWS_REGION" {
type = string
default = "eu-west-1"
}