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
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!
Most helpful comment
The better solution seems to be to set the
GOOGLE_PROJECTor equivalent environment variable before runningterraform import: