Debugging Atlas HCL Using print()
With features such as composite schemas, custom rules, schema linting, and more, the atlas.hcl
file can get complex.
To validate or debug the file, you can use print
statements as you commonly would with other languages.
Example 1
To ensure that the proper value is being assigned to a variable, simply wrap it in a print statement:
atlas.hcl
data "runtimevar" "myip" {
url = "https://api.ipify.org?format=json"
}
locals {
ip = print(data.runtimevar.myip)
}
env "test" {
url = "mysql://user:pass@localhost:3306/my_db"
}
The print statement is evaluated when reached after running a command that accesses the file, such as atlas schema inspect --env test
.
After running the command, ip
is printed and I see a JSON in the output where I expected a string containing my IP address:
{"ip":"127.0.0.1"}
Now I know to decode and index the JSON to get the proper output.
atlas.hcl
data "runtimevar" "myip" {
url = "https://api.ipify.org?format=json"
}
locals {
ip = print(jsondecode(data.runtimevar.myip)["ip"])
}
127.0.0.1