July 2017
Beginner
208 pages
5h 10m
English
Continuing analogy with programming, list in Terraform is similar to arrays in most programming languages. There is a very nice place where we can use lists in our templates: security group.
Currently, an application module defines a single security group and assigns it to the instance. But an EC2 instance can have multiple security groups attached. We could have a default security group that allows an SSH access and then on an application level we have another one for app-specific permissions.
Let's add yet another variable to module/application/variables.tf, with an empty list as a default value:
variable "extra_sgs" { default = [] }
Now, let's define a default security group in template.tf with SSH access allowed: ...
Read now
Unlock full access