Terraform-provider-google: import google_compute_router_nat fails

Created on 2 May 2019  ·  5Comments  ·  Source: hashicorp/terraform-provider-google


Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.11.13

  • provider.google v2.5.1

Affected Resource(s)

google_compute_router_nat

Terraform Configuration Files

resource "google_compute_router_nat" "nat-gateway" {
  project   =   "project_name"
}

Debug Output

https://gist.github.com/ricosega/0b038513447d32312f563b152b52a0eb

Expected Behavior

Import the state in the state file

Actual Behavior

Prompting error and not saving it to state file.

Steps to Reproduce

  1. terraform import google_compute_router_nat.nat-gateway us-west2/core-router/nat-gateway
bug

All 5 comments

Hey @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!

Was this page helpful?
0 / 5 - 0 ratings