Description

Hands-on Challenge Day - Multi-Cloud Deployment with Terraform

Introduction

What is Terraform?

Terraform is an open-source infrastructure as code software tool created by HashiCorp. It allows users to define and provision a cloud infrastructure using a high-level configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. Terraform supports multiple cloud service providers, enabling a multi-cloud strategy for infrastructure management.

The Importance of Multi-Cloud Strategy

A multi-cloud strategy involves using two or more cloud computing services from different providers. This approach can help reduce reliance on any single vendor, increase flexibility through more choice, and improve redundancy and disaster recovery capabilities.

Challenge Scenario

"GlobalWeb Inc." is a digital media company that serves a global audience with high-quality content. To ensure high availability and adhere to data sovereignty regulations in different regions, GlobalWeb Inc. has decided to adopt a multi-cloud strategy, deploying resources across AWS and Google Cloud Platform (GCP).

Problem Statement: GlobalWeb Inc. needs to deploy a static website on AWS S3 and a Google Cloud Storage (GCS) bucket to serve content to users in different regions, ensuring high availability and compliance with regional data laws.

Your Mission: Use Terraform to automate the deployment of a static website on both AWS S3 and Google Cloud Storage. Ensure that the website is publicly accessible and that the deployments are managed as code for easy replication and management.

Challenge: Deploying a Static Website on AWS and GCP with Terraform

Requirements:

  1. AWS and GCP Accounts: Access to an Amazon Web Services account and a Google Cloud Platform account.
  2. Terraform Installed: Ensure Terraform is installed on your machine.

Steps:

  1. Configure Provider Credentials:

  2. Define the Infrastructure with Terraform:

    Terraform Configuration (main.tf):

    # AWS Provider Configuration
    provider "aws" {
      region = "us-east-1"
    }
    
    # GCP Provider Configuration
    provider "google" {
      credentials = file("<PATH_TO_YOUR_GCP_CREDENTIALS_JSON>")
      project     = "<YOUR_GCP_PROJECT_ID>"
      region      = "us-central1"
    }
    
    # AWS S3 Bucket for Static Website
    resource "aws_s3_bucket" "aws_static_website" {
      bucket = "globalweb-static-site-aws"
      website {
        index_document = "index.html"
        error_document = "error.html"
      }
    
      policy =<<POLICY
    {
      "Version": "2012-10-17",
      "Statement": [{
        "Sid": "PublicReadGetObject",
            "Effect": "Allow",
          "Principal": "*",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::globalweb-static-site-aws/*"
        }
      ]
    }
    POLICY
    }
    
    # GCP Cloud Storage Bucket for Static Website
    resource "google_storage_bucket" "gcp_static_website" {
      name          = "globalweb-static-site-gcp"
      location      = "US"
      force_destroy = true
      website {
        main_page_suffix = "index.html"
        not_found_page   = "error.html"
      }
    }
    
    
  3. Deploy the Infrastructure:

    terraform init
    terraform apply
    
    
  4. Prepare and Upload the Static Website:

    Sample index.html:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Welcome to GlobalWeb</title>
    </head>
    <body>
        <h1>Hello, World! Welcome to GlobalWeb Inc.</h1>
    </body>
    </html>