GCP Free Learning
,

How to launch a new Compute Engine instance in GCP using Google Console/ gcloud CLI and Terraform?

by

GCP Free Learning

Here’s a detailed explanation of how to launch a new Compute Engine instance in GCP using the Console, gcloud CLI, and Terraform:

1. Using GCP Console:

a. Go to the GCP Console: https://console.cloud.google.com/

b. Navigate to Compute Engine > VM instances.

c. Click on the “Create” button to start creating a new instance.

d. Fill in the required fields such as instance name, region, zone, and machine type.

e. Choose a boot disk by clicking on the “Change” button under the “Boot disk” section. Select the desired OS image and disk size.

f. Configure additional settings like network, external IP, and firewall rules, as required.

g. Click the “Create” button to launch the instance.

2. Using gcloud CLI:

First, install the Google Cloud SDK (https://cloud.google.com/sdk/docs/install) if you haven’t already.

a. Open the terminal (Command Prompt or PowerShell on Windows, Terminal on macOS or Linux).

b. Authenticate with your Google Cloud account using the following command:

gcloud auth login

c. Set your GCP project:

gcloud config set project PROJECT_ID

d. Launch a new instance with the desired configuration:

gcloud compute instances create INSTANCE_NAME \
    --image-family IMAGE_FAMILY \
    --image-project IMAGE_PROJECT \
    --machine-type MACHINE_TYPE \
    --boot-disk-size DISK_SIZE_GB \
    --zone ZONE \
    --tags TAGS

Replace INSTANCE_NAME, IMAGE_FAMILY, IMAGE_PROJECT, MACHINE_TYPE, DISK_SIZE_GB, ZONE, and TAGS with appropriate values.

3. Using Terraform:

First, install Terraform (https://learn.hashicorp.com/tutorials/terraform/install-cli) if you haven’t already.

a. Create a new directory for your Terraform configuration:

mkdir gcp-instance
cd gcp-instance

b. Create a main.tf file with the following content:

provider "google" {
  credentials = file("<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON>")
  project     = "<YOUR_PROJECT_ID>"
  region      = "us-central1"
}

resource "google_compute_instance" "default" {
  name         = "terraform-instance"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = "default"
    access_config {
      // Ephemeral external IP
    }
  }
}

Replace <PATH_TO_YOUR_SERVICE_ACCOUNT_JSON> and <YOUR_PROJECT_ID> with appropriate values.

c. Initialize Terraform:

terraform init

d. Review the execution plan:

terraform plan

e. Apply the changes to create the instance:

terraform apply

Glance and Google’s Next-Level Gaming Recommendation Engine

Collaborative Excellence: Glance and Google’s Next-Level Gaming Recommendation Engine Introduction: In the dynamic gaming industry, personalized recommendations are crucial for..

gcp_ml gcp_ml

Digits and Google Cloud ML

How Digits is Transforming the Accounting Landscape Using Google Cloud ML The finance and accounting industry is experiencing a significant..

GCP AI GCP AI

Google Cloud’s Vertex AI Model Garden and the Launch of Generative AI Studio

Google Cloud’s Vertex AI Model Garden and the Launch of Generative AI Studio Artificial Intelligence (AI) and Machine Learning (ML)..

GCP AI/ML GCP AI/ML

Google Cloud’s Pioneering AI Models and the Launch of Generative AI Studio

 Google Cloud’s Pioneering AI Models and the Launch of Generative AI Studio Artificial Intelligence (AI) continues to break new grounds,..

GCP App Engine GCP App Engine

How to scale an App Engine application in GCP?

Scaling an App Engine application involves configuring the scaling settings in the app.yaml file and deploying the changes. I’ll provide..

Leave a Reply

Your email address will not be published. Required fields are marked *