---
- name: Create RouteTable ( Public )
  ec2_vpc_route_table:
    region: "{{ aws_region }}"
    subnets:
      - "{{ subnet_public.results.0.subnet.id }}"
      - "{{ subnet_public.results.1.subnet.id }}"
      - "{{ subnet_public.results.2.subnet.id }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ igw.gateway_id }}"
    tags:
      Name: routing
    vpc_id: "{{ vpc.vpc.id }}"
  retries: 3
  delay: 3

- name: Create RouteTables ( Private )
  ec2_vpc_route_table:
    region: "{{ aws_region }}"
    subnets:
      - "{{ item.subnet }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ item.natgw }}"
    tags:
      Name: "{{ item.az }}"
    vpc_id: "{{ vpc.vpc.id }}"
  retries: 3
  delay: 5
  with_items:
    - az: "{{ vpc_subnet_azs.0 }}"
      subnet: "{{ subnet_private.results.0.subnet.id }}"
      natgw: "{{ natgw.results.0.nat_gateway_id }}"
    - az: "{{ vpc_subnet_azs.1 }}"
      subnet: "{{ subnet_private.results.1.subnet.id }}"
      natgw: "{{ natgw.results.1.nat_gateway_id }}"
    - az: "{{ vpc_subnet_azs.2 }}"
      subnet: "{{ subnet_private.results.2.subnet.id }}"
      natgw: "{{ natgw.results.2.nat_gateway_id }}"
