Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

Member-only story

Terraform 101: types of variables

--

In Terraform, the type of variable you use depends on the kind of data you need to represent. Here’s a guide on when to use each type:

Primitive Types: These are the basic data types in Terraform.

  • string: Use this when you need to represent text. For example, you might use a string to represent a resource name, a region, or an API key.
  • number: Use this when you need to represent a numeric value. For example, you might use a number to represent the amount of resources to create.
  • bool: Use this when you need to represent a true or false value. For example, you might use a boolean to control whether certain resources are created.

Collection Types: These are data types that can hold multiple values.

  • list: Use this when you need an ordered collection of items of the same type. For example, you might use a list to represent the availability zones for your resources.
  • set: Use this when you need an unordered collection of unique items of the same type. For example, you might use a set to represent the unique tags for your resources.
  • map: Use this when you need a collection of key-value pairs. For example, you might use a map to represent the tags for your resources, where each tag is a key-value pair.

--

--

Written by Jiadong Chen

Microsoft MVP, MCT | Azure Certified Solutions Architect & Cybersecurity Architect Expert | Member of .NET Foundation | Packt Author

Responses (1)