1. Answers
  2. Enabling Cloud Run Services To Access VPC Networks

Enabling Cloud Run Services to Access VPC Networks

Introduction

In this guide, we will enable Cloud Run services to access VPC networks using Pulumi. This involves creating a VPC connector and configuring the Cloud Run service to use this connector. The key services involved are Google Cloud VPC, VPC Connector, and Cloud Run.

Step-by-Step Explanation

Step 1: Create a VPC Network

First, we need to create a VPC network. This network will be used by the VPC connector and the Cloud Run service.

Step 2: Create a VPC Connector

Next, we create a VPC connector in the specified VPC network. The VPC connector allows Cloud Run services to communicate with resources in the VPC network.

Step 3: Deploy Cloud Run Service

Finally, we deploy a Cloud Run service and configure it to use the VPC connector created in the previous step.

Conclusion

By following these steps, you can enable your Cloud Run services to access resources in your VPC networks. This setup ensures secure and private communication between your Cloud Run services and other resources in your VPC network.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

// Step 1: Create a VPC Network
const network = new gcp.compute.Network("my-vpc-network", {
    autoCreateSubnetworks: true,
});

// Step 2: Create a VPC Connector
const vpcConnector = new gcp.vpcaccess.Connector("my-vpc-connector", {
    network: network.name,
    region: "us-central1",
    ipCidrRange: "10.8.0.0/28",
});

// Step 3: Deploy Cloud Run Service
const cloudRunService = new gcp.cloudrunv2.Service("my-cloud-run-service", {
    location: "us-central1",
    template: {
        containers: [{
            image: "gcr.io/cloudrun/hello",
        }],
        vpcAccess: {
            connector: vpcConnector.id,
        },
    },
});

// Export the URL
export const cloudRunUrl = cloudRunService.uri;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up