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

how can i import compute engine metadata from the non-default project? #10961

Open
marengaz opened this issue Jan 24, 2022 · 2 comments
Open
Labels

Comments

@marengaz
Copy link

marengaz commented Jan 24, 2022

my code

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 4.8.0"
    }
  }
}

provider "google" {
  region = "europe-west2"
}

resource "google_compute_project_metadata_item" "enableguestattributes" {
  for_each = toset([ "my-project-1", "my-project-2" ])
  project  = each.key
  key      = "enable-guest-attributes"
  value    = "TRUE"
}
$ terraform import 'google_compute_project_metadata_item.enableguestattributes["my-project-1"]' enable-guest-attributes
google_compute_project_metadata_item.enableguestattributes["my-project-1"]: Importing from ID "enable-guest-attributes"...
google_compute_project_metadata_item.enableguestattributes["my-project-1"]: Import prepared!
  Prepared google_compute_project_metadata_item for import
google_compute_project_metadata_item.enableguestattributes["my-project-1"]: Refreshing state... [id=enable-guest-attributes]
╷
│ Error: project: required field is not set
│ 
│ 
╵

the docs show that compute engine metadata items can be imported using the key as i tried above, but it seems not to be possible to import a metadata item when the resource belongs to a different project than the provider

i have additionally tried:

terraform import 'google_compute_project_metadata_item.enableguestattributes["my-project-1"]' 'my-project-1/enable-guest-attributes'

is it a bug or is there something im missing?

modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Jun 17, 2024
…r an update in resource `google_workbench_instance` (hashicorp#10961)

[upstream:e69e5f7253af4532e5ed75617a8cab176eef4a72]

Signed-off-by: Modular Magician <[email protected]>
modular-magician added a commit that referenced this issue Jun 17, 2024
…r an update in resource `google_workbench_instance` (#10961) (#18464)

[upstream:e69e5f7253af4532e5ed75617a8cab176eef4a72]

Signed-off-by: Modular Magician <[email protected]>
@eriksw
Copy link

eriksw commented Oct 2, 2024

This is still an active issue and I beleive it should be classified as a bug instead of a question.

#13370 did not fix it.

It does not appear to be possible to import this resource when there is no project set at the provider level. In some situations, such as one workspace managing several google cloud projects, setting it at the provider level would be incorrect.

@wyardley
Copy link

wyardley commented Oct 2, 2024

Given this example:

resource "google_compute_project_metadata_item" "test" {
  key   = "TEST"
  value = "FOOBAR"
  project = "xxx"
}

with a value like

commonInstanceMetadata:
  fingerprint: 9wSsw7q2AB8=
  items:
  - key: TEST
    value: FOOBAR
  kind: compute#metadata

Trying to do this:

$ terraform  import google_compute_project_metadata_item.test projects/xxxx/TEST

will of course not work, and the normal import syntax of:

terraform  import google_compute_project_metadata_item.test TEST

also doesn't seem to work if the provider level configuration has a different project configured, even if project is set at the resource level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants