So I'm running into a curious problem with my stac...
# python
w
So I'm running into a curious problem with my stack. I have a main that refers to my vpc, sec-group and ec2 generation files. Each is invoked in sequence, first vpc, then my groups, then my ec2 instances. My VPC returns back the vpc object, and adds the subnet ID's into parameter store for reference. However when it gets to my ec2 creation I get an error stating that my parameters haven't been created yet. If however I comment out ec2 and let it run, no errors. Then if I then restore ec2 and re-run it will run to completion as the parameters were already created. So from the looks of it, my vpc function is returning before the actual calls to AWS are finished. How can I make the function wait for this to be completed?
a
Can you share some code snippets and/or error messages? What do you mean by adding "subnetID's into parameter store"? How are you passing in those outputs from the VPC?
w
I call a add-to-ssm function, I provide the path, value and it writes the subnet ID to ssm parameter store once the function completes. So in my VPC code block I have pub_subnet = aws.ec2.Subnet(...) Following that is my ssm.AddIdToSSM(PATH, VALUE) However when the VPC code block returns, it has not actually finished either creating the subnet, or writing to parameter store. When it continues to the ec2 creation portion I get the following:
Copy code
Exception: invoke of aws:ssm/getParameter:getParameter failed: invocation of aws:ssm/getParameter:getParameter returned an error: invoking aws:ssm/getParameter:getParameter: 1 error occurred:
        * describing SSM parameter (/sandbox/production/us-east-1/us-production/subnets/private1): ParameterNotFound:
a
Ok, so even though your Python program runs "in sequence", Pulumi will first execute the whole program to determine what needs to be created. Then all the resources are created by calling the respective cloud APIs. Pulumi will automatically detect if one resource creation is dependant on the output from another, but only if these references are direct:
Copy code
vpc = aws.ec2.Vpc(...)

# Used as input in another resource...
other = aws.someOther(vpc_id=vpc.id)
Are those resources not in the same Pulumi stack? Why do you want to first store the output in SSM and then retreive it from there?
w
@adventurous-butcher-54166 thank you for the advice! I changed my VPC function to output a dict with all the id's and this allowed my ec2 function to execute without the errors!
a
My pleasure, and if you happen to bump into cases where an Output isn't accepted you can always go for
resource.id.apply(lambda x: x)
which will signal that the value isn't yet available.