Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing google_compute_project_metadata_item fails with "Error: project: required field is not set" #8731

Closed
levid0s opened this issue Mar 19, 2021 · 7 comments
Assignees
Labels

Comments

@levid0s
Copy link

levid0s commented Mar 19, 2021

This issue is exactly as described as #5742

Terraform Version

  • Terraform v0.14.8
  • Google provider 3.60.0

Affected Resource(s)

  • google_compute_project_metadata_item

Terraform Configuration Files

resource "google_compute_project_metadata_item" "enable_oslogin_at_project_level" {
  count      = "${contains(local.project_services, "compute.googleapis.com") ? 1 : 0}"
  project    = "${google_project.project.project_id}"
  key        = "enable-oslogin"
  value      = "TRUE"
  depends_on = ["google_project_service.project_services"]
}

Debug Output

PS> tf-14-8 import  module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]  enable-oslogin

module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Importing from ID "enable-oslogin"...
module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Import prepared!
  Prepared google_compute_project_metadata_item for import
module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Refreshing state... [id=enable-oslogin]

Error: project: required field is not set


@venkykuberan venkykuberan self-assigned this Mar 19, 2021
@venkykuberan
Copy link
Contributor

@KbLev The use case for import is that resource was created outside of terraform and you want terraform to manage it going forward by importing them. During the import command your terraform config should be empty alike

resource "google_compute_project_metadata_item" "enable_oslogin_at_project_level" {
  
}

Once the resource is imported to terraform state you can fill in your config's key/value pairs as per the values in the state.

Hope that helps.

@levid0s
Copy link
Author

levid0s commented Apr 1, 2021

Thanks for the response. I just got back to test it and no luck so far.

I tried three combinations of commented-out fields:

resource "google_compute_project_metadata_item" "enable_oslogin_at_project_level" {
  project    = "${google_project.project.project_id}"
  key        = "enable-oslogin"
  # # value      = "TRUE"
  depends_on = ["google_project_service.project_services"]
}

resource "google_compute_project_metadata_item" "enable_oslogin_at_project_level" {
  project    = "grey-rat-617512"
  # key        = "enable-oslogin"
  # # value      = "TRUE"
  # depends_on = ["google_project_service.project_services"]
}

resource "google_compute_project_metadata_item" "enable_oslogin_at_project_level" {
  # project    = "${google_project.project.project_id}"
  # key        = "enable-oslogin"
  # # value      = "TRUE"
  # depends_on = ["google_project_service.project_services"]
}

Same error:


PS> tf-14-8 import module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]  enable-oslogin

module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Importing from ID "enable-oslogin"...
module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Import prepared!
  Prepared google_compute_project_metadata_item for import
module.projects_module.module.project.google_compute_project_metadata_item.enable_oslogin_at_project_level[0]: Refreshing state... [id=enable-oslogin]

Error: project: required field is not set

@ghost ghost removed waiting-response labels Apr 1, 2021
@venkykuberan
Copy link
Contributor

Try importing the resource without the module and see if it works. I am not sure the module you are using expects project to be passed.

@edwardmedia
Copy link
Contributor

edwardmedia commented Jul 29, 2021

@KbLev have you tried the suggestion?

@edwardmedia
Copy link
Contributor

@KbLev is this still an issue?

@edwardmedia
Copy link
Contributor

@KbLev closing assuming this is no longer an issue

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants