https://pulumi.com logo
#typescript
Title
# typescript
r

refined-terabyte-65361

07/27/2021, 12:45 AM
how to access config from code ?
l

little-cartoon-10569

07/27/2021, 12:48 AM
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

refined-terabyte-65361

07/27/2021, 12:53 AM
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

little-cartoon-10569

07/27/2021, 12:59 AM
The aws provider should grab that config without you needing to worry about it though. The
aws:region
config value is used automatically.
r

refined-terabyte-65361

07/27/2021, 1:04 AM
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

red-match-15116

07/27/2021, 1:16 AM
https://basarat.gitbook.io/typescript/future-javascript/template-strings (This is how strings are interpolated in typescript)
👀 1
👍 1
2 Views