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

Questions about how to use it #2

Open
carlos-alarcon opened this issue Feb 21, 2020 · 1 comment
Open

Questions about how to use it #2

carlos-alarcon opened this issue Feb 21, 2020 · 1 comment

Comments

@carlos-alarcon
Copy link

Hi I have some questions about how to use the provider:

Let's say we have a rest api and a script which receives
{ "name" : "name1" }

by STDIN and create as first parameter it will create a resource in our system:
{ 'id': 'id-1', 'name': 'name1' }

so if we set:

resource "multiverse_custom_resource" "own-resource" { executor = "node" script = "script_name" id_key = "id" data = <<EOF { "name": "${var.name}" } EOF }

So it works great to create the resource. And it is stored in the state.
The problem I have is that I need the Id to: read, update and destroy the resource so somehow it should be present in the data when reading, destroying and updating but not when creating since it will be an output from the creation itself.

How do I have to do it?.
I had tried using ${multiverse_custom_resource.own-resource.id} but terraform tell mi there is a cycle which seems very normal

I think it could be done if when doing read/update/destroy the Id is also added to the script as a second param

@carlos-alarcon carlos-alarcon changed the title Cuestions about how to use it Questions about how to use it Apr 8, 2020
@benishak
Copy link
Contributor

Hey @carlos-alarcon, just saw this... I live this answer for you if you still need it and for future users..
the id is saved and stored in the states, to update or destroy or read the resource you created by your script.. you don't need to provid the id explicitly.. just by doing e. g. terraform destroy, terraform will read the id from the states and pass it to the provider and the provider pass it to your script so your script can use the id to find the resource and delete/destroy it.

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