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

stocky-spoon-28903

06/03/2019, 2:33 PM
Loops ;-)
b

brave-salesmen-42327

06/03/2019, 5:44 PM
Looping inside some output appy() to generate multiple resources based on a config object of some kind:
Copy code
apiKeysOutput.apply((keys) => {
  for( let apiKeyName of Object.keys(keys)) {
    usagePlanKeys.push(
      new aws.apigateway.UsagePlanKey(`${namePrefix}-UsagePlanKey_${apiKeyName}`, {
        keyId: keys[apiKeyName].id,
        keyType: "API_KEY",
        usagePlanId: apiGatewayUsagePlan.id,
      })
    )
  }
})
Then I can send all my api keys out in the output using
usagePlanKeys
s

stocky-spoon-28903

06/03/2019, 5:53 PM
That can be simplified btw with
Object.keys.map
b

brave-salesmen-42327

06/03/2019, 6:04 PM
Poof ~
Copy code
const usagePlanKeys:aws.apigateway.UsagePlanKey[] = []

apiKeysOutput.apply( keys => {
  Object.keys(keys).map(apiKeyName => {
    usagePlanKeys.push(
      new aws.apigateway.UsagePlanKey(`${namePrefix}-UsagePlanKey_${apiKeyName}`, {
        keyId: keys[apiKeyName].id,
        keyType: "API_KEY",
        usagePlanId: apiGatewayUsagePlan.id,
      })
    )
  })
})
Iteration 2:
Copy code
var usagePlanKeys:any = apiKeysOutput.apply( apiKeys => 
  Object.keys(apiKeys).map( keyName => 
    new aws.apigateway.UsagePlanKey(`${namePrefix}-UsagePlanKey_${keyName}`, {
      keyId: apiKeys[keyName].id,
      keyType: "API_KEY",
      usagePlanId: apiGatewayUsagePlan.id,
    })
  )
)