terraform-provider-google: Removed fields in state cause errors when importing as of `3.X.0`

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.12.6
+ provider.google v3.1.0
+ provider.google-beta v3.1.0

Affected Resource(s)

  • google_google_compute_network_peering

Terraform Configuration Files

resource "google_compute_network_peering" "peer_prod_qa" {
   name         = "prod-qa"
   network      = "${google_compute_network.prod.self_link}"
   peer_network = "${google_compute_network.qa.self_link}"
}

Expected Behavior

terraform import google_compute_network_peering.peer_prod_qa {project}/{network}/{name}

Should have imported the resource into the state.

Actual Behavior

Fails to import into state and complains about other resources.

google_compute_network_peering.peer_prod_qa: Importing from ID "REDACTED/prod/prod-qa"...
google_compute_network_peering.peer_prod_qa: Import prepared!
  Prepared google_compute_network_peering for import
google_compute_network_peering.peer_prod_qa: Refreshing state... [id=prod/prod-qa]
Error: Invalid resource instance data in state
  on /REDACTED/src/github.com/REDACTED/REDACTED/infrastructure/terraform/environments/gc4/gcp.tf line 21:
  21: resource "google_project" "REDACTED_gcp_prod" {
Instance google_project.REDACTED_gcp_prod data could not be decoded from the
state: unsupported attribute "app_engine".

Steps to Reproduce

  1. remove from stateterraform state rm google_compute_network_peering.peer_prod_qa
  2. attempt to import terraform import google_compute_network_peering.peer_prod_qa {project}/{network}/{name}

Important Factoids

This is occurring during a provider update from 2.20.0 to 3.1.0. The terraform state rm and import are an attempt to sidestep some resource re-creation that was being forced due to API changes.

References

Might be related to

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Same here, but I’ve this error during a simple plan after the upgrade from 2.8 to 3.17.

Error: unsupported attribute "app_engine".

Error: unsupported attribute "policy_data"

Error: unsupported attribute "policy_etag"

After looking my state file, I notice that :

    {
      "module": "module.gcp.module.common",
      "mode": "data",
      "type": "google_project",
      "name": "my_data_project",
      "provider": "provider.google.prd",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "app_engine": [],
            "auto_create_network": null,
            "...": "...",
            "policy_data": null,
            "policy_etag": null,
            "...": "..."
          }
        }
      ]
    }

I remove app_engine, policy_data & policy_etag attribute from my state file and the plan works well.

I it helps, I think it’s related to this commit: https://github.com/terraform-providers/terraform-provider-google/commit/1b413bcb4e704933b16f61207b4f70c0cb6a4dbb#diff-c9e10abda825286093bfa6bbad9fb4c2

The datasource google_project does not support app_engine attribute anymore because the latter has been removed from the primary resource google_project (in 3.3.0 provider version). I also had trouble trying to import a google_compute_router_peer resource, and I had to clean up the following attributes for every occurrence of a google_project datasource in my .tfstate file:

  • app_engine
  • policy_data
  • policy_etag

Of course, I just did it as a test because I wouldn’t call that a clean migration path.