Here’s how to get Regional Quotas for your project in GCP.
gcloud compute regions describe us-central1 --project your-project-id |
cloud engineer
Here’s how to get Regional Quotas for your project in GCP.
gcloud compute regions describe us-central1 --project your-project-id |
gcloud compute regions describe us-central1 --project your-project-id
You can monitor the success or failure of a service account in GCP.
gcloud policy-intelligence query-activity \ --activity-type=ACTIVITY_TYPE \ --project=PROJECT_ID \ --limit=LIMIT |
gcloud policy-intelligence query-activity \ --activity-type=ACTIVITY_TYPE \ --project=PROJECT_ID \ --limit=LIMIT
The two options you can use for ACTIVITY_TYPE are:
Instead of the GCP Console, you can reset Windows Server password via gcloud.
gcloud compute reset-windows-password server-name \ --zone us-central1-a \ --project project-id |
gcloud compute reset-windows-password server-name \ --zone us-central1-a \ --project project-id
Username and password will generated.
I’m having trouble logging in using Google SDK Compute SSH on a Mac Terminal.
Here’s the fix.
gcloud compute ssh USERNAME@SERVER --zone ZONE --project PROJECTID --internal-ip 2>&1 |
gcloud compute ssh USERNAME@SERVER --zone ZONE --project PROJECTID --internal-ip 2>&1
There was an issue with a redirect to another shell.
How to reset password of a GCP Compute Engine running on Windows OS.
gcloud compute reset-windows-password servername \ --zone us-central1-a \ --project your-project-id |
gcloud compute reset-windows-password servername \ --zone us-central1-a \ --project your-project-id
Output
This command creates an account and sets an initial password for the user [firstname_lastname] if the account does not already exist. If the account already exists, resetting the password can cause the LOSS OF ENCRYPTED DATA secured with the current password, including files and stored passwords. For more information, see: https://cloud.google.com/compute/docs/operating-systems/windows#reset Would you like to set or reset the password for [firstname_lastname] (Y/n)? y Resetting and retrieving password for [firstname_lastname] on [servername] Updated [https://www.googleapis.com/compute/v1/projects/your-project-id/zones/us-central1-a/instances/servername]. WARNING: Instance [servername] does not appear to have an external IP address, so it will not be able to accept external connections. To add an external IP address to the instance, use gcloud compute instances add-access-config. password: xxxxxxxxxxxxxxx username: firstname_lastname |
This command creates an account and sets an initial password for the user [firstname_lastname] if the account does not already exist. If the account already exists, resetting the password can cause the LOSS OF ENCRYPTED DATA secured with the current password, including files and stored passwords. For more information, see: https://cloud.google.com/compute/docs/operating-systems/windows#reset Would you like to set or reset the password for [firstname_lastname] (Y/n)? y Resetting and retrieving password for [firstname_lastname] on [servername] Updated [https://www.googleapis.com/compute/v1/projects/your-project-id/zones/us-central1-a/instances/servername]. WARNING: Instance [servername] does not appear to have an external IP address, so it will not be able to accept external connections. To add an external IP address to the instance, use gcloud compute instances add-access-config. password: xxxxxxxxxxxxxxx username: firstname_lastname
How to add a second drive on GCP Compute Engine using Terraform.
provider "google" { project = "your-project-id" zone = "us-central1-c" } resource "google_compute_disk" "data-drive" { name = "data-drive" type = "pd-standard" zone = "us-central1-c" size = "20" } resource "google_compute_attached_disk" "attach-data-drive" { count = 1 disk = google_compute_disk.data-drive.id instance = google_compute_instance.test.id } resource "google_compute_instance" "test" { name = "test" machine_type = "e2-micro" boot_disk { initialize_params { image = "rocky-linux-cloud/rocky-linux-8" } } scheduling { preemptible = true automatic_restart = false } network_interface { network = "default" access_config { } } } |
provider "google" { project = "your-project-id" zone = "us-central1-c" } resource "google_compute_disk" "data-drive" { name = "data-drive" type = "pd-standard" zone = "us-central1-c" size = "20" } resource "google_compute_attached_disk" "attach-data-drive" { count = 1 disk = google_compute_disk.data-drive.id instance = google_compute_instance.test.id } resource "google_compute_instance" "test" { name = "test" machine_type = "e2-micro" boot_disk { initialize_params { image = "rocky-linux-cloud/rocky-linux-8" } } scheduling { preemptible = true automatic_restart = false } network_interface { network = "default" access_config { } } }
How to create scheduled snapshots in GCP.
gcloud compute resource-policies create snapshot-schedule hourly \ --description "my hourly schedule" \ --max-retention-days 7 \ --start-time 00:00 \ --hourly-schedule 1 \ --region us-central1 \ --on-source-disk-delete keep-auto-snapshots \ --storage-location US |
gcloud compute resource-policies create snapshot-schedule hourly \ --description "my hourly schedule" \ --max-retention-days 7 \ --start-time 00:00 \ --hourly-schedule 1 \ --region us-central1 \ --on-source-disk-delete keep-auto-snapshots \ --storage-location US
Add snapshot schedule to a disk.
gcloud compute disks add-resource-policies disk-name \ --resource-policies hourly \ --zone us-central1-a |
gcloud compute disks add-resource-policies disk-name \ --resource-policies hourly \ --zone us-central1-a
gcloud compute disks create disk-name \ --resource-policies hourly \ --zone us-central1-a |
gcloud compute disks create disk-name \ --resource-policies hourly \ --zone us-central1-a
List snapshot schedules.
gcloud compute resource-policies list |
gcloud compute resource-policies list
Describe snapshot schedule.
gcloud compute resource-policies describe hourly |
gcloud compute resource-policies describe hourly
How to add a startup-script to metadata. The script executes every time VM is started.
gcloud compute instances add-metadata instance-name \ --project your-project-id \ --zone us-central1-c \ --metadata=startup-script='#! /bin/bash sudo -i echo "Time: $(date)" >> /tmp/date.txt' |
gcloud compute instances add-metadata instance-name \ --project your-project-id \ --zone us-central1-c \ --metadata=startup-script='#! /bin/bash sudo -i echo "Time: $(date)" >> /tmp/date.txt'