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

Shell script resource to be re-created in each apply #129

Open
ariannasg opened this issue Oct 26, 2023 · 0 comments
Open

Shell script resource to be re-created in each apply #129

ariannasg opened this issue Oct 26, 2023 · 0 comments

Comments

@ariannasg
Copy link

We've found an issue with TF tracking changes to the script when there aren't any and after it has been successfully applied.

After some investigation, we concluded that this is due to the output that the shell_script resource is producing and that:

  • you can echo whatever you want in a script
  • shell provider will only look at the final non-empty thing you echo from a script and use this as the output
  • that final echo must be valid JSON, otherwise it ignores it and will record the script output as null
  • also weirdly, only the final part of that final echo needs to be valid JSON (i.e. you can do echo 'blah blah blah {"is_json": "true"}' and it will magically extract {"is_json": "true"} as the output
  • if output is null, will always say the resource needs to be created
  • if output is empty and there's a change, it will say it needs to be created (not changed)
  • if you output nothing in the create function, it will take the output from the read function during an apply

The simplest solution we found is to have final statement in the read function with an echo in JSON format, e.g.:

function read {
  echo "Running the shell script READ operation...";
  echo "Nothing to do";
  echo '{"read": "OK"}';
  return 0;
}

Can some documentation about this be added to the provider please? Thank you.

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

1 participant