https://pulumi.com logo
#python
Title
# python
q

quiet-football-73782

01/17/2024, 8:06 PM
Hey guys, I am new to the tool, trying to learn. Not going to lie - a bit confused. I am not that experienced within devops so pardon me if I ask any dumb questions. I am building my project infra on aws with pulumi, Some resources need to reference other resources and their attributes. Example: My dbase on RDS needs a security group, which I created previously through pulumi. I could pass the sec group id by passing the element itself:
Copy code
security_group = ec2.SecurityGroup(f'dbSecurityGroup',
                                   description=f'Enable MySQL access.',
                                   ingress=ingress_rules)

...

db_instance = rds.Instance("database",
                           ...,
                           vpc_security_group_ids=[security_group.id])
And that in practice works fine. But I am structuring my project with a bunch of services and each has its own script. So I would like to directly refer the securityGroupId from within the rds script, without passing it as an argument when calling such script. The only option to retrieve that id I found so far is to access the StackReference, which seems a bit odd, as I am already on that stack.
Copy code
security_group_id = pulumi.StackReference(".../.../...").get_output("securityGroupId")
(☝️ also works fine) Is there a way to directly access it without using stackreference? pulumi.get_stack() does not have an get output module, and I couldn't find anything that would work as such. Thank you
Hmm. Okay. Figured it out.
2 Views