Please find attached in this PR the implementation to extend the aws_ec2_gather_instances.rb task so it will now cycle through all the available AWS regions to the user in scenarios where the default option is passed to the task.
In order to make this task possible, the following was done:
aws_keys_valid?() helper was introduced. Originally the task only supported enumerating one region per run meaning that the credentials were checked and then instances belonging to only one region were gathered. However now that there could be multiple regions, this helper method will be ran when the task starts and if it fails, the task will be aborted. This has the added benefit of not iterating through all the regions when the credentials are invalid.
retrieve_ec2_regions() helper was added. This will make a call to the return the list of EC2 Regions that the credentials have access to. Rather than hard-coding the list of regions, this can prove helpful in cases where the AWS Key belongs to a government entity in which regions such as us-gov-east-1 will be accessible. Another added benefit is that this allows the list of regions to be pulled dynamically, without us having to intervene in case a region gets added/removed in AWS. However if the key lacks permission to call the describe_regions operation, it will return a hardcoded list of the default regions.
The region task option can also take in an array of regions to cycle through that are delimited by using a comma; e.g:
Hi team,
Please find attached in this PR the implementation to extend the
aws_ec2_gather_instances.rb
task so it will now cycle through all the available AWS regions to the user in scenarios where the default option is passed to the task.In order to make this task possible, the following was done:
aws_keys_valid?()
helper was introduced. Originally the task only supported enumerating one region per run meaning that the credentials were checked and then instances belonging to only one region were gathered. However now that there could be multiple regions, this helper method will be ran when the task starts and if it fails, the task will be aborted. This has the added benefit of not iterating through all the regions when the credentials are invalid.retrieve_ec2_regions()
helper was added. This will make a call to the return the list of EC2 Regions that the credentials have access to. Rather than hard-coding the list of regions, this can prove helpful in cases where the AWS Key belongs to a government entity in which regions such asus-gov-east-1
will be accessible. Another added benefit is that this allows the list of regions to be pulled dynamically, without us having to intervene in case a region gets added/removed in AWS. However if the key lacks permission to call thedescribe_regions
operation, it will return a hardcoded list of the default regions.The
region
task option can also take in an array of regions to cycle through that are delimited by using a comma; e.g:us-east-1, us-east-2
Thank you.
Best regards, Maxim