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 IAM service account to google_sql_user fails #9760

Closed
villesau opened this issue Aug 10, 2021 · 6 comments
Closed

Importing IAM service account to google_sql_user fails #9760

villesau opened this issue Aug 10, 2021 · 6 comments
Labels

Comments

@villesau
Copy link

villesau commented Aug 10, 2021

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 v1.0.3
  • registry.terraform.io/hashicorp/google v3.79.0

Affected Resource(s)

  • google_sql_user

Terraform Configuration Files

resource "google_sql_user" "sql_backend_access" {
  name     = "some-backend@${var.project_id}.iam"
  instance = module.pg.instance_name
  project  = var.project_id
  type     = "CLOUD_IAM_SERVICE_ACCOUNT"
}

Expected Behavior

tf import google_sql_user.sql_backend_access <project-id>/<instance>/some-backend@<project-id>.iam imports the service account.

Actual Behavior

It fails to following error:

╷
│ Error: Cannot import non-existent remote object
│ 
│ While attempting to import an existing object to "google_sql_user.sql_backend_access", the provider detected that no object exists with the given id. Only pre-existing objects can be
│ imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
╵

Steps to Reproduce

All of the following fails:

  1. tf import google_sql_user.sql_backend_access project/<project-id>/<instance>/some-backend@<project-id>.iam
  2. tf import google_sql_user.sql_backend_access project/<project-id>/<instance>/<actual-unique-iam-id>
  3. tf import google_sql_user.sql_backend_access project/<project-id>/<instance>/some-backend

Important Factoids

  • importing regular users succeeds
  • running apply (without importing) results following:
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to google_sql_user.sql_backend_access, provider "provider[\"registry.terraform.io/hashicorp/google\"]" produced an unexpected new value: Root resource was present, but
│ now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

E: The above error actually might also happen in some cases even when creating totally new IAM service account users. The accounts get created but terraflrm errors out and it's not possible to recover from it since importing is broken.

@villesau villesau added the bug label Aug 10, 2021
@itspngu
Copy link

itspngu commented Aug 11, 2021

This also happens for "actual" IAM users which aren't service accounts.

@villesau
Copy link
Author

villesau commented Aug 11, 2021

I believe that pinning the provider version to 3.77.0 might help. It helped with #9723 at least.

@itspngu
Copy link

itspngu commented Aug 11, 2021

Can confirm that pinning to 3.77.0 did let me import IAM Cloud SQL users.

Also forgot to mention in my first comment that this bug in fact breaks existing configurations, because the provider can not find accounts on the instance, tries to create them, and eventually complains about not finding the accounts it just "created".

@villesau
Copy link
Author

@megan07 @slevenick this PR GoogleCloudPlatform/magic-modules#4984 likely caused this and #9723

@rileykarson
Copy link
Collaborator

Deduping to #9723, since they appear to be the same 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 13, 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