methods/ec_common.rb
# Add ingress rule to AWS EC2 security group
Add ingress rule to AWS EC2 security group
Add ingress rule to AWS EC2 security group
def add_ingress_rule_to_aws_security_group(options)
  ec2 = initiate_aws_ec2_client(options)
  prefix_list_id = get_aws_prefix_list_id(options)
  handle_output(options,"Information:\tAdding ingress rule to security group #{options['group']} (Protocol: #{options['proto']} From: #{options['from']} To: #{options['to']} CIDR: #{options['cidr']})")
  begin
    ec2.authorize_security_group_ingress({
      group_id: options['group'],
      ip_permissions: [
        {
          ip_protocol:  options['proto'],
          from_port:    options['from'],
          to_port:      options['to'],
          ip_ranges: [
            {
              cidr_ip: options['cidr'],
            },
          ],
        },
      ],
    })
  rescue Aws::EC2::Errors::InvalidPermissionDuplicate
    handle_output(options,"Warning:\tRule already exists")
  end
  return
end
def add_ingress_rule_to_aws_security_group ( options ) ec2 = initiate_aws_ec2_client ( options ) prefix_list_id = get_aws_prefix_list_id ( options ) handle_output ( options , "Information:\tAdding ingress rule to security group #{options['group']} (Protocol: #{options['proto']} From: #{options['from']} To: #{options['to']} CIDR: #{options['cidr']})" ) begin ec2 . authorize_security_group_ingress ( { group_id : options [ 'group' ] , ip_permissions : [ { ip_protocol : options [ 'proto' ] , from_port : options [ 'from' ] , to_port : options [ 'to' ] , ip_ranges : [ { cidr_ip : options [ 'cidr' ] , } , ] , } , ] , } ) rescue Aws :: EC2 :: Errors :: InvalidPermissionDuplicate handle_output ( options , "Warning:\tRule already exists" ) end return end
Add ingress rule to AWS EC2 security group
Add ingress rule to AWS EC2 security group
options
<not_specific>