How to get all the instances per VPC and get security group of each instance for a particular zone.

I’m trying to pull all the information of all the instances per VPC and get security group of each instance for a particular zone. I am using ec2_vpc (it is deprecated) module to get the information about an existing VPC but from reading the docs, I’m not completely sure this is possible since all the docs and examples are assuming you are either creating a VPC or deleting one.

Can anyone help me with a solution of how to get the full list of ec2 instance info for a particular region? Thanks!

You need a number of separate steps:

  1. Get VPC id (ec2_vpc_net_facts)
  2. Get list of instances in that VPC using vpc-id as a filter (ec2_remote_facts)
  3. Get the list of ENIs for each of those EC2 instances (ec2_eni_facts)

The last module will return information about security groups used by the ENIs.

kind regards
Pshem

Thanks Pshem, worked for me!

Cheers!
Nirjhar