Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Terraform testing local variables and output csv file without resource Part 1

This is article is about how I test and verify my maps, list, object and sets values without any resources and to check provided objects are mentioned correctly. Here in below example I wanted to test csv file content in terraform. To check the same I created local variables from CSV file and watch the output, how it looks like below.

vmware vsphere ESXi vCenter azure cloud terraform testing variable locals without resource block provider output csv information file.png

Tot test values provided without resource I used items and values in locals variable and then used output to see how data looks on console if any modification is required. This is also an example of how to use CSV as input variables either from file or text data.

Download this script here or it is also available on github.com.

locals {

  # We've included this inline to create a complete example, but in practice
  # this is more likely to be loaded from a file using the "file" function.

    csv_data = file("${path.module}/info.csv")

#   csv_data = <<-CSV
#     name,cpu,memory,network,storage
#     server1,1,2,vlan10,vsanstorage01
#     server2,2,2,vlan10,vsanstorage01
#     server3,2,4,vlan11,vsanstorage02
#     server4,4,6,vlan11,vsanstorage02
#   CSV
  
   vms = csvdecode(local.csv_data)
}

# Output block to display the value of the "resource_info_value" variable

output "vms_details" {
  value = local.vms
}

output "vm_names" {
    value = [for vm in local.vms : vm.name]
}

Useful Articles
Terraform error retrieving storage account failure responding to request StatusCode 404 StorageAccountNotFound The storage account was not found
Terraform clone virtual machine template in VMware vSphere vCenter from CSV file
Terraform A reference to a resource type must be followed by at least one attribute access, specifying the resource name
Terraform one module deploy null or multiple resources based on input
Hashicorp Terraform map and object inside module and variable example
Terraform module clone VMware vSphere Linux and Windows virtual machine
Terraform VMware vSphere Virtual Machine customization clone failed on Windows
Terraform VMware vSphere Virtual Machine cloning Operating system not found
How to Install Minikube on Ubuntu - Step by Step
MINIKUBE Unable to start VM - This computer doesn't have VT-X AMD-v enabled
Install and Setup your own Kubernetes Cluster with K3s
Rancher k3s.yaml permission denied when using kubectl - Kubernetes

Go Back

Comment

Blog Search

Page Views

11170568

Follow me on Blogarama