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

brave-angle-33257

04/13/2020, 9:13 PM
can anyone help me with this
Outputs
situation?
I have an output from a stack that is a list of strings
String[]
Copy code
Outputs:
    table_names        : [
        [0]: "user"
        [1]: "token"
    ]
In another stack, I'm trying to create an alarm for each table
Copy code
var dynamo_stack = new pulumi.StackReference(`${this.company}-dynamo-tables.${this.region}.${this.env}`);
        var table_names = <pulumi.Output<string[]>>dynamo_stack.getOutput('table_names');

        /// alarms
        for ( let table in table_names ) {

            var alarm_name = `${this.prefix}-dynamodb-read-throttle-${table}`;
            console.log(alarm_name);

        }
I get this when I run it:
Copy code
Diagnostics:
  pulumi:pulumi:Stack (mycompany-alarms-mycompany-alarms.us-east-1.stage):
    mycompany-us-east-1-stage-dynamodb-read-throttle-__pulumiOutput
    mycompany-us-east-1-stage-dynamodb-read-throttle-resources
    mycompany-us-east-1-stage-dynamodb-read-throttle-allResources
    mycompany-us-east-1-stage-dynamodb-read-throttle-isKnown
    mycompany-us-east-1-stage-dynamodb-read-throttle-isSecret
    mycompany-us-east-1-stage-dynamodb-read-throttle-promise
    mycompany-us-east-1-stage-dynamodb-read-throttle-toString
    mycompany-us-east-1-stage-dynamodb-read-throttle-toJSON
I've tried multiple variations, but not sure the proper way to iterate through an array of outputs and use that string item in a loop
f

fast-dinner-32080

04/13/2020, 9:18 PM
You will need to use .apply on the stack output to get the underlying value.
h

handsome-actor-1155

04/13/2020, 9:19 PM
Try something like:
Copy code
var table_names = dynamo_stack.getOutput('table_names').apply(tables => do_table_things);
b

brave-angle-33257

04/13/2020, 9:20 PM
the output is a list of string, do i have to do all the actions I want per table in that
do_table_things
?
h

handsome-actor-1155

04/13/2020, 9:21 PM
Yes, technically inside that apply statement
Copy code
var table_names = dynamo_stack.getOutput('table_names').apply(tables => tables.foreach(table => print(table));
b

brave-angle-33257

04/13/2020, 9:22 PM
so, inside that .apply() I'll get the
String[]
? can I pass that to a function and iterate inside the function
ah, alrighty.. let me give that a shot then
in that example then, there really is no value being set to
table_names
then
its just a call to do things on the outputs then
i.e.
Copy code
// do the table stuffs
dynamo_stack.getOutput('table_names').apply(tables => tables.foreach(table => print(table));
h

handsome-actor-1155

04/13/2020, 9:30 PM
you got it
b

brave-angle-33257

04/13/2020, 9:32 PM
cool, this seemed to work:
Copy code
make_dynamo_alarms() {

        var dynamo_stack = new pulumi.StackReference(`${this.company}-dynamo-tables.${this.region}.${this.env}`);
        dynamo_stack.getOutput('table_names').apply(tables => this.dynamo_alarm(tables));

    }

    dynamo_alarm(tables) {
        for ( let table of tables ) {
            console.log(table)
        }
    }
Copy code
Diagnostics:
  pulumi:pulumi:Stack (mycompany-alarms-mycompany-alarms.us-east-1.stage):
    user
    token
thank you!!
now that i have something that does what I expect, i can tweak it to be better from here.. i think i got the gist now
👍 1