In this tutorial, you will deploy a pre-generated webapp to EC2 instances behind an ELB. You will:
- use
locals
to assign your expressions to variables for reuse. - use conditionals to declare if you want your configuration to contain multiple instances for high-availability.
- use the
splat
expression to return multiple private IPs in your network.
- Update the network resources of your configuration and add the
local.common_tags
expression to yourtags
attribute. - Create a new file called
outputs.tf
and add the values for your instance tags. terraform init
terraform apply
Your local
block accepts conditional criteria. Update your main.tf
file with new criteria. If the name
variable is blank, the output of the random_id
resource is the tag value.
Open variables.tf
and add a new boolean variable for high availability.
Open main.tf
in your editor and update your aws_instance count parameter with the new conditional variable criteria.
Edit the outputs.tf
file to add the new private_addresses output. This output will return the private DNS of all instances created by the aws_instance.ubuntu
resource.