mumoshu / variant2

Turn your bash scripts into a modern, single-executable CLI app today
MIT License
141 stars 11 forks source link

Error thrown when variable is used in a config source job block #24

Open carlosreyna-bread opened 4 years ago

carlosreyna-bread commented 4 years ago

When var is used in a config source job block, it throws an error.

Error message:

Unknown variable; There is no variable named "var"

Example code that throws error:

variable "a" {
  value = "some value"
}

config "aconfig" {
  source job {
    name   = "ajob"
    args   = {
      errors_on   = "${var.a}"
      also_errors = var.a
    }
  }
}
mumoshu commented 4 years ago

@carlosreyna-bread Hey!

Thanks for trying Variant. Currently, a variable can depend on config, but the opposite is impossible. Do you think we need a real DAG computation among arbitrary combinations of variable and config so that it can be e.g. var a -> config b -> var b -> config c -> ....?

Also, I was trying to make Variant 2's variable resolution as much similar as possible to Terraform. Do you know if Terraform does support a DAG of e.g. arbitrary local and `var?

AFAIK, in Terraform, a complex dependency graph like resource -> provider -> resource dependency isn't handled very well, that you usually need terraform apply -target whatever to cut the graph manually. So probably it won't work for local and var as well?

carlosreyna-bread commented 4 years ago

@mumoshu, terraform variables cannot use locals. locals can be used on modules / resources and locals can point to outputs of modules and attributes of resources.

When the local is parsed, it adds the module / resource been used into a dependency and runs the module before the local can be used.

module / resource -> local -> module / resource.

I can see where this would be a lot of complex work, and if it cannot be done, there are work arounds, so it is not a huge deal.