Is there a way to loop through a list of resources...
# general
Is there a way to loop through a list of resources e.g. ec2 instances per id, in order to create another resource like an Cloudwatch alert/alarm?
Yes! If you already know the instance IDs, you can just use a for loop to do this. If you need to look up the instances (or other resources), there are
functions that can help with this - e.g.
@gentle-diamond-70147 - thanks! where is documentation on how to implement the loop in? Can you send that
I already know the instances- I have a list of them
my list looks like
Copy code
test_instances = [i-xyz i-abc]
i just want to reference the each instance ID one at time
@gentle-diamond-70147 - can you provide an example?
You would do something like this, assuming you're using Python:
Copy code
test_instances = ["i-xyz", "i-abc"]

for instance_id in test_instances:
    instance_alarm = aws.cloudwatch.MetricAlarm(f"alarm-{instance_id}",
        alarm_description=f"Monitor for instance {instance_id}",
        # other inputs
That's just normal python by the way, the for loop is not something specific to Pulumi, in case that's not clear.
i will test this