An organization wants to automatically stop running Compute Engine instances in a specific Google Cloud project whenever project spending exceeds 100% of its designated monthly budget limit. You need to design an automated cost-control workflow while accounting for GCP billing budget capabilities and limitations. Which implementation strategy should you choose?
- Configure the Cloud Billing budget to publish alert notifications to a Cloud Pub/Sub topic, subscribe a Cloud Function that executes Compute Engine stop API calls upon receiving budget messages, and account for eventual consistency since billing data processing includes an inherent reporting latency.Answer
- BEnable the direct resource termination toggle under the Cloud Billing Budget threshold rules configuration tab, specifying the compute project ID and selecting automatic instance termination upon hitting the 100% threshold.
- CGrant the Project Editor role to the Billing Account administrator, enable automatic spending caps on the Billing Account settings page, and configure budget alert emails to trigger automatic instance caps via Google Cloud Support.
- DConfigure standard BigQuery billing export in the target compute project, enable the Cloud Billing API in that same project, and set up a BigQuery event trigger to directly stop Compute Engine instances in real time when cumulative cost rows exceed the threshold.
Answer
Publish Cloud Billing budget alert notifications to a Cloud Pub/Sub topic, subscribe a Cloud Function to execute Compute Engine stop API calls upon notification, and account for reporting latency.
The correct strategy requires recognizing that Google Cloud billing budgets do not natively stop resources or cap costs. To achieve automated cost control, budget alerts must publish messages to a Cloud Pub/Sub topic, which triggers a serverless function (such as Cloud Functions) to invoke Compute Engine APIs to halt running instances. Additionally, billing data processing involves inherent latency, so automated remediation is asynchronously executed rather than instantaneous.
Step-by-Step Solution
Key Concept
Automated Budget Notification Handling via Pub/Sub and Cloud Functions