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:
- Importing Pulumi and GCP packages: We import the necessary Pulumi and GCP packages to interact with GCP resources.
- 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 aspd-standard
orpd-ssd
.zone
: The zone where the disk will be created.
- 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 upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.