Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Quick links: redhat.com, Customer Portal, Red Hat's developer site, Red Hat's partner site.

  • You are here

    Red Hat

    Learn about our open source products, services, and company.

  • You are here

    Red Hat Customer Portal

    Get product support and knowledge from the open source experts.

  • You are here

    Red Hat Developer

    Read developer tutorials and download Red Hat software for cloud application development.

  • You are here

    Red Hat Partner Connect

    Get training, subscriptions, certifications, and more for partners to build, sell, and support customer solutions.

Products & tools

  • Ansible.com

    Learn about and try our IT automation product.
  • Red Hat Ecosystem Catalog

    Find hardware, software, and cloud providers―and download container images―certified to perform with Red Hat technologies.

Try, buy, & sell

  • Red Hat Hybrid Cloud Console

    Access technical how-tos, tutorials, and learning paths focused on Red Hat’s hybrid cloud managed services.
  • Red Hat Store

    Buy select Red Hat products and services online.

Events

  • Red Hat Summit and AnsibleFest

    Register for and learn about our annual open source IT industry event.

Simplify multi-VPC connectivity with amazon.aws 9.0.0

July 2, 2025
Alina Buzachis
Related topics:
Automation and managementDeveloper ProductivitySecurity
Related products:
Red Hat Ansible Automation Platform

Share:

  • How to secure multi-VPC connectivity
  • 3-step implementation guide 
  • What's next?

In our previous articles, How to scale smarter with Ansible and amazon.aws 9.0.0 and 3 steps to secure network segmentation with Ansible Automation Platform and AWS, we explored key updates in the amazon.aws 9.0.0 Ansible collection. We have demonstrated how to automate cloud scaling and how to implement strong security and network segmentation in Amazon Web Services (AWS) environments. 

In this final article of our three-part series, we will focus on multi-Virtual Private Cloud (VPC) connectivity—a critical component for modern cloud architectures. As organizations expand their cloud environments, they often operate multiple VPCs to isolate workloads, improve security, and optimize resource management across regions. Ensuring secure and efficient communication between these VPCs, as well as with on-premise networks, is a challenge that requires a robust, automated solution.

This article will demonstrate how to automate multi-VPC connectivity using VPC peering and virtual private network (VPN) gateways, which are critical components for building scalable, secure cloud architectures.

How to secure multi-VPC connectivity

How to secure multi-VPC connectivity

Many organizations operate multiple VPCs in order to separate workloads, enhance security, or manage resources across different regions. These environments often require secure communication between VPCs and with on-premise networks. This use case demonstrates how to establish secure multi-VPC connectivity using peering, VPN gateways, and egress-only internet gateways for IPv6 traffic.

First, we create a VPC peering connection to enable private communication between two VPCs. VPC peering is a cost-effective way to connect resources without exposing them to the public internet. 

Next, we set up a VPN gateway for one of the VPCs to establish secure communication with an on-premise data center. This step is essential for hybrid cloud setups where sensitive data must be transmitted securely between the cloud and on-premise environments. 

Finally, we configure an egress-only internet gateway for IPv6 traffic within the VPC. This gateway allows instances to initiate outbound internet connections while blocking inbound traffic, enhancing security for IPv6-enabled applications. Retrieving the gateway’s details confirms that it is ready to manage outbound IPv6 traffic.

This use case showcases how to create secure and efficient multi-VPC and hybrid cloud architectures involving the following modules:

  • ec2_vpc_peering: Creates, deletes, accepts, and rejects VPC peering connections between two VPCs.

  • ec2_vpc_peering_info: Retrieves information about AWS VPC peerings.

  • ec2_vpc_vpn: Manages EC2 VPN connections.

  • ec2_vpc_vpn_info: Retrieves information about EC2 VPN connections.

  • ec2_vpc_egress_igw: Manages AWS VPC egress-only internet gateways.

  • ec2_vpc_egress_igw_info: Retrieves information about AWS VPC egress-only internet gateways.

3-step implementation guide 

3-step implementation guide 

Now that we’ve outlined the key automation modules involved in multi-VPC connectivity with peering and VPN gateways, let’s walk through the implementation of an automated, scalable, and resilient infrastructure using Ansible Automation Platform. 

This guide will explain how to:

  1. Create a VPC peering connection to enable private communication between multiple VPCs.
  2. Set Up a VPN connection to securely link the cloud environment with an on-premise network.
  3. Configure an egress-only internet gateway for secure outbound IPv6 traffic.

By following these steps, we will ensure that our infrastructure remains highly available, cost-optimized, and secure, while automating the process of establishing connectivity between VPCs and on-premise networks.

