오늘은 필요에 따라 또 다른 IaaC(Infrastructure as Code)를 작성했다. Amazon Web Services(AWS)와 Google Cloud Platform(GCP) 간에 안전한 VPN 연결(IPsec)을 생성할 수 있다.

이게 무엇을 할 수 있는가?

AWS에 Customer Gateway 생성. AWS에 Virtual Private Gateway 생성. AWS에 Site-to-Site VPN Connection 생성. AWS에 VPN 연결 접근을 위한 Security Group 생성. GCP에 VPN 연결용 External IP 주소 생성. GCP에 VPN 연결용 방화벽 규칙 관리. GCP에 Route Rule 생성.

요구사항

사용법

  1. 리포지토리 클론

    git clone git@github.com:flightlesstux/aws-to-gcp-vpn-w-terraform.git

  2. Google SDK가 설치되지 않았더라도 Google Platform에 인증. CI/CD 파이프라인에 정말 유용하다! 이미 gcloud auth login과 같이 Google Cloud Platform 프로젝트에 로그인했다면 이 단계를 건너뛸 수 있다.

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

  3. Project ID도 Terraform을 통해 선언되지만, 값을 export하지 않으면 아래와 같은 오류가 발생할 수 있다.

    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. AWS Region에 리소스를 생성하기 위해 AWS Access Key ID와 Secret Access Key를 Export.

    AWS_ACCESS_KEY_ID=AKIA1SFAESADASFASR5D
    AWS_SECRET_ACCESS_KEY=Aasdfiajfar1O9DFASDAA3rasdas02304adsq9re


  5. 변수 설정

    variables.tf의 값 편집

  6. State 버킷 설정

    state.tf 파일을 통해 Terraform state 버킷 설정. AWS S3 또는 Google Cloud Storage를 사용할 수 있다.

  7. 초기화

    terraform init

  8. 배포!

    terraform apply 또는 terraform apply -auto-approve

리포지토리 주소

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

이 글이 도움이 되었길 바란다...