1. Answers
  2. Creating a GCP Compute Disk with Pulumi

How do I create a GCP compute disk with Pulumi?

In this guide, we will create a Google Cloud Platform (GCP) Compute Engine disk using Pulumi. We will define the disk’s properties such as name, size, type, and zone. This disk can be attached to a virtual machine instance later.

Key Points:

  • We will use the @pulumi/gcp package to interact with GCP resources.
  • The disk will be defined with a specific name, size, type, and zone.
  • This example assumes you have already configured Pulumi to use GCP.

Below is the TypeScript code to create a GCP compute disk:

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

// Define the GCP compute disk
const computeDisk = new gcp.compute.Disk("my-compute-disk", {
    name: "my-compute-disk",
    size: 50, // Size in GB
    type: "pd-standard", // Disk type: pd-standard, pd-ssd, etc.
    zone: "us-central1-a", // Zone where the disk will be created
});

// Export the URL of the created disk
export const diskSelfLink = computeDisk.selfLink;

Explanation:

  1. Importing Pulumi and GCP packages: We import the necessary Pulumi and GCP packages to interact with GCP resources.
  2. Defining the Compute Disk: We create a new gcp.compute.Disk resource with specified properties:
    • name: The name of the disk.
    • size: The size of the disk in GB.
    • type: The type of the disk, such as pd-standard or pd-ssd.
    • zone: The zone where the disk will be created.
  3. Exporting the Disk SelfLink: We export the selfLink of the created disk, which is a URL that can be used to reference the disk.

Summary:

We successfully created a GCP Compute Engine disk using Pulumi. The disk is defined with specific properties and can be attached to a VM instance as needed. This demonstrates how to use Pulumi to manage GCP resources programmatically.

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