Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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
like image 788
mon Avatar asked Jan 24 '26 15:01

mon


1 Answers

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.

like image 195
DazWilkin Avatar answered Jan 29 '26 18:01

DazWilkin