Fix issue when we're sending in empty vars to Nomad
This fixes one issue where the Nomad job doesn't accept any variables
which results in a KeyError, and speeds up cases where we are not
passing in variables
@@ -98,16 +98,18 @@ class NomadJob(pulumi.ComponentResource):
) -> NomadVars:
"""
This is a hack to deal with issues around pulumi preview.
- The Problem: Specifically, during pulumi preview, pulumi Output objects never resolve into strings or other types. This means that if a PR creates a new resource and then tries to use that resource's attributes in a Nomad variable, there's a type error because Pulumi object != string. Frustratingly, this manifests as a variable unset error for ALL Nomad variables in the file. This can also happen if a project is being pulumi'd up with no existing resources.
+ The Problem: Specifically, during pulumi preview, pulumi Output objects never resolve into strings or other
+ types. This means that if a PR creates a new resource and then tries to use that resource's attributes in a
+ Nomad variable, there's a type error because Pulumi object != string. Frustratingly, this manifests as a
+ variable unset error for ALL Nomad variables in the file. This can also happen if a project is being pulumi'd up
+ with no existing resources.
The Solution:
- We're using reflection to parse the Nomad file's input variable types. We're then mocking the primitives types (str, bool, number) with fake value
-
-
-
-
+ We're using reflection to parse the Nomad file's input variable types. We're then mocking the primitives types
+ (str, bool, number) with fake values
"""
- if pulumi.runtime.is_dry_run():
+ # short circuit if there are no variables to parse
+ if pulumi.runtime.is_dry_run() and len(vars) >= 1:
hcl2_parser = HCL2TypeParser().parser
with open(jobspec) as file:
