https://pulumi.com logo
#general
Title
# general
m

magnificent-psychiatrist-75197

07/06/2022, 9:38 PM
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

billowy-army-68599

07/06/2022, 9:49 PM
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

magnificent-psychiatrist-75197

07/06/2022, 9:57 PM
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

billowy-army-68599

07/06/2022, 9:58 PM
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

magnificent-psychiatrist-75197

07/06/2022, 9:59 PM
In the typescript section on that link it has the following line
Copy code
iamRoleArns: [aws_iam_role.example.arn],
b

billowy-army-68599

07/06/2022, 9:59 PM
that's assuming it's in the same file
m

magnificent-psychiatrist-75197

07/06/2022, 9:59 PM
What is the aws_iam_role referenced in the example
b

billowy-army-68599

07/06/2022, 10:00 PM
it's just a hypothetical iam role...
m

magnificent-psychiatrist-75197

07/06/2022, 10:00 PM
Also same file has
clusterIdentifier: aws_redshift_cluster.example.cluster_identifier,
b

billowy-army-68599

07/06/2022, 10:00 PM
again, it's a hypothetical redshift cluster
m

magnificent-psychiatrist-75197

07/06/2022, 10:00 PM
Are aws_iam_role and aws_redshift_cluster variables expected to be already defined in the file above?
b

billowy-army-68599

07/06/2022, 10:00 PM
yes
m

magnificent-psychiatrist-75197

07/06/2022, 10:02 PM
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

billowy-army-68599

07/06/2022, 10:07 PM
this is just a very small example snippet, i'm not sure what else to say
m

magnificent-psychiatrist-75197

07/06/2022, 10:33 PM
No worries. Thanks a lot for your help
55 Views