Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
Fix issue when we're sending in empty vars to Nomad
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thomas Wunderlich committed Aug 18, 2022
1 parent 1e139a7 commit 1e8ecfd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pulumi/infra/nomad_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ def _fix_pulumi_preview(
) -> 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:
Expand Down

0 comments on commit 1e8ecfd

Please sign in to comment.