Invalid value 'PROJECT' when adding RAW image to project - google-cloud-storage

$ gcloud compute images create image99 --source-uri gs://bucket99/1234z.image.tar.gz
NAME PROJECT ALIAS DEPRECATED STATUS
ERROR: (gcloud.compute.images.create) Some requests did not succeed:
- Invalid value 'PROJECT'. Values must match the following regular expression: '(?:(?:[-a-z0-9]{1,63}\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?))'
I'm using this URI scheme to add a RAW image to my project but returns the above error. I created a project and uploaded 1234z.image.tar.gz in storage -> cloud storage. How do I add the image to my project?
gs://BUCKET_NAME/IMAGE_NAME.image.tar.gz

You get this error because gcloud configuration is populated with incorrect project name. Use the following command with correct name of your project:
$ gcloud config set project PROJECT_NAME

Related

Retrieve gcloud Project createTime

I'm searching how I can get the value "createTime" for the asset type "cloudresourcemanager.Project, which to my understanding reflects the creation time for a GCP project.
This data is available on GCP following : IAM & Admin > Asset Inventory > Resource > Asset type cloudresourcemanager.Project.
I found out how to retrieve info from this specific asset type. I'm actually using the following command :
gcloud asset list --project='my-super-project' --asset-types='cloudresourcemanager.googleapis.com/Project'
But the only info I get from this command is the value of the last updateTime and I don't find out where CreateTime is registered.
Thks
As recommended by #DazWilkin.
If you are searching for Project Creation Time, the info is available using
gcloud projects describe <project_id>
--format option can help output only this value, e.g:
gcloud projects describe <project_id> --format="value(createTime)"

Invalid repository type PYTHON. Valid type is PYPI

I have created (using terraform resource google_artifact_registry_repository) a python repository on Google Artifact Registry. Here's my terraform code that created it:
resource "google_artifact_registry_repository" "pypi" {
provider = google-beta
project = var.project_id
location = var.region
repository_id = "dataplatformpypi"
description = "PyPi repo for use by dataplatform"
format = "PYTHON"
}
here is that repository:
I am now following the quickstart at https://cloud.google.com/artifact-registry/docs/python/quickstart, specifically the Configure authentication section which instructs me to issue gcloud artifacts print-settings python. I actually modify that slightly to issue:
gcloud --project myproject artifacts print-settings python --repository dataplatformpypi --location europe-west2
and I get error:
ERROR: (gcloud.artifacts.print-settings.python) Invalid repository type PYTHON. Valid type is PYPI.
I haven't specified the repository type as part of that command so I can only assume that "repository type PYTHON" refers to the format of the repository:
However given that the repository has been created successfully and PYTHON is (according to the terraform resource documentation) a valid value for the repository format I am struggling to understand what the problem is here.
I would appreciate any advice.
It doesn't appear to be a user-specific problem. Other users have also encountered the issue. There's a similar issue ongoing in GitHub. You can follow the thread here.

Error in Google Cloud Shell Commands while working on the lab (Securing Google Cloud with CFT Scorecard)