We'll break down the Ansible playbook into steps and demonstrate how each task automates and streamlines the multi-VPC connectivity setup.

1. Create VPC peering connection

The first step is to establish private communication between two VPCs using a VPC peering connection. This allows the VPCs to exchange traffic securely without the need for a public IP or internet exposure. The amazon.aws.ec2_vpc_peering module creates a peering connection between two VPCs and accepts the peering request to enable communication between the VPCs. The amazon.aws.ec2_vpc_peering_info module retrieves information about the VPC peering connections:

---
- name: Multi-VPC Connectivity with Peering and VPN Gateways
  hosts: localhost
  gather_facts: false
  tasks:
   - name: Create an EC2 VPC peering connection request
     amazon.aws.ec2_vpc_peering:
       state: present
       vpc_id: "vpc-12345678"
       peer_vpc_id: "vpc-87654321"
     register: _result_vpc_peering
   - name: Get all the EC2 VPC peering connections with specific filters
     amazon.aws.ec2_vpc_peering_info:
       filters:
         status-code: ["pending-acceptance"]
     register: _result_vpc_peering_info
   - name: Accept the EC2 VPC peering request
     amazon.aws.ec2_vpc_peering:
       peering_id: '{{ _result_vpc_peering_info.pending_vpc_peers.vpc_peering_connections[0].vpc_peering_connection_id }}'
       state: "accept"
       wait: true
Copy snippet

2. Create VPN connection 

The amazon.aws.ec2_vpc_vpn module sets up a VPN connection using the customer gateway (on-premise device) and virtual private gateway (in the VPC). This establishes a secure communication channel between the VPC and an on-premise network, which is critical for hybrid cloud scenarios where sensitive data must be transferred securely between the cloud and the data center. The community.aws.ec2_customer_gateway module allows you to manage customer gateways in AWS. Customer gateways are used in VPN connections between an AWS Virtual Private Gateway (VPG) or a transit gateway and your on-premise network. The amazon.aws.ec2_vpc_vpn_info module retrieves information about the VPN connection:

   - name: Create VPN connection
     amazon.aws.ec2_vpc_vpn:
       state: present
       customer_gateway_id: "cgw-abc123"  # The ID of the customer gateway (on-premises device)
       vpn_gateway_id: "vgw-xyz789"  # The ID of the virtual private gateway in the VPC
       static_only: false  # Indicating that BGP (dynamic routing) is used, not static routing
       tunnel_options:
         - TunnelInsideCidr: "169.254.10.0/30"  # Internal CIDR range for the VPN tunnel
           PreSharedKey: "myPreSharedKey"  # Pre-shared key for authentication
    register: _vpn_connection
   - name: Retrieve VPN connection information
     amazon.aws.ec2_vpc_vpn_info:
       filters:
         vpn-gateway-id: "{{ _vpn_connection.vpn_connection_id }}"
Copy snippet

The following are the logs of the amazon.aws.ec2_vpc_vpn_info module: 

[Partial log]
…
"vpn_connections": [
        {
            "category": "VPN",
            "customer_gateway_configuration": "<?xml version=\"1.0\" encoding=\"UTF-8\”?>\n …\n”,
            "customer_gateway_id": "cgw-abc123",
            "gateway_association_state": "associated",
            "options": {
                "enable_acceleration": false,
                "local_ipv4_network_cidr": "0.0.0.0/0",
                "outside_ip_address_type": "PublicIpv4",
                "remote_ipv4_network_cidr": "0.0.0.0/0",
                "static_routes_only": false,
                "tunnel_inside_ip_version": "ipv4",
                "tunnel_options": [
                    {
                        "log_options": {
                            "cloud_watch_log_options": {
                                "log_enabled": false
                            }
                        },
                        "outside_ip_address": "3.229.0.8",
                        "pre_shared_key": "myPreSharedKey",
                        "tunnel_inside_cidr": "169.254.10.0/30"
                    },
                    {
                        "log_options": {
                            "cloud_watch_log_options": {
                                "log_enabled": false
                            }
                        },
                        "outside_ip_address": "184.72.102.191",
                        "pre_shared_key": "2hKkGhWeDD03dxs6332EEV7gwo.CeSaJ",
                        "tunnel_inside_cidr": "169.254.193.20/30"
                    }
                ]
            },
            "routes": [],
            "state": "available",
            "tags": {},
            "type": "ipsec.1",
            "vgw_telemetry": [
                {
                    "accepted_route_count": 0,
                    "last_status_change": "2025-01-20T10:56:37+00:00",
                    "outside_ip_address": "3.229.0.8",
                    "status": "DOWN",
                    "status_message": "IPSEC IS DOWN"
                },
                {
                    "accepted_route_count": 0,
                    "last_status_change": "2025-01-20T10:56:22+00:00",
                    "outside_ip_address": "184.72.102.191",
                    "status": "DOWN",
                    "status_message": "IPSEC IS DOWN"
                }
            ],
            "vpn_connection_id": "vpn-07934309550c3a585",
            "vpn_gateway_id": "vgw-xyz789"
        }
]
Copy snippet

