sparse-intern-71089
09/07/2021, 5:51 AMbored-table-20691
09/07/2021, 6:08 AMwide-crayon-4093
09/07/2021, 6:25 AMfunc SetupPostgres(ctx *pulumi.Context, args *DataArgs, opts ...pulumi.ResourceOption) error {
var postgresCfg ConfigPostgres
config.New(ctx, "data").RequireObject("postgres", &postgresCfg)
for _, instanceCfg := range postgresCfg.Instances {
err := setupPostgresInstance(ctx, &instanceCfg, args, opts...)
if err != nil {
return err
}
}
return nil
}
func setupPostgresInstance(
ctx *pulumi.Context, cfg *ConfigPostgresInstance, args *DataArgs, opts ...pulumi.ResourceOption,
) error {
instance := &PostgresInstance{
Name: cfg.Name,
InstanceName: fmt.Sprintf("postgres-%s", cfg.Name),
}
instance.pgaPasswordName = fmt.Sprintf("%s-pga", instance.InstanceName)
instance.pgaPassword, err = random.NewRandomPassword(ctx, instance.pgaPasswordName, &random.RandomPasswordArgs{
Length: <http://pulumi.Int|pulumi.Int>(24),
Special: pulumi.Bool(false),
}, opts...)
if err != nil {
return err
}
pgaConfig := instance.pgaPassword.Result.ApplyT(func(pgaPassword string) string {
// instance here is the last element, not the current
return instance.preparePgaConfig(pgaCfg.ApiKey, pgaPassword)
}).(pulumi.StringOutput)
return nil
}
wide-crayon-4093
09/07/2021, 6:27 AMbored-table-20691
09/07/2021, 6:36 AMApplyT
callback function will not be invoked until it’s ready, and at that point, you’re referring to the last iteration of the loop most likelywide-crayon-4093
09/07/2021, 6:37 AMwide-crayon-4093
09/07/2021, 6:39 AM