1. [Home](<https://delaparra-services.nl/>) 
1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) 
1. [ternary](<https://delaparra-services.nl/knowledge-hub/ternary>)

  

Category: Terraform 

# ternary

  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    

## What is ternary?

 

ternary: The conditional expression: condition ? true\_value : false\_value. The closest HCL has to an if statement. Terraform's conditional expression, ` condition ? true_value : false_value `, is the closest thing HCL has to an ` if ` statement. ` instance_type = var.env == "prod" ? "m5.large" : "t3.micro" ` picks a bigger server for production. Combined with ` count ` or ` for_each `, it can switch resources on and off: ` count = var.enable_backups ? 1 : 0 `.

 

Definition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)

 

## Frequently asked questions about ternary

  

### What should you keep in mind with ternary?

 

Keep conditions simple and readable. Several nested ternaries in one line are hard to review. Move complex decisions into a ` locals ` block with descriptive names, or use a map lookup such as ` var.sizes[var.env] `, which scales better when you add more environments. Both branches must produce compatible types, which occasionally needs a conversion function like ` tostring() `.

    

### What does an example of ternary look like?

 

```
instance_type = var.env == "prod" ? "m5.large" : "t3.micro"
```

 

## At a glance

   CategoryTerraform Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026

 

## More Terraform terms

 

- [state lock](<https://delaparra-services.nl/knowledge-hub/state-lock>) 
- [state mv / rm](<https://delaparra-services.nl/knowledge-hub/state-mv-rm>) 
- [taint](<https://delaparra-services.nl/knowledge-hub/taint-terraform>) 
- [terraform block](<https://delaparra-services.nl/knowledge-hub/terraform-block>) 
- [terraform.tfstate](<https://delaparra-services.nl/knowledge-hub/terraformtfstate>) 
- [validate](<https://delaparra-services.nl/knowledge-hub/validate>)

 

[All terms starting with T](<https://delaparra-services.nl/knowledge-hub#letter-t>)

 

## Skills

 

- ### Terraform safe workflow

 

Use when running or changing Terraform (or OpenTofu) - init, fmt, validate, plan, apply, destroy, import, state mv/rm, refresh, workspaces, remote backends, state locking, drift, taint/-replace. Enforces a plan-review-apply workflow and protects state.

 [View skill](<https://delaparra-services.nl/skills/terraform-safe-workflow>) [Download zip](<https://delaparra-services.nl/skills/terraform-safe-workflow/download>) 
- ### Terraform Module Library

 

Build reusable Terraform modules for AWS, Azure, GCP, and OCI infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.

 [View skill](<https://delaparra-services.nl/skills/terraform-module-library>) [Download zip](<https://delaparra-services.nl/skills/terraform-module-library/download>) 
- ### Multi-Cloud Architecture

 

Design multi-cloud architectures using a decision framework to select and integrate services across AWS, Azure, GCP, and OCI. Use when building multi-cloud systems, avoiding vendor lock-in, or leveraging best-of-breed services from multiple providers.

 [View skill](<https://delaparra-services.nl/skills/multi-cloud-architecture>) [Download zip](<https://delaparra-services.nl/skills/multi-cloud-architecture/download>)

 [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/ternary/skills.zip>)

 

## Manuals

 

- [Kubernetes and Terraform: do you need them?](<https://delaparra-services.nl/manuals/kubernetes-en-terraform-heb-je-het-nodig>) 
- [Choosing cloud services for your app](<https://delaparra-services.nl/manuals/cloud-diensten-kiezen>)

 

## Related services

 

- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)

Perhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet.

 

## Need any help?

 

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.

  [Get in touch](<https://delaparra-services.nl/availability>)

[HTML version](https://delaparra-services.nl/knowledge-hub/ternary)
