Terraform v0.11.13
google_compute_router_nat
resource "google_compute_router_nat" "nat-gateway" {
project = "project_name"
}
https://gist.github.com/ricosega/0b038513447d32312f563b152b52a0eb
Import the state in the state file
Prompting error and not saving it to state file.
terraform import google_compute_router_nat.nat-gateway us-west2/core-router/nat-gatewayHey @ricosega! terraform import doesn't actually pull information from the config; instead, the project is inferred from the default value defined in your provider block / by an env var.
I am not sure that is the problem, because I have been able to import any other resources but not this one.
And the error is the following where you can see that first it correctly imports the resource but then it fails when trying to refresh state:
google_compute_router_nat.nat-gateway: Importing from ID "us-west2/core-router/nat-gateway"...
google_compute_router_nat.nat-gateway: Import complete!
Imported google_compute_router_nat (ID: us-west2/core-router/nat-gateway)
google_compute_router_nat.nat-gateway: Refreshing state... (ID: us-west2/core-router/nat-gateway)
Error: google_compute_router_nat.nat-gateway (import id: us-west2/core-router/nat-gateway): 1 error(s) occurred:
* import google_compute_router_nat.nat-gateway result: us-west2/core-router/nat-gateway: google_compute_router_nat.nat-gateway: project: required field is not set
I just had this problem. This particular import does not allow to pass the project via the id, like {project}/{region}/{router}/{nat}, while others (all the ones I imported so far) support that.
The fix like mentioned above by @rileykarson is to force some project, in my case I did:
GOOGLE_PROJECT=my-project-id terraform import google_compute_router_nat.nat-name region/router-name/nat-name
Project can be specified explicitly on the resource at import-time beginning with 2.8.0.
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!