Hi folks, I managed to write a typescript like th...
# typescript
Hi folks, I managed to write a typescript like this:
Copy code

    const accounts =
        someJsons.map((out: any) =>
            // Explicit providers
            // <https://www.pulumi.com/docs/concepts/resources/providers/>
            account: new cloudflare.Provider(out.account_id, { apiToken: out.account_token })

    const buckets =
        accounts.map((out: any) =>
            bucket: new cloudflare.R2Bucket(`r2-${out.bucket_name}`, {
                accountId: out.account_id,
                name: out.bucket_name,
                location: out.bucket_location,
            }, { provider: out.account }),

            allPms: cloudflare.getApiTokenPermissionGroups({ provider: out.account })

Where I import a JSON with array where each element has one S3 bucket name and a Cloudflare account ID where this bucket should be created. It works great unless they're two buckets in the same account since
account: new cloudflare.Provider(out.account_id
throws an error when re-using the same
. I need to write some condition that checks if the account was already used and then return it's object or create a new object if the account hasn't been created yet. Could you please help me how to do that? Thank you.
Can't you just keep track of the account_ids you've already made providers for in a map? I don't think you need any Pulumi specific tricks to support this.