acceptable-army-69872
07/16/2021, 6:11 PMfunction createProviderMap(o_accounts: aws.organizations.Account[]): Map <string, aws.Provider> {
let providerMap = new Map();
o_accounts.map( o_account => {
pulumi.all([o_account.id, o_account.name ]).apply ( ([id, name]) => {
providerMap.set(name, new aws.Provider(`${id}-provider`, {
assumeRole: {
roleArn: `arn:aws:iam::${id}:role/OrganizationAccountAccessRole`,
sessionName: "PulumiSession",
},
profile: config_aws.require('profile'),
region: aws.config.requireRegion(),
}));
});
});
console.log(providerMap);
}
I feel like I'm missing something big, but this is my first use of Map. Perhaps the issue is I'm creating the provider inside of a .all
...thoughts?steep-toddler-94095
07/16/2021, 8:23 PMMap
within an apply
like that. Your function would have to return a
pulumi.Output<{
[x: string]: aws.Provider;
}>[]
but then the Output
would sort of taint your resource types in a similar way that Promise
does. There isn't really a way around having to deal with Output
as long as you want to get the id
from an aws.organizations.Account[]
acceptable-army-69872
07/16/2021, 8:37 PMsteep-toddler-94095
07/16/2021, 8:44 PMacceptable-army-69872
07/16/2021, 8:50 PMsteep-toddler-94095
07/16/2021, 9:05 PMgetResource
functions return a Promise
instead of an Output
. Given the requirement that you create some of these accounts dynamically I think you may just have to deal with having `Output<Provider>`s. I don't recommend using getOrganization
here because the promise may resolve before the new account is actually created.
The official stance is that it's not recommended to create resources within an apply
but sometimes I do not see a better way around it.acceptable-army-69872
07/16/2021, 9:13 PMif this.accountId === undefined; this.accountId = createAccount(name, email);
so instead of big ass json blob, big ass directory of account objects.export function getOrCreateZone(zoneName: string): any {
return aws.route53.getZone({
name: zoneName
}).then(zone => {
let zoneId: any = zone.zoneId;
if (zoneId === undefined) {
const newZone: aws.route53.Zone = new aws.route53.Zone(zoneName, {
comment: `${config.require("stack")} ${zoneName} service`,
name: zoneName,
tags: {
Name: zoneName,
Environment: config.require("stack")
}
});
zoneId = newZone.zoneId.apply(zId => {return `${zId}`});
}
return zoneId;
});
}
that I think it would work.steep-toddler-94095
07/16/2021, 9:30 PMany
. At the very least, let Typescript infer the type for you instead
export function getOrCreateZone(zoneName: string) {
return aws.route53.getZone({ name: zoneName }).then(
(zone) =>
(zone.zoneId as string | undefined) ??
new aws.route53.Zone(zoneName, {
comment: `${config.require("stack")} ${zoneName} service`,
name: zoneName,
tags: {
Name: zoneName,
Environment: config.require("stack"),
},
}).zoneId
)
}
acceptable-army-69872
07/16/2021, 9:36 PM