Google Cloud Platform - Specifying Project Name - deployment

I am trying to follow Google's instructions on deploying a Cloud Function from the command line. I cloned their sample project, but when I used gcloud functions deploy to deploy it, it complained that it failed to find attribute [project]. I had to provide that manually.
Where in their docs to they talk about setting the project attribute? I must've missed it, and it seems pretty important ...

This answer is in addition to #Kolban.
You can modify your gcloud settings at any time. Here are some common ones:
gcloud config set core/project my-project-id
gcloud config set compute/region us-central1
To list your projects:
gcloud projects list
To see your current settings:
gcloud config list
To see your authorization settings:
gcloud auth list
Then there are settings for individual services such as Cloud Run:
gcloud config set run/region us-central1
To get help to see the vast number of settings available:
gcloud config --help
All of this is documented. Just put a command into Google and a document link will appear. For example put this string into Google: "gcloud compute instances create". The first link takes you to the command documentation.

When you install the Google Cloud SDK (which provides the gcloud command), you have the opportunity to create one or more configurations (including the default). Think of these as "profiles" for your interaction with GCP. A configuration includes:
Your identity
Your default project
Your default region/zone
See the following article:
Initializing Cloud SDK
It sounds like you either didn't run gcloud init or didn't identify a project you wanted to use when you did run it. When you subsequently run gcloud commands and don't specify a project, then the current configuration project will be used. If you didn't set one, then that would explain the error encountered.

Related

Where I can see "set context" for change kubernetes namespace in Intellij IDEA?

In official tutorial saying about changing namespace by cliking on namespace item and set context
But I can't see in my version 2020.3
A namespace is a part of a Kubernetes context, other ones are cluster and user credentials. So essentially a Kubernetes context is a shortcut which gives you a quick access to a namespace in your cluster. For the screenshot you posted, default namespace has a context created for it (usual scenario), but other namespaces do not have a context.
If you want to create a context for another namespace, please use kubectl config set-context command in a terminal. Cloud Code doesn't support this operation via UI or Kubernetes Explorer since it's normally rarely used. Contexts are normally created automatically when you start a cluster like minikube or GKE.
Note that for the Kubernetes plugin (which I prefer over the google cloud intellij plugin) you can change the kubernetes context in the Services section by right clicking the current context you're on, selecting contexts from the dropdown menu and picking one of the contexts listed there:
You'll have to add your google-cloud cluster to your local kubectl's contexts by updating your local ~/.kube/config file as explained in the Google Cloud documentation.
Note that changing contexts from the command line will not update IntelliJ, you have to do it from that menu. I'm using Intellij IDEA 2022.1 Ultimate Edition

Is it possible to auto select different "gcloud" configs for different projects in multiple workspaces / folders ? Gcloud on multiple projects

From this question and this article we get that is possible to create multiple configs for the gcloud SDK.
But it seems that you have to manually switch between then, by running:
gcloud config configurations activate <CONFIG_NAME>
But is there a way for each config to be automatically selected whenever I open up a project workspace/folder on VSCode? How can I do this?
I've just tested activating a new config on a different VSCode project. That seems to update it globally. Now, all of my VSCode windows (different projects) are seeing the same activated config.
Isn't it dangerous? I mean, I could be uploading stuff to the cloud on a different project that I'm not aware of. How do people usually handle this? Do I need to run the activate command on every script before deploying something?
Unfortunately, I am not aware of such a possibility, however I have found something interesting that may help you. There is following extension:
GCP Project Switcher
The extension only allows you to change projects, however as I looked into the code it is running gcloud set config project command under the hood. You could raise a request to add the possibility to change the whole configuration to the instead of project only, as it is a very similar approach.

Setting GCloud SDK properties through environment variables