I am working in a GCP lab (Securing Google Cloud with CFT Scorecard). All instructions for the lab are given.
First I have to run the following two commands to set environment variables
export GOOGLE_PROJECT=$DEVSHELL_PROJECT_ID
export CAI_BUCKET_NAME=cai-$GOOGLE_PROJECT
In the second command given above I don't know what to replace with my own credentials? May be that is the reason I am getting error.
Now I have to enable the "cloudasset.googleapis.com" gcloud service. For this they gave the following command.
gcloud services enable cloudasset.googleapis.com \
--project $GOOGLE_PROJECT
Error for this is given in the screeshot attached herewith:
Error in the serviec enabling command
Next step is to clone the policy: The given command for that is:
git clone https://github.com/forseti-security/policy-library.git
After that they said: "You realize Policy Library enforces policies that are located in the policy-library/policies/constraints folder, in which case you can copy a sample policy from the samples directory into the constraints directory".
and gave this command:
cp policy-library/samples/storage_blacklist_public.yaml policy-library/policies/constraints/
On running this command I received this:
error on running the directory command
Finally they said "Create the bucket that will hold the data that Cloud Asset Inventory (CAI) will export" and gave the following command:
gsutil mb -l us-central1 -p $GOOGLE_PROJECT gs://$CAI_BUCKET_NAME
I am confused in where to replace my own credentials like in the place of project_Id I wrote my own project id.
Also I don't know these errors are ocurring. Kindly help me.
I'm unable to access the tutorial.
What happens if you run the following:
echo ${DEVSHELL_PROJECT_ID}
I suspect you'll get an empty result because I think this environment variable isn't actually set.
I think it should be:
echo ${DEVSHELL_GCLOUD_CONFIG}
Does that return a result?
If so, perhaps try using that variable instead:
export GOOGLE_PROJECT=${DEVSHELL_GCLOUD_CONFIG}
export CAI_BUCKET_NAME=cai-${GOOGLE_PROJECT}
It's not entirely clear to me why this tutorial is using this approach but, if the above works, it may get you further along.
We're you asked to create a Google Cloud Platform project?
As per the shared error, this seems to be because your env variable GOOGLE_PROJECT is not set. You can verify it by using echo $GOOGLE_PROJECT and seeing whether it returns the project ID or not. You could also use echo $DEVSHELL_PROJECT_ID. If that returns the project ID and the former doesn't, it means that you didn't export the variable as stated at the beginning.
If the problem is that GOOGLE_PROJECT doesn't have any value, there are different approaches on how to solve it.
Set the env variable as you explained at the beginning. Obviously this will only work if the variable DEVSHELL_PROJECT_ID is also set.
export GOOGLE_PROJECT=$DEVSHELL_PROJECT_ID
Manually set the project ID into that variable. This is far from ideal because in Qwiklabs they create a new temporal project on every lab, so this would've only worked if you were still on that project. The project ID can be seen on both of your shared screenshots.
export GOOGLE_PROJECT=qwiklabs-gcp-03-c6e1787dc09e
Avoid using the argument --project. According to the documentation, the aforementioned argument is optional and if none is used the command will take the one by default, which will be on the configuration settings. You can get the current project by using this:
gcloud config get-value project
If the previous command matches the project ID you want to use, you can simply issue the following command:
gcloud services enable cloudasset.googleapis.com
Notice that the project ID is not being explicitly mentioned using --project.
Regarding your issue with the GitHub file, I have checked the repository and the file storage_blacklist_public.yaml doesn't seem to be in the directory policy-library/samples. There seems to be a trace that it was once there, but it isn't anymore, they should probably update the lab as it isn't anymore.
About your credentials confusion, you don't have to use your own project ID, just the one given on your lab. If I recall properly all the needed data should be on the left side of the lab. Still, you shouldn't need to authenticate in a normal situation as you are already logged in your temporal project if you are accessing it form the Cloud Shell, which is where you should be doing all this.
Adding this for the later versions
in the gcloud shell you can set a temp variable for the current project id with
PROJECT_ID="$(gcloud config get-value project)"
then use like
--project ${PROJECT_ID}

Grant permissions to the service account error

Following step by step the example at,
https://cloud.google.com/text-to-speech/docs/reference/libraries#client-libraries-usage-python
on Step2, I get the following error.
D:\google-api-python\py>gcloud projects add-iam-policy-binding [my-project-for-tts] --member "serviceAccount:[tts-python-1]#[my-project-for-tts].iam.gserviceaccount.com" --role "roles/owner"
ERROR: (gcloud.projects.add-iam-policy-binding) INVALID_ARGUMENT: Request contains an invalid argument.
What argument seems to be invalid here?
My intention is to use the Text-to-Speech services by loading a custom input text file and save the output in my local disk. I installed successfully google-sdk and python.
It seems like the square brackets are the invalid argument here. Using my own service account and running your command I get the same error, but removing the the [] runs fine.
If you remove the [] then the command will work fine.
As per the Google Documentation, you need = to provide member and role value. Your command should look like below:
gcloud projects add-iam-policy-binding my-project-for-tts --member='serviceAccount:tts-python-1#my-project-for-tts.iam.gserviceaccount.com' --role='roles/owner'
Also, make sure you are using the latest gcloud package.

GCloud SDK failing to parse Policy File (JSON)

Feel like I'm missing something obvious here but I can't spot it.
I'm trying to apply an IAM Policy using JSON however gcloud seems to always try and interpret the policy file as YAML.
I've tested this with a YAML equivalent and it works. The policy.json file I'm sure is correct, I used gcloud projects get-iam-policy ${proj} to create it.
As far as I can tell I've followed the documentation for this correctly, there doesn't seem to be an extra flag or option to supply for it to read the policy as JSON.
Command:
gcloud projects set-iam-policy ${proj} policy.json
Error:
ERROR: (gcloud.projects.set-iam-policy) Failed to parse YAML from [policy.json]: while scanning for the next token found character '\t' that cannot start any token
in "policy.json", line 3, column 1
GCloud SDK Version: 228.0.0
The get-iam-policy output is in YAML format by default. To ensure you have the correct output, try the following command:
gcloud projects get-iam-policy your-project --format=json >> policy.json
This will write the output formatted to JSON in a policy.json file.