mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-22 07:01:56 +03:00
for and foreach demo
This commit is contained in:
@@ -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)}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
provider "aws" {
|
||||||
|
region = var.AWS_REGION
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
variable "AWS_REGION" {
|
||||||
|
type = string
|
||||||
|
default = "eu-west-1"
|
||||||
|
}
|
||||||
|
variable "project_tags" {
|
||||||
|
type = map(string)
|
||||||
|
default = {
|
||||||
|
Component = "Frontend"
|
||||||
|
Environment = "Production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
provider "aws" {
|
||||||
|
region = var.AWS_REGION
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
variable "AWS_REGION" {
|
||||||
|
type = string
|
||||||
|
default = "eu-west-1"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user