https://pulumi.com logo
#aws
Title
# aws
b

best-lifeguard-91445

02/04/2021, 8:19 PM
Given the following code, how can ensure that my outputs are evaluated prior to the resource creation that relies on it. The following does not appear to work..
Copy code
export const evaluateEnvironmentVariables = (services: Services, variables: Map<string, Output<string>>): void => {
    for (const service of services) {
        for (const envVar of service.environment) {
            const envVarName = envVar.name.toString();
            const replacementValue = variables.get(envVarName);

            if (replacementValue) {
                replacementValue.apply(value => {
                    envVar.value = value; // envVar.value is Input<string>, value is Output<string>
                });
            }
        }
    }
};

services.evaluateEnvironmentVariables(allServices, variables);

// Create resource that depends on these updated environment variables (KeyValuePair)
l

little-cartoon-10569

02/04/2021, 8:23 PM
Can you pass the variables via constructor args instead of env vars?
Alternatively, you could try doing these things in the args of the resource? Haven't tried this though..
Copy code
new YourEnvVarResource(name, {
  services: pulumi.output(services).apply((services) => { /* your code */}),
  ...
});
In theory this would make your resources dependent on the
apply
, I think? So it wouldn't be created until that apply completed...
b

best-lifeguard-91445

02/04/2021, 8:30 PM
I'll give it a shot. thanks!