-
Hi, dbHost := if env == "dev" { "XXXX.rds.amazonaws.com" } else if env == "staging" { "YYYY.rds.amazonaws.com" } else if env == "prod" { "ZZZZ.rds.amazonaws.com" } else { error("env not supported") }
bastionHost := if env == "dev" { "111.111.111.111" } else if env == "staging" { "222.111.111.111" } else if env == "prod" { "333.111.111.111" } else { error("env not supported") }
tunnel env:
ssh -i ~/.certs/cert-{{env}}.pem -fN -l ec2-user -L 5432:{{db-{{env}}}}:5432 {{bastion-{{env}}}} -v and call it like this: $ just tunnel dev
# or
$ just tunnel staging
# or
$ just tunnel prod This, unfortunately, doesn't work, and I have no clue by reading the docs how to achieve it. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Can you post the error you get? I don't notice anything obviously wrong from the justfile itself. |
Beta Was this translation helpful? Give feedback.
-
Why is it
instead of
Are you expecting nested expansion and that |
Beta Was this translation helpful? Give feedback.
-
The issue I'm trying to solve, is that I have a directory I want to run $ j tunnel dev|staging|prod and use this default:
@just --list
dbHost := if env == "dev" { "XXXX.rds.amazonaws.com" } else if env == "staging" { "YYYY.rds.amazonaws.com" } else if env == "prod" { "ZZZZ.rds.amazonaws.com" } else { error("env not supported") }
bastionHost := if env == "dev" { "111.111.111.111" } else if env == "staging" { "222.111.111.111" } else if env == "prod" { "333.111.111.111" } else { error("env not supported") }
tunnel env:
ssh -i ~/.certs/cert-{{env}}.pem -fN -l ec2-user -L 5432:{{dbHost}}:5432 {{bastionHost}} -v but it doesn't work. Thank You |
Beta Was this translation helpful? Give feedback.
-
There is one major problem with your code. default:
@just --list
tunnel env:
#!/bin/sh
dbHost={{ if env == "dev" { "XXXX.rds.amazonaws.com" } else if env == "staging" { "YYYY.rds.amazonaws.com" } else if env == "prod" { "ZZZZ.rds.amazonaws.com" } else { error("env not supported") } }}
bastionHost={{ if env == "dev" { "111.111.111.111" } else if env == "staging" { "222.111.111.111" } else if env == "prod" { "333.111.111.111" } else { error("env not supported") } }}
echo ssh -i ~/.certs/cert-{{env}}.pem -fN -l ec2-user -L "5432:${dbHost}:5432" "${bastionHost}" -v or go more shell based with default:
@just --list
tunnel env:
#!/bin/sh
dbHost='Undefined'
bastionHost='Undefined'
if [ '{{env}}' = 'dev' ]; then
dbHost='XXXX.rds.amazonaws.com'
bastionHost='111.111.111.111'
elif [ '{{env}}' = 'staging' ]; then
dbHost='YYYY.rds.amazonaws.com'
bastionHost='222.111.111.111'
elif [ '{{env}}' = 'prod' ]; then
dbHost='ZZZZ.rds.amazonaws.com'
bastionHost='333.111.111.111'
else
echo '{{env}} env not supported'
fi
ssh -i ~/.certs/cert-{{env}}.pem -fN -l ec2-user -L "5432:${dbHost}:5432" "${bastionHost}" -v Also there is no |
Beta Was this translation helpful? Give feedback.
-
Many thanks guys |
Beta Was this translation helpful? Give feedback.
There is one major problem with your code.
env
is only defined for the tunnel recipe. It doesn't exist in the global context of the Justfile. So yourif
statements need to reside in the the tunnel recipe somehow. You could do a shebang recipe like