Runtime.services.[deploy-action-name].outputs.[out...
# 🌱|help-and-getting-started
m
Hi. I'm having trouble trying to figure out what to use instead of this output variable template as the documentation for 0.13 does not mention what to use instead. This variable is for the purpose of referencing Terraform outputs inside a Kubernetes deployment manifest. The value that comes out of referencing the variable is a literal "${runtime.services.deploy.outputs.environment_name}" instead of "dev" (example).
q
@many-pizza-75746 what happens if you use the variable kapa gave you?
Or if I'm understanding you correctly the variable never interpolates
m
i will still get the template as a string literal
yes
q
Can you please print a sanitized YAML for me?
m
oh Im not at my laptop at the moment but I'll be able to get back to you on that
what commands would I need to run?
q
I just need a look at your relevant Garden config files
m
runtime.services.foo.outputs was usable in 0.12 has this changed in 0.13?
alright I'll grab that for you when available
q
Thank you, happy to take a look!
m
sorry but which command would I need to run?
for the output you are looking for
q
I just need the Garden config files around your Kubernetes manifests
m
alright
q
So any
garden.yml
files you have
m
garden.yml (terraform provider folder)
Copy code
kind: Deploy
description: AWS Shared Product Infrastructure
type: terraform
name: infrastructure-aws

variables:
  use_default_passwords: true
garden.yml (server deploy folder)
Copy code
kind: Deploy
type: kubernetes
name: server
disabled: ${!var.connect.enabled}

include:
  - "*"

spec:  
  files:
    - deployment.yaml
    - service.yaml
    - hpa.yaml
    - ingress.yaml
    - pdb.yaml

variables:
  tls-suffix: "${var.acme.production ? 'prod' : 'staging'}"
  issuer: 'letsencrypt-issuer-staging'

dependencies:
  - deploy.gitlab-registry
  - deploy.letsencrypt-issuer-staging
  - deploy.letsencrypt-issuer-prod
  - deploy.infrastructure-aws
  - deploy.redis
  - run.server-migrate

---
kind: Run
type: kubernetes-pod
name: server-migrate
dependencies:
  - deploy.gitlab-registry
  - deploy.server-pg
  - deploy.keycloak
  - deploy.redis
disabled: ${var.server.migration.action == 'reseed'}
spec:
  resource:
      kind: "Deployment"
      name: server
  files:
    - deployment.yaml
  command: ["yarn"]
  args: ["db:migrate"]
  env:
    DD_SERVICE: "server.migration"
in the deployment.yaml I have something like this
Copy code
- name: ADMIN_PASSWORD
              value: "${runtime.services.infrastructure-aws.outputs.admin_password}"
this runtime.services variable is supposed to reference the terraform output ADMIN_PASSWORD
and what comes out of ADMIN_PASSWORD is not the actual password but a literal string of "${runtime.services.infrastructure-aws.outputs.admin_password}"
q
What if you remove the quotes?
m
doesnt change anything
im not able to work on this right now but I just grabbed the files so that you can take a look
q
Can we try and swap out the entire variable for one just for testing say ${var.issuer} ?
m
I have tried that and it works but when I reran the deploy command it did not reference that value from the terraform outputs
I also tried to reference with provider.outputs on the project file but that didn't work as I believe it's a syntax error
q
So you tried with ${providers.terraform.outputs.infrastructure-aws.admin-password} ?
Ah I see the issue (I think)
m
yup
q
This is using a Deploy action. There's two types of Terraform providers
One at the provider level and one at the action level
m
and it would appear as "${providers.terraform.outputs.infrastructure-aws.admin-password}"
would this mean that it would have to be a module instead?
that was not stated clearly in the docs
q
Actions can only reference other action variables
So for example publishId: ${actions.deploy.my-terraform.outputs.gcp_repository_url}/api
m
then you get weird stuff happening with special characters
q
Is a valid variable
m
hmm
how would I be able to reference terraform outputs in this case?
q
You just do it as I formatted it above for the publishId
Is it your kubernetes-pod action using the variable? It's unclear the way it came through
If so, you should be free to reference the terraform action
m
server-migrate isnt listing infrastructure-aws in dependencies in your code block above
q
actions.deploy.infrastructure-aws.outputs
m
Oh I didn't realise that yea that's a really good point
I'll need to check that out tomorrow and try that out
m
now stop doing work outside work hours
m
Haha lol
ok thanks for the help guys
q
Any time! Let us know how it goes when you get back to work
m
Morning @quaint-dress-831 I tried changing the variable to that on my deployment.yaml file and it still appeared as the string literal
in this case it's "${actions.deploy.infrastructure-aws.admin_password}"
q
Try "${actions.deploy.infrastructure-aws.outputs.admin_password}"
that's the password field for the database
and it's still showing up as a string literal
q
Can you patch them using the patchResources directive in your garden.yml ?
That's the recommended way of patching in variables. Option 2: using Garden template variables inside Kubernetes manifests may be broken and we'll need to file a bug
m
Hi @quaint-dress-831 it seems like that way allows the variable to be read now so the problem is solved. Just some feedback regarding this feature though, this way feels a lot less flexible than before as in 0.12 it was possible to just list the variables on manifest files and it would allow the terraform outputs to be read on there without needing to add changes to the garden.yaml files. I hope that there is a consideration to return that previous feature in some shape or form as trying to use patchresources in this way can make setting this up cumbersome rather than just applying the variable onto the manifest files. The documentation also needs to be updated with this information as there was no indication for setting up Terraform for garden that the variables need to be set up in this way for the outputs to be readable. Thanks