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

Need a way to migrate to google_bigquery_dataset_access #7486

Open
rvandegrift opened this issue Oct 9, 2020 · 10 comments
Open

Need a way to migrate to google_bigquery_dataset_access #7486

rvandegrift opened this issue Oct 9, 2020 · 10 comments

Comments

@rvandegrift
Copy link
Contributor

rvandegrift commented Oct 9, 2020

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 the 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 the issue is assigned to a user, that user is claiming responsibility for the issue. If the issue is assigned to "hashibot", a community member has claimed the issue already.

Description

I have some bigquery datasets that use old-style access blocks in the dataset. I'd like to switch to the newer google_bigquery_dataset_access, but the provider doesn't correctly handle this. When the google_bigquery_dataset_access resource is created, it conflicts with the existing IAM policy elements, resulting in errors like:

google_bigquery_dataset_access.access: Creating...

Error: Unable to create DatasetAccess, existing object already found: map[role:OWNER userByEmail:user@domain.com]

New or Affected Resource(s)

  • google_bigquery_dataset_access

Potential Terraform Configuration

Initial config:

resource "google_bigquery_dataset" "ds" {
  dataset_id = "table"
  location   = "US"

  access {
    role          = "OWNER"
    user_by_email = "user@domain.com"
  }
}

Desired config:

resource "google_bigquery_dataset" "ds" {
  dataset_id = "table"
  location   = "US"
}

resource "google_bigquery_dataset_access" "access" {
  dataset_id = google_bigquery_dataset.ds.dataset_id

  role          = "OWNER"
  user_by_email = "user@domain.com"
}

Ideally, terraform would be to detect that the exact policy element already exists, and just consider it successful. If that wouldn't work, it'd still be better than nothing to have terraform import support.

References

  • #0000

b/359365569

@ghost ghost added the enhancement label Oct 9, 2020
@danawillow danawillow added this to the Goals milestone Oct 12, 2020
@slevenick
Copy link
Collaborator

Hey @rvandegrift you can try the bigquery dataset IAM policy which wraps the dataset access resource as a workaround. It should be able to support your use case

https://www.terraform.io/docs/providers/google/r/bigquery_dataset_iam.html

@rvandegrift
Copy link
Contributor Author

I left this out of my example to keep it simple, but I need authorized view support.

@objectiveryan
Copy link

This bug is blocking my team from using google_bigquery_dataset_access; thankfully we can still use access blocks (like the OP we also have authorized views).

@CrAzE124
Copy link

CrAzE124 commented Jun 2, 2021

We're also trying to migrate from access to google_bigquery_dataset_access and face the same problem (also in #8165 ). We'd like to move to this resource instead of bigquery_dataset_iam as we need authorized view support, but would also like the permissions to be non-authoritative, so that we can set additional permissions dynamically from client SDK's. Is there any plan to make this migration possible at the moment? Manually migrating datasets is a non-starter as we have thousands of datasets currently, and our terraform code is dynamically generated.

@alessandroberlati
Copy link

alessandroberlati commented Jun 7, 2021

The easiest way I found was to:

  • remove all access blocks in favor of google_bigquery_dataset_access
  • add a single access block with your admin email as OWNER
  • apply the changes
  • remove the last access block that will not produce any changes
  • manually remove the Data owner from UI (one per dataset)

@amerenda
Copy link

If you're having this issue with dataset VIEWS:

  • Navigate to the BiqQuery GCP console page
  • Expand the GCP project
  • Open the source dataset for the view (click the vertical dots, open)
  • Select Share Dataset
  • Select Authorized Views
  • Find the view that does not exist in terraform, but exists in BQ, remove it.
  • Run terraform apply

modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Mar 23, 2023
…rp#7486)

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit that referenced this issue Mar 23, 2023
…14078)

Signed-off-by: Modular Magician <magic-modules@google.com>
@github-actions github-actions bot added service/bigquery forward/review In review; remove label to forward labels Aug 17, 2023
@ggtisc
Copy link
Collaborator

ggtisc commented Aug 12, 2024

Currently I did not find any argument in the terraform registry to achieve this proposal, it seems to me that it should rather be an action executed by some method

@ggtisc ggtisc assigned ggtisc and unassigned ggtisc Aug 12, 2024
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Aug 12, 2024
@roaks3
Copy link
Collaborator

roaks3 commented Aug 22, 2024

Note: it seems like import would help quite a bit to solve this (#7659), but assuming import is possible by coming up with a suitable identifier, I think this use-case would also benefit from being considered for acquire-on-create behavior (ie. when adding a new google_bigquery_dataset_access, check if the exact same object already exists, and if it does use that).

@wj-chen
Copy link

wj-chen commented Aug 26, 2024

I think this use-case would also benefit from being considered for acquire-on-create behavior (ie. when adding a new google_bigquery_dataset_access, check if the exact same object already exists, and if it does use that).

This sounds promising. Would it be in a pre_create? Do you know of examples we can look at as a reference? @roaks3

@roaks3
Copy link
Collaborator

roaks3 commented Aug 26, 2024

Yea, we do it with google_project_service, and plan to do it with google_identity_platform_config as well (I think some others exist too). I'm still not sure if it's a good fit here, but presumably it would be done with a pre_create or custom_create.

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

No branches or pull requests