# Using with\_items with ec2\_vpc subnets

**URL:** <https://forum.ansible.com/t/using-with-items-with-ec2-vpc-subnets/16738>\
**Category:** Ansible Project\
**Created:** [November 10, 2014, 9:42pm UTC](https://forum.ansible.com/t/using-with-items-with-ec2-vpc-subnets/16738 "2014-11-10T21:42:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ringo](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Steven\_Ringo](https://forum.ansible.com/u/Steven_Ringo)\
**Post date:** [November 10, 2014, 9:42pm UTC](https://forum.ansible.com/t/using-with-items-with-ec2-vpc-subnets/16738/1 "2014-11-10T21:42:18Z")

</div>

Hi,

The `ec2_vpc` module is used to create/change both VPCs and its subnets.

A `with_items` iterator on `ec2_vpc`, as expected, will call `ec2_vpc` as many times as there are items in the loop.

This means there is no way to add a `with_items` to the `subnets` parameter inside `ec2_vpc`

It is possible to create `subnets` variable independently from the call to `ec2_vpc`, and use that, however I am struggling to create the list I need:

I have something like:

Variables:

```auto
    - stack: "atlas"
    - env: "dev"
    - app: "core"
    - visibility: "private"
    - subnet_parameters:
        - cidr: "10.220.220.0/24"
          availability_zone: "ap-southeast-2a"
          suffix: "A"
        - cidr: "10.220.221.0/24"
          availability_zone: "ap-southeast-2b"
          suffix: "B"

```

Any idea on how would I be able to generate something like this, from those variables? `set_fact` seems as if its not designed for loops?

```auto
  - module or something else here?
    - cidr: "{{ item.cidr }}"
      az: "{{ item.availability_zone }}"
      resource_tags:
        Name: "{{ app }} {{ stack }} {{ env }} {{ item.suffix }} subnet",
        stack: "{{ stack }}",
        environment: "{{ env }}",
        application: "{{ app }}",
        visibility: "{{ visibility }}"
      with_items: "{{ subnet_parameters }}"

```

Thanks so much,

Steve
