Unable to reference values from terraform provider
# 🌱|help-and-getting-started
m
When attempting to reference the Terraform provider outputs on the project.garden.yaml file, I see that on the terraform-gke example that it makes use of the providers.terraform.outputs variable to reference the output on the project file. However, this issue occurs with me in that I am not able to reference those Terraform outputs when I set the providers.terraform.outputs variables.
q
@many-pizza-75746 are you attempting to cross-reference outputs? Provider variable outputs can only be consumed by providers.
m
How would I retrieve the outputs from the terraform file to be used as outputs on the project file?
q
@many-pizza-75746 you'd need to either go all-in on providers or all in on deployments to make variables available between e.g. a Terraform Deployment action and other actions or a Terraform provider and other provider
We have both a Terraform provider and a Terraform action so you'd need to choose one or the other
m
garden --env=$ENVIRONMENT get config -o json > config.json if I were to run something like this to retrieve the outputs to write to a file?
q
I've actually run into this before by the way and I agree it's not ideal. I think variables should be allowed to cross-pollinate.
m
does this mean that if I do not include the provider I would still be able to run garden --env=$ENVIRONMENT plugins terraform apply-action --yes -- infrastructure-aws -input=false -auto-approve with no issues?
q
Yes. You only need the action or the provider.
m
Ok back to the original question
How would I go about retrieving outputs from terraform to be written to a file outside of garden
I'm assuming that garden get outputs would not give me the information I'm looking for
q
You could use a Run action
A Run action allows you to run arbitrary commands
And then hook that in as a dependency
m
Could I get an example of how that would look like? I'm having a bit of trouble picturing how that would work
q
Sure! But I'm still in bed haha. I'm in Denmark and I assume our timezones are different. Give me a little time to get my life going and I'll respond with a fuller example in a bit.
m
Oh no problem. Good morning to you
q
@many-pizza-75746 meanwhile if you wanted to take a look, this example uses the old
Module
types from 0.12 but it should be easily convertible: https://github.com/dmytri/garden-lib-artifacts/blob/main/lib%2Fgarden.yml
You'd convert to the Run exec action: https://docs.garden.io/reference/action-types/run/exec
m
will do thanks
q
@many-pizza-75746 can you try this example produced by kapa? https://discord.com/channels/817392104711651328/1199656454005719141/1199656539091378276
m
previously we had
project.garden.yml
outputs that referenced runtime.services.terraformmodule.foo, that same thing in 0.13 doesnt work anymore once the terraform module is converted to an action
q
@mammoth-flag-56137 can you try and use
${actions.deploy.$nameofterraformaction.outputs.$nameofoutput}
instead?
m
We ended up just cd ing into the terraform dir and using terraform outputs -json
We just needed the AWS resource name of various ECR repos to feed to docker login
q
@mammoth-flag-56137 in the future, this article I wrote up uses Terraform outputs extensively to demonstrate using Garden as multi-registry image builder and pusher: https://garden.motif.land/flux-fastapi-mongodb-garden
It may be helpful
m
We do our image building separately with kaniko and store them in gitlab, when we deploy we pull from gitlab then push to ECR
q
I meant more as an example of using Terraform outputs within your Garden graph in the future, should you desire to
m
Strictly speaking we do use them in other actions it's just the garden.project.yml outputs we struggled with updating to 0.13 but as above we realised we didn't actually need to get those values through garden
f
@many-pizza-75746 @mammoth-flag-56137 are you still experiencing issues accessing terraform outputs and if so could you create a small reproducible example? I am using terraform outputs in a couple of garden projects myself, without problems so would be great to get a repro where it fails 🙂
2 Views