Task Description: We have a Google Cloud Platform (GCP) project where we need to monitor the IP address utilization of our subnets continuously. The Network Analyzer tool in GCP provides insights on the subnet allocation ratios and priorities. We want to create a solution that retrieves this data, sends metrics to Cloud Monitoring, and creates an alarm to alert us when the IP utilization reaches a certain threshold.
The solution should include:
- A Cloud Function (or any other suitable GCP service) that periodically retrieves the subnet data and allocation ratios from the Network Analyzer API.
- The Cloud Function should process the retrieved data and send custom metrics to Cloud Monitoring, including the subnet name, allocation ratio, and priority.
- An alert policy should be created in Cloud Monitoring to monitor the custom metrics and trigger an alarm when the allocation ratio exceeds a specified threshold (e.g., 75%) or when the priority changes from LOW or MEDIUM to HIGH or CRITICAL.
- The solution should be implemented using Infrastructure as Code (IaC) principles, preferably using Terraform or Google Cloud Deployment Manager. The IaC script should provision the necessary resources, such as the Cloud Function, Cloud Monitoring metrics, and alert policy.