Transforming a List of Server Names with Terraform For Expressions
📖 Scenario: You are managing cloud servers and have a list of server names. You want to create a new list where each server name is transformed to include a prefix that indicates the environment.
🎯 Goal: Build a Terraform configuration that uses a for expression to transform a list of server names by adding the prefix "prod-" to each name.
📋 What You'll Learn
Create a variable called
server_names with the exact list: ["app1", "db1", "cache1"]Create a variable called
env_prefix with the exact value "prod-"Use a
for expression to create a local variable called prefixed_servers that adds env_prefix to each server name in server_namesOutput the
prefixed_servers list💡 Why This Matters
🌍 Real World
Cloud engineers often need to manage lists of resources and apply consistent naming conventions automatically. Using for expressions in Terraform helps transform data efficiently.
💼 Career
Understanding for expressions in Terraform is essential for infrastructure as code roles, enabling automation and reducing manual errors in cloud resource management.
Progress0 / 4 steps