some-continent-7311
09/28/2022, 10:21 AMimport * as pulumi from "@pulumi/pulumi";
import { Output } from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
export = async () => {
const environment = pulumi.getStack();
const clusterConfig = new pulumi.StackReference(`xyz/cluster-config/${environment}`);
const tenantIds = await clusterConfig.requireOutput("tenantIds").apply(value => value as string[]);
const config = new pulumi.Config();
const project = config.require('project');
const location = config.require('location');
const storageClass = config.require('storageClass');
const bucketUrls = new Array();;
for (let tenantId of tenantIds) {
const tenantName = tenantId.split('-')[0];
const bucketName = `xyz-${environment}-${tenantId}`;
const bucket = new gcp.storage.Bucket(bucketName, {
name: bucketName,
project,
location,
storageClass,
labels: {
'tenant': tenantName,
'env': environment,
},
});
bucketUrls.push(bucket.url);
}
return {
bucketUrls
};
};
However, when I run pulumi up
I get this error:
index.ts(16,23): error TS2488: Type 'Output<string[]>' must have a '[Symbol.iterator]()' method that returns an iterator
because of this line:
const tenantIds = await clusterConfig.requireOutput("tenantIds").apply(value => value as string[]);
What’s the proper way to convert Ouptput<any>
to string[]
and iterate the list of strings?^1.0.0
to Pulumi ^3.0.0
and have to replace requireOutputSync
(deprecated) with requireOutput
but can’t quite figure out how to make the code async.ripe-russia-4239
09/28/2022, 11:52 AMsome-continent-7311
09/28/2022, 12:45 PMinterpolate
can help me here.ripe-russia-4239
09/28/2022, 1:10 PMOutput<any>
to Output<string[]>
first, like so:
const tenantIds = await clusterConfig.requireOutput("tenantIds") as Output<string[]>
tenantIds.apply(ids => {
// ...
for (let tenantId of ids) {
// ...
}
}
some-continent-7311
09/28/2022, 1:12 PMlittle-cartoon-10569
09/28/2022, 7:49 PMsome-continent-7311
09/29/2022, 7:21 AMrequireOutputValue
.