lib/aws_recon/collectors/ec2.rb in aws_recon-0.2.4 vs lib/aws_recon/collectors/ec2.rb in aws_recon-0.2.5

- old
+ new

@@ -46,9 +46,26 @@ struct = OpenStruct.new(instance.to_h) struct.type = 'instance' struct.arn = instance.instance_id # no true ARN struct.reservation_id = reservation.reservation_id + # collect instance user_data + if @options.collect_user_data + user_data_raw = @client.describe_instance_attribute({ + attribute: 'userData', + instance_id: instance.instance_id + }).user_data.to_h[:value] + + # don't save non-string user_data + if user_data_raw + user_data = Base64.decode64(user_data_raw) + + if user_data.force_encoding('UTF-8').ascii_only? + struct.user_data = user_data + end + end + end + resources.push(struct.to_h) end end end