Splitting code into TypeScript modules => "depe...
# general
f
Splitting code into TypeScript modules => "dependsOn" doesn't work Hello, the system I want to create with Pulumi basically consists of a MongoDB, a VNet with some subnets, 3 WebApps, a KeyVault and a Virtual Machine. As programming language I want to use TypeScript and the target system is Azure. My problem now is that all the examples I have found so far for creating various Azure resources with Pulumi, always work only with a single index.ts file. To make the code clearer I split the TypeScript code into single modules and made the contained objects available for other TypeScript modules via export. This way the code structure is easier to read and I then have e.g. a KeyVault.ts module that contains only the KeyVault related resource like Keys, Secrets and the related Access Policies. Unfortunately I found out that it can happen that Pulumi creates the resources in the wrong order. Therefore I use "depensOn" to define the order at the sensitive places myself. Unfortunately this does not work for me if I split the code into different TS modules. This means that no error is reported but the order in which the resources are created does not correspond to my "dependsOn" configuration. My dependsOn configuration only works if I have all the TypeScript code in a singleTypeScript file. Can you tell me if I am doing something wrong or why Pulumi behaves like this? ..and are there any examples available which show the how to split the code into different TypeScript modules? Many thanks and greetings, Wolfgang Schreck
1
f
Are you importing the modules A to module B? . I am doing that myself but with go without issues. I create resources 1,2,3 in package A and in package B I import the package A and use the resources 1,2,3 created on package A.
f
Hello Hernando and thanks for your answer... So if I take your example, I create the resources 1,2,3 in module A (app-services.ts) and export them there and in module B (key-vault.ts) I import the resources from module A. I can also access the resources from module A in module B, and for example I can also read the outputs from the resources 1,2,3 im module B. However, the dependencies I configured via "dependsOn" are not taken into account, that means the build order is not as I configured it via "dependsOn". If I now simply copy the code from module A into module B, then the build order works as configured in "dependsOn". I have therefore now placed the code for all resources in a single ts module - a bad solution that I actually did not want to have in this form.
f
Did you try passing the resources as arguments and handle empty resources?. Lets say in Package B you need to deploy an EC2 in a specific subnet but the subnet is created in Package A. Then your function/method on package B need to receive an argument that is the subnet from Package A. If the value is empty/null or whatever you dont want then handle that logic (i.e if len(subnet) < 1 {handle it here , dont create EC2 } else { continue creating the ec2}).