3. Set up egress-only internet gateway for IPv6

The amazon.aws.ec2_vpc_egress_igw module configures an egress-only gateway. This gateway is used to manage outbound IPv6 traffic from the VPC to the internet while blocking any inbound IPv6 traffic. This is critical when instances in your VPC need to access the internet (e.g., software updates, accessing public services, etc.) but you don’t want to expose them to external inbound connections over IPv6. The amazon.aws.ec2_vpc_egress_igw_info module retrieves information about the egress-only internet gateway:

   - name: Set up egress-only internet gateway for IPv6
     amazon.aws.ec2_vpc_egress_igw:
       vpc_id: "vpc-12345678"
     register: _egress_igw
   - name: Gather information about a filtered list of VPC egress only internet gateways
     amazon.aws.ec2_vpc_egress_igw_info:
       filters:
         "tag:Name": "{{ _egress_igw.gateway_id }}"
Copy snippet

The following is a sample partial log output from the amazon.aws.ec2_vpc_iwg_info module: 

[Partial log]
…
"egress_only_internet_gateways": [
        {
            "attachments": [
                {
                    "state": "attached",
                    "vpc_id": "vpc-12345678”
                }
            ],
            "egress_only_internet_gateway_id": "eigw-0e91a0f2433018227",
            "tags": {}
        }
]
Copy snippet
What's next?

What's next?

In this final article of our series, we’ve demonstrated how the latest features in the amazon.aws 9.0.0 collection empower you to automate secure and scalable multi-VPC connectivity. By leveraging VPC peering, VPN connections, and egress-only internet gateways, we’ve shown how to build efficient and secure network architectures in AWS. This automation helps to reduce manual intervention, improve scalability, and ensure robust security for cloud environments.

We hope this series has provided you with a deeper understanding of how these new modules and features can streamline the management of your AWS infrastructure. Stay tuned for future insights and tutorials on how to optimize and scale your AWS architecture with Ansible!

Looking to get started with Red Hat Ansible Automation Platform for Amazon Web Services?

  • Check out the Amazon Web Services Collection.
  • Try out our hands-on Interactive Labs.
  • Read the e-book Using automation to get the most from your public cloud.

Learn more:

  • For further reading and information, visit the other articles related to Ansible Automation Platform.
  • Check out Red Hat Summit 2025.
  • Watch the YouTube playlist for everything about Ansible Collections.
  • If you're new to Ansible automation, check out our getting started guide on developers.redhat.com.

Related Posts

  • Generate Ansible Playbooks using natural language prompts

  • How OpenShift Dev Spaces makes Ansible content testing easy

  • How Ansible Automation task scheduling improves productivity

  • How to deploy applications using Ansible Automation Platform

Recent Posts

  • Create Additional Alerts for OpenShift GitOps

  • Shape the Future of Linux: Contribute to bootc Open Source Project

  • Camel integration quarterly digest: Q2 2025

  • Optimize RHEL for edge and IoT deployments

  • Deploy ChatQnA on OpenShift with AMD Instinct

What’s up next?

Discover the basics of creating Ansible playbooks using practical examples, including key components such as plays, tasks, modules, and more in this learning path.

Start the activity
Red Hat Developers logo LinkedIn YouTube Twitter Facebook

Products

  • Red Hat Enterprise Linux
  • Red Hat OpenShift
  • Red Hat Ansible Automation Platform

Build

  • Developer Sandbox
  • Developer Tools
  • Interactive Tutorials
  • API Catalog

Quicklinks

  • Learning Resources
  • E-books
  • Cheat Sheets
  • Blog
  • Events
  • Newsletter

Communicate

  • About us
  • Contact sales
  • Find a partner
  • Report a website issue
  • Site Status Dashboard
  • Report a security problem

RED HAT DEVELOPER

Build here. Go anywhere.

We serve the builders. The problem solvers who create careers with code.

Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

Sign me up

Red Hat legal and privacy links

  • About Red Hat
  • Jobs
  • Events
  • Locations
  • Contact Red Hat
  • Red Hat Blog
  • Inclusion at Red Hat
  • Cool Stuff Store
  • Red Hat Summit
© 2025 Red Hat

Red Hat legal and privacy links

  • Privacy statement
  • Terms of use
  • All policies and guidelines
  • Digital accessibility

Report a website issue