https://pulumi.com logo
p

proud-tiger-5743

09/24/2018, 10:53 PM
If I'm creating two pieces of infrastructure - but one needs the
name
of the previous one, how can I ensure that infrastructure A exists before Infrastructure B is created?
f

full-dress-10026

09/24/2018, 10:57 PM
Have you tried passing
ResourceOptions
with
dependsOn
set?
p

proud-tiger-5743

09/24/2018, 10:58 PM
In the resource constructor?
f

full-dress-10026

09/24/2018, 10:58 PM
Yes
p

proud-tiger-5743

09/24/2018, 11:00 PM
I haven't - I'm still new to Pulumi, do you have an short example?
s

stocky-spoon-28903

09/24/2018, 11:05 PM
You should be able to feed the name through and dependencies will be inferred- for example:
Copy code
const vpc = new aws.ec2.Vpc(`my-vpc`, { ... });

const subnet = new aws.ec2.Subnet(`my-subnet`, {
    vpcId: vpc.id,
    //... other properties
});
That will create the VPC before the subnet
p

proud-tiger-5743

09/24/2018, 11:08 PM
What about situations where the infrastructure doesn't have a natural relationship - like subnet - vpc? In this case the Kinesis stream name is being used to generate the Swagger template, which API Gateway doesn't necessarily need
And what results from the initial build is a reference to the
previous
name of the stream
s

stocky-spoon-28903

09/24/2018, 11:20 PM
You can refer to any property on an object and the dependency will be tracked through as far as I’m aware!
p

proud-tiger-5743

09/24/2018, 11:20 PM
oh - that's convenient
s

stocky-spoon-28903

09/24/2018, 11:20 PM
ID isn’t special cased in that example
p

proud-tiger-5743

09/24/2018, 11:21 PM
Would the same apply to something like this
Copy code
const ingestAPI = new aws.apigateway.RestApi(
  "ingest",
  {
    body: streamIAMRole.arn.apply(arn => swaggerSpec(arn, gatewayRequestStream))
  },
  { parent: ingestStream }
);
s

stocky-spoon-28903

09/24/2018, 11:21 PM
it shold do
p

proud-tiger-5743

09/24/2018, 11:26 PM
That seems to have worked
s

stocky-spoon-28903

09/24/2018, 11:27 PM
dependsOn
(like in Terraform) is a blunt tool that you shouldn’t have to use very often - the only times you need it are when two things truly have no exterior relationship but some internal one - it’s usually indicative of an irritating API design at the provider I’ve found