Conditional Expressions/Fxns Flashcards

1
Q

What are conditional expressions in terraform?

A

They allow you to choose between two values based on a condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Whats the syntax of conditional expressions in Terraform?

A

condition ? true_val : false_val

Ex: instance_type = var.environment == “dev” ? “t2.micro” : “m5.large”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What conditions can you use in Terraform?

A

== Equal to
!= Not Equal to
&& - Both conditions have to be true

Ex: instance_type = var.environment == “prod” && var.region == “us-east-1” ? m5.large : t2.micro

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is passed to the lookup function in Terraform and what does it expect?

A

The lookup () function requires that you first pass a map variable followed by a key.

Ex. ami = lookup (var.ami, var.region)
*where var.ami is a map variable with key/value pairs and var.region is the key passed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If a key passed to a lookup function doesn’t match a value in the map variable, what does the lookup function return

A

The default value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the length function work in Terraform?

A

It determines the length of a given list, map, or string

Ex:
length ([“first”,”second”]
Answer = 2

> length({“a” = “b”})
1
length(“hello”)
5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the element function work?

A

The element function retrieves a single element from the list

Ex:
> element([“a”, “b”, “c”], 1)
b, since the first element in a list is 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does the formatdate () function work?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the timestamp() function work?

A

It returns a UTC timestamp string in RFC 3339 format

Ex
> timestamp()
2018-05-13T07:44:12Z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly