Course outlines for learning terraform.
expected time | requirements |
---|---|
30 minutes | A computer with Terraform installed, terraform knowledge. |
Goal: Understand what functions are and how to apply (some of) them.
Terraform has many built-in function. Some noteworthy:
You can use functions in any/many places, let’s take a look at an example:
variable "name" {
type = string
description = "The name of the project. It's used to generate unique values for all kinds of resources."
default = "my"
validation {
condition = length(var.name) > 0 && length(var.name) <= 32
error_message = "Please use a name with at least 1 character, and at most 32 characters."
}
}
validation
block to this variables.tf
:variable "example" {
type = string
description = "Some variable"
}
The validation should:
length
of the input is at least 4
characters, at most 16
characters.contains
hello
.variable "example" {
type = string
description = "Some variable"
default = "hello there"
validation {
condition = length(var.example) >= 4 && length(var.example) <= 16 && can(regex(".*hello.*", var.example)) && lower(var.example) == var.example
error_message = "The example variable must be 4 up to 16 characters, contain 'hello' and be lowercase."
}
}