How do I manage GCP Cloud Asset Inventory with Pulumi?
In this guide, we will demonstrate how to manage Google Cloud Asset Inventory using Pulumi. We’ll create a Cloud Asset Inventory feed that allows you to monitor and manage your cloud resources effectively.
The resources involved include:
gcp.cloudasset.ProjectFeed
: Used to create an asset feed for a specific project.
Below is a Pulumi program written in TypeScript that sets up a Cloud Asset Inventory feed in GCP.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Define the project and feed ID
const projectId = "your-gcp-project-id";
const feedId = "my-asset-feed";
// Define the Pub/Sub topic to which the feed will publish updates
const topic = new gcp.pubsub.Topic("asset-feed-topic");
// Create a Cloud Asset Inventory feed
const assetFeed = new gcp.cloudasset.ProjectFeed("assetFeed", {
feedId: feedId,
project: projectId,
assetNames: [
`//cloudresourcemanager.googleapis.com/projects/${projectId}`,
],
assetTypes: [
"compute.googleapis.com/Disk",
"compute.googleapis.com/Instance",
],
contentType: "RESOURCE",
feedOutputConfig: {
pubsubDestination: {
topic: topic.id,
},
},
});
// Export the topic name and feed name
export const topicName = topic.name;
export const feedName = assetFeed.name;
Key Points:
- Project ID: Replace
your-gcp-project-id
with your actual GCP project ID. - Feed ID: The
feedId
is a unique identifier for the feed. - Pub/Sub Topic: The feed will publish updates to this Pub/Sub topic.
- Asset Names and Types: Specify the assets and types you want to monitor.
- Content Type: Set to
RESOURCE
to monitor resource changes.
Summary:
In this guide, we created a Cloud Asset Inventory feed in GCP using Pulumi. This feed monitors specific asset types and publishes updates to a Pub/Sub topic. This setup is essential for effective cloud resource management and monitoring.
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.