I'm trying to configure properties for the Google Cloud SDK in a non-interactive environment (specifically, a Docker container), and I'd like to use environment variables to do it (because it seems much simpler to get right and portable compared to volume-mounting config files...). However, I can't find any documentation on what the environment variables should be called, etc.
Is it possible to configure the Google Cloud SDK using environment variables, and how do I do so?
Clarification: For now, the only property I care about is the default project, core/project in this listing.
There is a set of environment variables (CLOUDSDK_) that match some (all?) of the gcloud config properties.
I was unable to find these documented but I'm aware of them through the kubectl Cloud Builder (see here) and this post
I've submitted an issue asking Google to document these (more clearly).

Opensuse Images No Longer Visible in Default Compute Instance

All,
Opensuse Images are not listed as Active in GCloud but are showing up in the gloud commands in my project.... the Opensuse project is not mine... can I link to someone else's
[Gcloud shell output
My apologies I found a suitable answer:
Is it possible in google cloud web client to create an instance from image in different project?
The Command syntax is from the Gloud Shell is:
gcloud compute instances create production-instance-from-staging-image --image staging-image-1 --image-project staging-project
For Opensuse you have to link to their staging project which is opensuse-project which includes the images. The exact command is attached.....
enter image description here
The Original Question is how to build Gcloud Instances on OpenSUSE with the Console. It used to be a default option in each project.
To achieve this you have to do two things:
1) Find the Opensuse Projects which are in fact documented in Google's online support but requires a gloud command to find the specific images.
The command is :
gloud compute images list --project opensuse-cloud --no-standard-images
2) You have to specifically provision to your project from the opensuse-cloud project
gcloud compute instances create your-instancename --image image-namefrom#1 --image-project opensuse-cloud

"No project ID could be determined from the Cloud SDK configuration" when running psqworker

When I was going through the Google Cloud tutorial: https://cloud.google.com/python/getting-started/using-pub-sub#running_the_app_on_your_local_machine
I got the following error:
google.auth._default No project ID could be determined from the Cloud SDK configuration. Consider running gcloud config set project or setting the GOOGLE_CLOUD_PROJECT environment variable
I did 'gcloud config set project [my project name]' with no success.
What's the problem?
Update: I've deployed app engines previously without any problem. The problem only happens when I run the psqworker for this Pub/Sub function. I know my project ID and used it before.
The first thing I would try would be:
gcloud info
This will tell you the account and project that gcloud is currently set to.
You may also find the available projects for your account with the following gcloud command:
gcloud projects list
Locate the project ID and project number
There are two ways to identify your project: the project number and project ID.
The project number is automatically assigned when you create a project.
The project ID is a unique identifier for a project. When you first create a project, you can accept the default generated project ID or create your own. A project ID cannot be changed after the project is created, so if you are creating a new project, be sure to choose an ID that you'll be comfortable using for the lifetime of the project.
Note: You should be aware that some resource identifiers (such as project IDs) might be retained beyond the life of your project. For
this reason, avoid storing sensitive information in resource
identifiers.
To locate your project ID and project number:
Go to the Cloud Platform Console
From the projects list, select the name of your project.
On the left, click Dashboard. The project name and ID are displayed in the Dashboard.
TL;DR
Use virtualenv -p C:/Python27/python.exe name-of-env instead of virtualenv -p C:/Python36/python.exe name-of-env in the tutorial
I ran into a similar issue. Here are the steps I went through and why. Hope it helps!
First I tried to specify the id with the command gcloud config set project name-of-your-project
This resulted in the error
ERROR: Python 3 and later is not compatible with by the Google Cloud SDK. Please use a Python 2.7.x version.
If you have a compatible Python interpreter installed, you can use it by setting
the CLOUDSDK_PYTHON environment variable to point to it.
I thought this error was weird because the tutorial tells you to use python3 but it doesn't work. So I created a virtualenv with python2.7 like so
virtualenv -p C:/Python27/python.exe name-of-env (I have python 2 and 3 so its easier to specify the whole path to the .exe file)
Then follow the rest of the tutorial with
name-of-env\scripts\activate
pip install -r requirements.txt
Don't know why you have to use python3 when it doesn't even work.