Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Terraform/GCP Error: project: required field is not set

Problem

The google_project document says the project_id is optional.

project_id – (Optional) The project ID. If it is not provided, the provider project is used.

However, Terraform complains it is required.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

gcp.tf

data "google_project" "project" {
}

output "project_number" {
  value = data.google_project.project.number
}
 Error: project: required field is not set
│ 
│   with data.google_project.project,
│   on gcp.tf line 1, in data "google_project" "project":
│    1: data "google_project" "project" {

Question

Please help understand if this is a documentation defect and the argument is mandatory actually.

Workaround

Set the GOOGLE_PROJECT environment variable.

export GOOGLE_PROJECT=...
terraform apply

>Solution :

Your ‘Workaround’ is functionally equivalent to what the documentation suggests. Namely that the provider project should be set, i.e.:

provider "google" {
  project = "..."
}

You don’t include your provider config but, I assume, it doesn’t include the default project to be used.

So, either|or but, somewhere you need to define the default project.

Otherwise, you should expect to get the error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading