Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing dictionary of variables to the variable_dict doesn't work #33

Open
k-willowhawk opened this issue Apr 21, 2021 · 1 comment
Open

Comments

@k-willowhawk
Copy link

I've been trying to pass values present in a workflow context to the terraform.apply action as input to the variable_dict. I can confirm it is a properly formed dictionary of variable=value pairs, but terraform doesn't seem to know their values on execution.

As a manual workaround I've needed to write out a variables file using the core.local action and pass the variable filename to terraform.apply, but this is cludgy.

@jensenja
Copy link

jensenja commented Sep 9, 2022

Not sure if you've solved this for yourself already, but what I do for this is to create the dictionary in a python-runner action, then on action completion I return the dictionary along with my success status:

from st2common.runners.base_action import Action

class MyAction(Action):
    def run(self, message):
        some_dict = {
            'apple': 'red',
            'banana': 'yellow',
        }
        # maybe do more stuff
        return (True, some_dict)

After that you just need to publish the result to a variable in the workflow context, and then reference it in your terraform plan/apply/whatever. If I had to guess - you might not be referencing the contents of the variable properly using Jinja/YAQL:

version: 1.0

input:
  - foo
  - bar

vars:
  - tform_variable_dict: null

tasks:
  get_tform_vars:
    action: my_pack.my_action
    next:
      - when: <% succeeded() %>
        publish:
          - tform_variable_dict: "{{ result().result }}"
        do: terraform_plan

  terraform_plan:
    action: terraform.plan
    input:
      plan_path: "/some/dir"
      variable_dict: "{{ ctx().tform_variable_dict }}"
[...]

EDIT: For sensitive/auth-y type stuff ie provider credentials or something, I actually do use the "write-to-file" pattern (although I'm using a python-runner with Jinja templates rather than core.local) because when you use the variable_dict parameter, the contents of the parameter will be shown in the web UI when you click on that particular action in the workflow step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants