https://garden.io logo
#🌱|help-and-getting-started
Unable to reference values from terraform provider
# 🌱|help-and-getting-started
m

many-pizza-75746

01/24/2024, 1:30 AM
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

quaint-dress-831

01/24/2024, 7:22 AM
@many-pizza-75746 are you attempting to cross-reference outputs? Provider variable outputs can only be consumed by providers.
m

many-pizza-75746

01/24/2024, 7:26 AM
How would I retrieve the outputs from the terraform file to be used as outputs on the project file?
q

quaint-dress-831

01/24/2024, 7:27 AM
@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

many-pizza-75746

01/24/2024, 7:28 AM
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

quaint-dress-831

01/24/2024, 7:29 AM
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

many-pizza-75746

01/24/2024, 7:29 AM
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

quaint-dress-831

01/24/2024, 7:30 AM
Yes. You only need the action or the provider.
m

many-pizza-75746

01/24/2024, 7:31 AM
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

quaint-dress-831

01/24/2024, 7:32 AM
You could use a Run action
A Run action allows you to run arbitrary commands
And then hook that in as a dependency
m

many-pizza-75746

01/24/2024, 7:33 AM
Could I get an example of how that would look like? I'm having a bit of trouble picturing how that would work
q

quaint-dress-831

01/24/2024, 7:34 AM
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

many-pizza-75746

01/24/2024, 7:34 AM
Oh no problem. Good morning to you
q

quaint-dress-831

01/24/2024, 7:42 AM
@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

many-pizza-75746

01/24/2024, 7:43 AM
will do thanks
q

quaint-dress-831

01/24/2024, 10:12 AM
@many-pizza-75746 can you try this example produced by kapa? https://discord.com/channels/817392104711651328/1199656454005719141/1199656539091378276
m

mammoth-flag-56137

01/24/2024, 11:37 PM
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

quaint-dress-831

01/25/2024, 9:16 AM
@mammoth-flag-56137 can you try and use
${actions.deploy.$nameofterraformaction.outputs.$nameofoutput}
instead?
m

mammoth-flag-56137

01/25/2024, 9:17 AM
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

quaint-dress-831

01/25/2024, 9:21 AM
@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

mammoth-flag-56137

01/25/2024, 9:23 AM
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

quaint-dress-831

01/25/2024, 9:26 AM
I meant more as an example of using Terraform outputs within your Garden graph in the future, should you desire to
m

mammoth-flag-56137

01/25/2024, 9:35 AM
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

freezing-pharmacist-34446

02/06/2024, 1:06 PM
@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 🙂