Network tags in GCP are used to apply firewall rules and network routes to instances. To add or remove network tags for a Compute Engine instance, follow these steps:
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 instance for which you want to add or remove network tags.
d. Click on the “Edit” button at the top of the instance details page.
e. Scroll down to the “Network tags” section.
f. To add a network tag, type the tag name in the text box and press Enter.
g. To remove a network tag, click the “x” next to the tag name.
h. Click the “Save” button at the bottom of the page.
2. Using gcloud CLI:
First, make sure you have the Google Cloud SDK (https://cloud.google.com/sdk/docs/install) installed.
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
Replace PROJECT_ID
with your project ID.
d. To add a network tag, run the following command:
gcloud compute instances add-tags INSTANCE_NAME --tags TAG_NAME --zone ZONE
e. To remove a network tag, run the following command:
gcloud compute instances remove-tags INSTANCE_NAME --tags TAG_NAME --zone ZONE
Replace INSTANCE_NAME
, TAG_NAME
, and ZONE
with appropriate values.
3. Using Terraform:
To add or remove network tags using Terraform, modify the tags
attribute in the google_compute_instance
resource block in your main.tf
file:
resource "google_compute_instance" "example" {
# ... other configuration ...
tags = ["TAG1", "TAG2", "TAG3"] # Add or remove tags as needed
# ... other configuration ...
}
Replace TAG1
, TAG2
, TAG3
with your desired network tags.
After modifying the tags
attribute, run the following commands:
a. Review the execution plan:
terraform plan
b. Apply the changes:
terraform apply
This will update the existing instance with the new network tags. Note that modifying network tags in Terraform may cause the instance to be recreated, depending on your configuration.
Leave a Reply