Introducing more variables
Personally, I try to do everything I can use variables rather than hardcoding values into the code itself – while this can take more time when it comes to writing your code, I highly recommend it as both tools we have looked at allow you to override variables at runtime via the command line.
To do this in Terraform, you can use the following flag when running the apply
command:
$ terraform apply -var region="eu-west-1"
When running the Terraform code, which we discussed earlier in the chapter, we launched a network in Amazon Web Services to change the region from us-east-1
, which is the default set within the code, to eu-west-1
instead.
You can add multiple variables; the following example expands on the previous one by adding a new address space to use:
$ terraform apply -var region="eu-west-1" -var address_space="172.16.0.0/24"
When running Ansible code, for example, in the playbook we executed in the...