Hi Everyone! If my js based stack is split across ...
# general
m
Hi Everyone! If my js based stack is split across files, how do I reference resources across files. One option is to pass them around. But I see lot of pulumi documentation reference existing resources by e.g. aws_iam_role.example.name (which is how I did this in terraform). However I couldn't figure out a way to get this done with pulumi. Thanks 🙂
b
this is a language problem, you need to export/import the files
we don't just collate all of the files in a directory like terraform because it violates the principal of least surprise
m
Thanks @billowy-army-68599. Which means that we should continue to pass variables between files. I see typescript examples references in documentation using the terraform methodology, e.g. https://www.pulumi.com/registry/packages/aws/api-docs/redshift/clusteriamroles/
Does it work with typescript or it doesn't work there too.
BTW, what I mean here is that if I have file1.js which has new aws.iam.role('exrole', {}). Can I reference it in file2.js by aws_iam_rile.exrole or do I need to pass that object between the two files
b
what terraform methodology is that showing?
if you have two different files, you need to export the file using your language of choice
export function
or something like that, then import it into another file
m
In the typescript section on that link it has the following line
Copy code
iamRoleArns: [aws_iam_role.example.arn],
b
that's assuming it's in the same file
m
What is the aws_iam_role referenced in the example
b
it's just a hypothetical iam role...
m
Also same file has
clusterIdentifier: aws_redshift_cluster.example.cluster_identifier,
b
again, it's a hypothetical redshift cluster
m
Are aws_iam_role and aws_redshift_cluster variables expected to be already defined in the file above?
b
yes
m
But then wouldn't it be just example.arn. or example_iam_role.arn. When I see this example it seems like there is a global dict of roles in aws_iam_role, where I can reference any existing roles by the name given to them on definition
b
this is just a very small example snippet, i'm not sure what else to say
m
No worries. Thanks a lot for your help
251 Views