how to access config from code ?
# typescript
r
how to access config from code ?
l
var bar = new pulumi.Config("foo").require("bar");
Unless "foo" is the name of the project, in which case, you would omit the parameter to
new Config()
.
r
its actually this i was trying to generalize
Copy code
config:
  aws:region: us-west-2
so i was trying to create a resource which is region specific so instead of hardcoding i am trying to use the region var
tenwit has the correct pattern there though, so following that and replacing
foo
with
aws
and
bar
with
region
gets you what you want.
l
The aws provider should grab that config without you needing to worry about it though. The
aws:region
config value is used automatically.
r
I tried to add new variable in pulumi.dev.yaml
Copy code
config:
  aws:region: us-west-2
  ecr:env: dev
when i try to access it throws error
Copy code
var env = new pulumi.Config("ecr").require("env");
const ecr = ecr("registry/${env}/alpine");
expecting
Copy code
const ecr = ecr("registry/dev/alpine");
Copy code
error: 1 error occurred:
        * error creating ECR repository: InvalidParameterException: Invalid parameter at 'repositoryName' failed to satisfy constraint: 'must satisfy regular expression '(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*''
oh so this works as expected
Copy code
`registry/${env}/alpine`
what is the difference between " and ` ?
r
https://basarat.gitbook.io/typescript/future-javascript/template-strings (This is how strings are interpolated in typescript)
👀 1
👍 1