variable "network_type" {
type = string
default = "create"
validation {
condition = var.network_type == "create" || var.network_type == "load"
error_message = "${var.network_type} not valid. Type must be either create or load"
}
}
contents of t.py
import hcl2
with open('test.tf', 'r') as file:
dict = hcl2.load(file)
print(dict)
python t.py
{'variable': [{'network_type': {'type': '${string}', 'default': 'create', 'validation': [{'condition': '${var.network_type == "create" || var.network_type == "load"}', 'error_message': '${var.network_type} not valid. Type must be either create or load'}]}}]}
Input test.tf
contents of t.py