1

From the pulumi docs for creating a global dynamo table, creating the global table depends on the replica tables being created first. My Pulumi project is in an asynchronous typescript environment, and I'm creating the replica tables inside the function below.

const replicaTables: any[] = [];
pulumi
  .all([createAwsProvidersInAllRegions(accountsConfig)])
  .apply(async ([providers]) => {
    return providers.map(({ provider, regionName, vpcId, subnets }) => { 
      // create replica tables here
      const regionalReplicaTable = createReplicaTable();
      replicaTables.push(regionalReplicaTable);

   });
});

I'm trying to create the global table in the code below.

 new aws.dynamodb.GlobalTable(`${namespace}-deviceInfo-global`, {replicas: replicaTables},
  {
     dependsOn: replicaTables,
  },

But the replicaTables array is empty at the time this code runs due to the asynchronous nature of the node environment. How do I ensure that the replicaTables array is filled with the replica tables at the time the code to create the global table runs?

Victor Cui
  • 1,393
  • 2
  • 15
  • 35
  • Is `accountsConfig` an output? Why does it have to be inside `pulumi.all`? – Mikhail Shilkov Dec 09 '20 at 17:35
  • `accountsConfig` is not a Pulumi outout, but it's an array of Pulumi configs. `const accountsConfig = config.requireObject('awsAccounts');` – Victor Cui Dec 09 '20 at 17:42
  • Then I wouldn't put it inside an apply. Use a loop or an `Array.map` to create replicas? – Mikhail Shilkov Dec 09 '20 at 17:48
  • don't I still need a container to hold all replicas even if I extract creating the replicas out of the `pulumi.all`? I'm still unsure what the point of `pulumi.all()` is. – Victor Cui Dec 09 '20 at 17:52

0 Answers0