Skip to content
Ercan Ermis
Ercan Ermis

notes for everyone about cloud technology

  • Cloud
    • AWS
    • GCP
  • Container
    • Kubernetes
    • Docker
  • Linux
  • DevOps
  • Privacy Policy
  • Contact
Ercan Ermis

notes for everyone about cloud technology

Connect your AWS to GCP with Terraform via IPSec Site-to-Site VPN

Ercan, May 4, 2021May 4, 2021

Today, I wrote another IaaC (infrastructure as a code) for my needs. You can create a secure VPN connection (IPsec) between Amazon Web Services (AWS) and Google Cloud Platform (GCP).

What can this do?

Creating a Customer Gateway on AWS. Creating a Virtual Private Gateway on AWS. Creating a Site-to-Site VPN Connection on AWS. Creating a Security Group for VPN connection access on AWS. Creating an External IP address for VPN connection on GCP. Creating a Managing the firewall rule for VPN connection on GCP. Creating a Route rule on GCP.

Requirements

  • Enable Compute Engine API if doesn’t enable.
  • Create a Service account with Editor role (or whatever you want) and export the key file.
  • Create Cloud Google Storage Bucket to keep the terraform state. If you want, you can add your service account as a member to the bucket OR Create S3 Bucket to keep the terraform state.
  • Check your IAM Permissions on the AWS side.

Usage

  1. Clone the repositry

    git clone [email protected]:flightlesstux/aws-to-gcp-vpn-w-terraform.git

  2. Authenticate to Google Platform if even google-sdk is not installed. It’s really useful for CI/CD pipelines! If you already logged in to your Google Cloud Platform project like gcloud auth login, you can skip this step.

    export GOOGLE_APPLICATION_CREDENTIALS="service-account-key.json"

  3. Project ID is also declared via terraform but if you don’t export the value, you will probable get an error like below.

    export GOOGLE_PROJECT="0123456789012"

    │ Error: project: required field is not set
    │
    │ with google_compute_instance_group_manager.this,
    │ on group_manager.tf line 1, in resource "google_compute_instance_group_manager" "this":
    │ 1: resource "google_compute_instance_group_manager" "this" {



  4. Export your AWS Access Key ID and Secret Access Key to create a resource in your AWS Region.

    AWS_ACCESS_KEY_ID=AKIA1SFAESADASFASR5D
    AWS_SECRET_ACCESS_KEY=Aasdfiajfar1O9DFASDAA3rasdas02304adsq9re


  5. Set your variables

    Edit values for variables.tf

  6. State bucket settings

    Set your terraform state bucket via state.tf file. You can use AWS S3 or Google Cloud Storage.

  7. Initialize

    terraform init

  8. Deploy!

    terraform apply or terraform apply -auto-approve

Repository Address

https://github.com/flightlesstux/aws-to-gcp-vpn-w-terraform

I hope, you enjoyed with this article…

Share on Social Media
x facebook linkedin reddit
AWS GCP amazon web servicesawsgcpgoogle cloud platformipsecsecurityvpnvpn tunnel

Post navigation

Previous post
Next post
  • AWS (45)
    • Serverless (4)
  • Best (9)
  • DevOps (16)
  • Docker (10)
  • GCP (3)
  • Kubernetes (3)
  • Linux (13)
  • Uncategorized (6)

Recent Posts

  • Automating AWS CloudWatch Log Group Tagging with Python and Boto3
  • Automating AWS ECR Tagging with Python and Boto3
  • Automating ECR Image Cleanup with Bash
  • Update ECR Repositories with Bash Script
  • Why Automated Tests Are Essential in Your CI/CD Pipeline and Development Flow
  • Streamline Your AWS ECR Management with This Powerful Bash Script
  • Setting up DKIM for Google Workspace (Gmail) using Terraform and AWS Route 53
  • Automate AWS Site-to-Site VPN Monitoring
  • Optimizing Docker Images: Tips for Reducing Image Size and Build Time
  • Monitoring EC2 Disk Space with a Simple Bash Script and Slack Alerts
  • Securing Docker Containers: Best Practices for Container Security
  • Mastering Dockerfile: Writing Efficient, Scalable Container Builds
  • Migrating a Git Repository from GitLab to GitHub with GPG-Signed Commits
  • Accessing AWS Services in Private Subnets Without 0.0.0.0/0
  • Understanding AWS Regions, Availability Zones, and VPCs: A Comprehensive Guide
©2025 Ercan Ermis | WordPress Theme by SuperbThemes