Skip to content

create an alb security group in for loop #267

@bsushant-athena

Description

@bsushant-athena
hi there, I've 10 arrays with list of IP's and I want to create a security group out of each one. I want to do this inside a for loop. i'm getting problem on the line 11...bold and added comment. Please suggest a way to achieve this

for i in 1..(10) do
	    resources (x_alb_security_group_#{i}") do
	        deletion_policy "Retain"
	        on_condition! :should_create_elb
	        type 'AWS::EC2::SecurityGroup'
	        properties do
	            group_description 'x -elb non-prod security group'
	            vpc_id attr!(:vpc_info_invoker, 'primaryVpcId')
	        end
	    end
##getting error below here >>
    **"_white_list#{i}".each_with_index do |security_ip, i|**
      resources("alb_ingress_rule_#{i}") do
        type "AWS::EC2::SecurityGroupIngress"
        properties do
          group_id ref!("x_alb_security_group_1")
          from_port 80
          to_port 80
          ip_protocol "tcp"
          cidr_ip security_ip
        end
      end
      resources("alb_ingress_rule_#{i + _white_list"#{i}".length}") do
        type "AWS::EC2::SecurityGroupIngress"
        properties do
          group_id ref!("x_alb_security_group_#{i}")
          from_port 443
          to_port 443
          ip_protocol "tcp"
          cidr_ip security_ip
        end
      end
    end
end	

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions