If I'm creating two pieces of infrastructure - but...
# general
p
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
Have you tried passing
ResourceOptions
with
dependsOn
set?
p
In the resource constructor?
f
Yes
p
I haven't - I'm still new to Pulumi, do you have an short example?
s
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
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
You can refer to any property on an object and the dependency will be tracked through as far as I’m aware!
p
oh - that's convenient
s
ID isn’t special cased in that example
p
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
it shold do
p
That seems to have worked
s
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