In terraform there is no actual if else condition block. But still you can use if condition to filter map or list of objects to get the required keys or values. In below example I have scenario where I wanted to create Resource Group in Azure to defined locations only. Incase no data is provided or…
Blog posts : "terraform"
Terraform variable precedence and priority
This is a informational article on how the variable precedence works in Terraform. This is how the priority is defined for variable when you use it in different ways. In the following diagram, it shows the information of variable priority matrix. Lower the number it has higher the priority and it w…
Terraform passing different credentials to different subscriptions with provider alias
While planning and designing Terraform configuration files for Azure deployment, I wanted to deploy resources to different environment in different subscriptions. In the designing code idea was to use different multiple credentials while deploying environments and referencing them with alias.
Terraform Force-Unlock Command and Unlocking State file on Azure backend with PowerShell
While working on collaborative environment of Terraform deployments, you might encounter an error of acquiring the tf state locking issue. In Terraform word when backend is configured to store state file on remote. It limits multiple users from making changes to environment at the same time to avoid…
Create storage account and Service Principal using PowerShell for Terraform Azure Backend
While working on earlier article Configure Azure Storage Account Blob as Terraform backend to store tfstate file, I wanted to test terraform backend configuration with Azure Service Principal (App registrations) account. To configure initial resources on Azure for backend, I have automated all the …
Configure Azure Storage Account Blob as Terraform backend to store tfstate file
In the HashiCorp Terraform context state file is a crucial file when deploying resources through terraform configuration tf file. State file's extension is .tfstate. It is a JSON information/documentation that stores and records details about your organization infrastructure and its configuration. …
Terraform variable validation example
In Terraform, the can
function is used to determine whether a given expression or operation can be evaluated without causing an error. It returns true
if the expression can be evaluated without errors, and false
otherwise. This can be particularly useful for handling optional or dynamic attributes t…
Terraform create Azure Virtual Machines from map of objects
I had a task to create multiple Ubuntu Virtual Machines on Microsoft Azure using Terraform. Below is the code for the same. Requirement was VM information should be put into variable with type of map object (Multiple VMs will be created using it). Another requirement was there is already core infras…
Creating a Private Endpoint for Azure Storage Account with Terraform example 3
This is third part of the script and little bit improvement and 2 separate logics I have added to the script. It is modification of earlier written part Creating a Private Endpoint for Azure Storage Account with Terraform example 2. In the script I wanted to create multiple endpoint for sub resourc…
Terraform refactoring moved block example
While working with Azure Terraform I converted/updated existing resource block to module (Removed resource block and added module replacing it). But after running terraform plan command I found that earlier created resource using resource block will be destroyed and it will be creating a complete…
Terraform create Azure Virtual Network subnets from map of object and show name in the header
This is a second part and little update to Using element function with count meta argument example Terraform Azure subnets. After submitting PR (Pull Request), reviewer asked they want small change in the output how it shows on the console. As I am using count to loop through subnet address prefixe…
Using element function with count meta argument example Terraform Azure subnets
I had a task to deploy multiple subnets to a Azure Virtual Network (vNet) using Hashicorp Terraform HCL. I wanted to test and use element() function combination with count meta argument to do the simple POC with less code and automation. Here is snapshot of my Virtual Network's Subnets view in the p…
Terraform Azure Create Private Endpoint to existing Storage Account with Custom Private DNS zone record link
I had a task to create Private Endpoint in Microsoft Azure and was requirement to automate this job using HashiCorp Terraform automation tf configuration files. This Private endpoint will be linked to existing Storage Account and Virtual Network. Other required sub resources Virtual Network Links …
Terraform count vs for_each for examples with map of objects
In this Terraform article I have two examples for loop and count loop. I have one map of object. Where I will use both the loops on map to show how to use them in different way. You can check my earlier articles for different loops examples - Terraform for_each loop on map example and Terraform…
Terraform remote-exec provisioner with ssh connection in null_resource
This is a Terraform example of remote-exec provisioner with ssh connection using null_resource. To use remote-exec you need to provide remote server connection information. In my below example I am using and creating connection with ssh protocol to linux servers with terraform configuration. If you …
Terraform fore_each for loop filter with if condition example
In this HashiCorp Terraform configuration example article, I am using if condition to filter list of variable objects. Here in this configuration I am have multiple list of resource group, Their name and location are different in the variable objects as mentioned below.
I want to deploy only…
Terraform foreach module output to show only required results
In my previous articles I was testing my variable information to see output, one thing I observed in the output was showing all the variable content information in the output.
Terraform testing local variables and output csv file without resource Part 1
Terraform testing variable map object va…
Terraform clone virtual machine template in VMware vSphere vCenter Dynamic Content Part 2
This is improvised Terraform configuration scripts to clone Windows and Linux Template from VMware vCenter server. I have made few improvements in the configuration adding dynamic content block in the modules for network and disks. Another change is use variables, New VM information from csv file to…
Terraform deploy create A Private DNS Record in Microsoft Azure from list of objects
This is an example of creating multiple private DNS records in Microsoft Azure from list of objects. Here I am starting with variables.tf, I am using below list of objects as type in variable.
#variables.tf variable "dns_records" { type = list(object({ name =
Terraform testing variable map object values without resource configuration part 2
This is second part of earlier written article Terraform testing local variables and output csv file without resource Part 1. Idea is use same method technique to learn and verify how to assign map of object works. Below is the example of variable map object and its output.
I used this map obje…
Blog Search
Page Views
12450092
Archive
- December 2024 (1)
- November 2024 (2)
- October 2024 (7)
- September 2024 (12)
- August 2024 (22)
- July 2024 (11)
- June 2024 (1)
- May 2024 (3)
- April 2024 (5)
- November 2023 (1)
Comments
-
AzraelJanuary 28, 2025 01:28AM
-
raghavendraJanuary 16, 2025 02:13PM
-
jose antonioJanuary 11, 2025 09:53PM
-
DanDecember 22, 2024 10:49PM
-
ChriSDecember 1, 2024 05:27PM