Terraform-provider-google: Error importing google_compute_network/google_compute_subnetwork when project not set in provider

Created on 25 Jan 2018  ·  4Comments  ·  Source: hashicorp/terraform-provider-google

I don't have project set in my google provider (either explicitly or implicitly via environment variable) and want to import networks and subnets via terraform import:

terraform import google_compute_network.net net-xxxxxx
google_compute_network.net: Importing from ID "net-xxxxxx"...
google_compute_network.net: Import complete!
  Imported google_compute_network (ID: net-xxxxxx)
google_compute_network.net: Refreshing state... (ID: net-xxxxxx)

Error: google_compute_network.net (import id: net-xxxxxx): 1 error(s) occurred:

* import google_compute_network.net result: net-xxxxxx: google_compute_network.net: project: required field is not set
terraform import google_compute_subnetwork.subnet us-east4/subnet-xxxxxx
google_compute_subnetwork.subnet: Importing from ID "us-east4/subnet-xxxxxx"...
google_compute_subnetwork.subnet: Import complete!
  Imported google_compute_subnetwork (ID: us-east4/subnet-xxxxxx)
google_compute_subnetwork.subnet: Refreshing state... (ID: us-east4/subnet-xxxxxx)

Error: google_compute_subnetwork.subnet (import id: us-east4/subnet-xxxxxx): 1 error(s) occurred:

* import google_compute_subnetwork.subnet result: us-east4/subnet-xxxxxx: google_compute_subnetwork.subnet: project: required field is not set

Most helpful comment

The better solution seems to be to set the GOOGLE_PROJECT or equivalent environment variable before running terraform import:

GOOGLE_PROJECT=abcd1234 terraform import google_compute_network.net net-xxxxxx
GOOGLE_PROJECT=abcd1234 terraform import google_compute_subnetwork.subnet us-east4/subnet-xxxxxx

All 4 comments

It's the calls to getProject here and here that return the error.

Will need to add an additional, optional part to the ID specified to terraform import that is the project ID to handle this case.

The better solution seems to be to set the GOOGLE_PROJECT or equivalent environment variable before running terraform import:

GOOGLE_PROJECT=abcd1234 terraform import google_compute_network.net net-xxxxxx
GOOGLE_PROJECT=abcd1234 terraform import google_compute_subnetwork.subnet us-east4/subnet-xxxxxx

@ewbankkit Thanks - the above workaround was helpful. This might be worth reopening though, because this should be added to the docs: https://www.terraform.io/docs/providers/google/r/compute_network.html#import

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings