https://pulumi.com logo
#getting-started
Title
# getting-started
f

future-photographer-26589

09/16/2021, 9:09 AM
Hello guys, I'm new to pulumi and I'm using pulumi with golang. I've a question regarding
ctx.Export
suppose I create a security group on aws and I exported the
SG_ID
, I need to assign this SG to another SG so is there any way I can read this exported value?
p

prehistoric-activity-61023

09/16/2021, 9:10 AM
I haven’t used pulumi with golang but I guess I can still be helpful 😉
do you want to use that from another pulumi stack?
If it’s within the same stack, you don’t have to even export it. You should be able to simple reference the variable internally in golang code.
(see https://github.com/pulumi/examples/blob/master/aws-go-s3-folder/main.go where BucketPolicy references previously created Bucket, saved in
siteBucket
variable)
If you want to reference that in a separate Pulumi stack, you want to use StackReference.
in that case, the stack you want to import something from MUST declare the variable as the output (using
ctx.Export
)
f

future-photographer-26589

09/16/2021, 9:32 AM
So I need to write pulumi code in Imperative style, also one more question, is pulumi.Run only called once in a given stack?
Thanks for the quick response...
p

prehistoric-activity-61023

09/16/2021, 9:39 AM
I don’t think you should write it in imperative style… the whole pulumi concept is being declarative. I hope you didn’t misunderstand me somehow.
Regarding your last question, cannot say for sure (no pulumi golang experience) but I guess you shouldn’t have more than one
pulumi.Run
invocation.
Each program (regardless of the programming language used) basically declares the resources and then pulumi engine (not sure if that’s the name used by Pulumi team) based on that performs a reconciliation loop by trying to match the actual state with the one written (declared) by you.
Not sure how much experience you have with similar tools (like terraform) so if you have any more questions, feel free to ask them 🙂
3 Views