DEV Community

Discussion on: Automate AWS security group with CloudFlare IPs

Collapse
 
deanhtid99 profile image
Dean Whittaker  🦈

Hi John,

I know this is quite an old post and I may not get a reply but going to try anyway.

I can get this working, but it only writes one ip address for each port. Do you have any idea why that may be?

The JSON has multiple IP's but only one writes to the security group. Struggling to figure this one out.

Any help will be much appreciated

Thanks

Dean

Collapse
 
yebowhatsay profile image
yebowhatsay • Edited

Dean

There is an error in the code at github.com/johnmccuk/cloudflare-ip...

Code

  ## IPv4
    # add new addresses
    for ipv4_cidr in ip_addresses['ipv4_cidrs']:
        for port in ports:
            if not check_ipv4_rule_exists(current_rules, ipv4_cidr, port):
                add_ipv4_rule(security_group, ipv4_cidr, port)

needs changing to

     ## IPv4
    # add new addresses
    for port in ports:
        for ipv4_cidr in ip_addresses['ipv4_cidrs']:
            if not check_ipv4_rule_exists(current_rules, ipv4_cidr, port):
                add_ipv4_rule(security_group, ipv4_cidr, port)

That is, swap line 188 with 189.