Wednesday, September 17, 2025

Generative AI Deployment with Terraform

 

A Multi-Cloud Comparison

This post provides a detailed breakdown of the steps and resources required to deploy a generative AI application using Terraform, drawing on the provided Google Cloud blog post and comparing the process to Azure and AWS.

Part 1: The Google Cloud (GCP) Approach (Based on the Blog Post)

The blog post "Deploy a Generative AI Application with Terraform" focuses on using a specific set of GCP services and Terraform resources. The goal is to set up a serverless application that can interact with a large language model.

Core Services Used

  • Generative AI on Vertex AI: This is Google Cloud's fully managed platform for machine learning and AI development. It provides access to Google's foundation models.

  • Cloud Functions: A serverless compute service that allows you to run code without provisioning or managing servers. It will host the application's back-end logic.

  • Cloud Storage: Used for storing the application's code and dependencies.

Terraform Resources & Files

  • main.tf: The primary configuration file where you define all the resources.

  • google_project: Represents the GCP project.

  • google_service_account: Creates a service account for the Cloud Function to run with.

  • google_storage_bucket: Provisions the Cloud Storage bucket.

  • google_storage_bucket_object: Uploads the Cloud Function code to the bucket.

  • google_cloudfunctions2_function: Defines the Cloud Function itself, pointing to the code in the storage bucket.

  • google_cloud_run_service_iam_member: Sets the IAM policy to allow public access to the Cloud Function endpoint.

  • variables.tf: Contains all the input variables for your configuration, such as the project ID and region.

  • outputs.tf: Defines the output values, such as the URL of the deployed Cloud Function, so you can easily access them after deployment.

Deployment Steps

  1. Prerequisites:

  • Install the gcloud CLI.

  • Install Terraform.

  • Authenticate with Google Cloud using gcloud auth application-default login.

  1. Code: Create the Terraform configuration files (main.tf, variables.tf, outputs.tf) and the application code for the Cloud Function.

  2. Initialization: Run terraform init to initialize the working directory and download the necessary providers.

  3. Planning: Run terraform plan to see a preview of the infrastructure changes that will be made.

  4. Deployment: Run terraform apply to create the resources in your GCP project. Terraform will execute the plan and output the Cloud Function's URL upon completion.

Part 2: Comparison with Azure & AWS

Azure

Azure's approach to generative AI deployment with Terraform centers on its Azure AI services, particularly Azure OpenAI Service. The steps are conceptually similar but use different resources and services.

  • Generative AI Service: The primary service is Azure OpenAI Service, which provides access to models like GPT-4.

  • Serverless Compute: Azure Functions is the direct equivalent of GCP Cloud Functions.

  • Storage: Azure Blob Storage or Azure Data Lake Storage are used for storing code and data.

GCP Resource / Service

Azure Equivalent

Description

google_project

azurerm_resource_group

A logical container for all your resources.

google_storage_bucket

azurerm_storage_account

Stores your application code, model data, etc.

google_cloudfunctions2_function

azurerm_function_app

Hosts the serverless back-end code.

Vertex AI / Generative AI

azurerm_cognitive_account

The resource that provisions and manages the Azure OpenAI service.

gcloud auth

az login

The command-line tool for authenticating with the cloud provider.

AWS

AWS provides a highly flexible environment for generative AI. The approach with Terraform typically involves using a combination of services, with Amazon Bedrock often serving as the AI backbone.

  • Generative AI Service: Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models.

  • Serverless Compute: AWS Lambda is the serverless function service, analogous to Cloud Functions and Azure Functions.

  • Storage: Amazon S3 (Simple Storage Service) is the object storage service used for code, data, and model artifacts.

  • API Endpoint: Amazon API Gateway is commonly used to create a REST API endpoint for the Lambda function.

GCP Resource / Service

AWS Equivalent

Description

google_project

AWS Account/Region

The main account and a selected region to host resources.

google_storage_bucket

aws_s3_bucket

The storage service for application code and data.

google_cloudfunctions2_function

aws_lambda_function

The serverless compute service that runs the application logic.

Vertex AI / Generative AI

Amazon Bedrock (via API)

Bedrock is a service, and you'd use a Lambda function with appropriate IAM roles to interact with it via API calls.

gcloud auth

aws configure

The command-line tool for setting up authentication.

Summary of Steps Across Clouds

Step

GCP (Google Cloud)

Azure

AWS

Authentication

gcloud auth application-default login

az login

aws configure

Provider

hashicorp/google

hashicorp/azurerm

hashicorp/aws

Resource Grouping

google_project

azurerm_resource_group

N/A (Resources are in a region)

Core AI Service

google_cloudfunctions2_function

azurerm_cognitive_account

Interaction with Amazon Bedrock

Serverless Compute

google_cloudfunctions2_function

azurerm_function_app

aws_lambda_function

Storage

google_storage_bucket

azurerm_storage_account

aws_s3_bucket

IAM/Permissions

google_cloud_run_service_iam_member

azurerm_function_app_

aws_iam_role

Deployment Command

terraform apply

terraform apply

terraform apply


No comments:

Generative AI Deployment with Terraform

  A Multi-Cloud Comparison This post provides a detailed breakdown of the steps and resources required to deploy a generative AI application...