stocky-spoon-28903
10/18/2018, 3:08 PMbright-motherboard-93404
10/18/2018, 3:10 PMfunction dashboard(name, instances) {
reutrn pulumi.all(instances).apply(
(is) =>
new aws.cloudwatch.Dashboard(name, {
dashboardName: name,
dashboardBody: JSON.stringify({
widgets: [
{type: "metric",
properties: {
metrics: defineMetrics(is),
period: 300,
stat: "Average",
region: "us-west-2",
title: "EC2 Instance CPU"
}
}
]
})
}))
};
function defineMetrics(instances) {
return instances.map(function(i) {
return ["AWS/EC2", "CPUUtilization", "InstanceId", i.id]
})
}
stocky-spoon-28903
10/18/2018, 3:10 PMbright-motherboard-93404
10/18/2018, 3:10 PMstocky-spoon-28903
10/18/2018, 3:11 PMapply
is an Output<string>
dashboardBody
property which is an Input<string>
- broadly speaking Input<T> = T | Output<T> | Promise<T>
bright-motherboard-93404
10/18/2018, 3:12 PMfunction mkDash(name, instances) {
let dashBody = pulumi.all(instances).apply(
(is) => JSON.stringify({
widgets: [
{type: "metric",
properties: {
metrics: defineMetrics(is),
period: 300,
stat: "Average",
region: "us-west-2",
title: "EC2 Instance CPU"
}
}
]
}));
return new aws.cloudwatch.Dashboard(name, {
dashboardName: name,
dashboardBody: dashBody
})
};
{
"message": "Should NOT have more than 3 items",
"dataPath": "/widgets/0/properties/metrics/0"
},
stocky-spoon-28903
10/18/2018, 3:17 PMbright-motherboard-93404
10/18/2018, 3:20 PMfunction defineMetrics(instances) {
return instances.map(function(i) {
return ["AWS/EC2", "CPUUtilization", "InstanceId", i.toString()]
})
}
stocky-spoon-28903
10/18/2018, 3:22 PMinstances
here aws.ec2.Instance[]
?bright-motherboard-93404
10/18/2018, 3:29 PMfunction mkDash(name, instances) {
let dashBody = pulumi.all(instances.map(i => i.id)).apply(
(iids) => {
x = defineMetrics(iids);
return JSON.stringify({
stocky-spoon-28903
10/18/2018, 4:03 PMbright-motherboard-93404
10/18/2018, 4:03 PMwith
construct... shiverstocky-spoon-28903
10/18/2018, 4:04 PMpulumi.all
as well, I’ll have a play around in a minutebright-motherboard-93404
10/18/2018, 4:04 PMstocky-spoon-28903
10/18/2018, 4:04 PMbright-motherboard-93404
10/18/2018, 4:04 PMstocky-spoon-28903
10/18/2018, 4:05 PMbright-motherboard-93404
10/18/2018, 4:05 PMstocky-spoon-28903
10/18/2018, 4:05 PM