-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 to add bind a role to service account? #1225
Comments
Thanks @rickypai for the detailed report! The IAM resources are tricky to get right, and we're still thinking about how to make it clearer which to use in what situations. In your case, you should be looking at the |
Hi @danawillow , I have the same issue, use |
Hey @jason-tian, the fix I mentioned in #1225 (comment) will apply to you as well. Since your gcloud command was |
Thanks @danawillow , the issue is fixed when I use projects iam binding. |
I think we got the documentation for this updated, so I'm going to close this out. If people think we could still stand to have better documentation here, feel free to reply and I can reopen this. |
forgot to say this but thanks for the documentation updates! |
It worked for me using: |
Hey @danawillow! The fix you mentioned is indeed working however EDIT: I realized I didn't understand the |
@MrBlaise you're absolutely right!!! I tested resource "google_service_account" "cloudsql-sa" {
account_id = "cloudsql-sa"
}
resource "google_project_iam_binding" "cloudsql-sa-cloudsql-admin-role" {
role = "roles/cloudsql.admin"
members = [
"serviceAccount:${google_service_account.cloudsql-sa.email}"
]
} It's actually dangerous to use |
That sounds like a bug and unintended behaviour to me. If you have a repro, I'd appreciate a new issue with a bug report. But as you mentioned, that's how iam_binding is meant to work. If you want Terraform to ignore members outside the config, use iam_member. :)
There aren't supposed to be any users added to the role using other means. That's the point of iam_binding. Would love any suggestions you have for how to make this clearer in the docs. We purposefully designed our IAM resources into these three levels to allow people to decide the amount of control and danger they wanted when dealing with IAM. For some people, they want to make sure an IAM policy hasn't been modified by hand; for them, iam_binding and iam_policy are perfect. Some people want to just make sure certain members have a certain role, but don't care if other things change; for them, iam_member is perfect. |
If I'm understanding what everybody is talking about correctly, then: nah, it's intended: https://github.com/terraform-providers/terraform-provider-google/blob/2.0.0/google/resource_iam_binding.go#L60
|
Interesting, I stand corrected! I'm sure there's a reason for that, but I can't recall what it is (beyond what's in the comment; I don't know why refresh wouldn't show that diff, I mean). |
Yeah refresh should definitely show the diff. |
This is related to #2379. |
Hello! 👋 Is there consensus about whether or not this is a bug? (see also my comments in #2379, thank you!) |
Hey @dossett, if you think there's a bug then please file a new issue and fill out the template. This issue was specifically about a misunderstanding of the difference between |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Hi, thank you for maintaining this project to allow GCP be used on terraform and potentially looking at this issue.
I'm trying to follow the guide to connect GKE applications to Cloud SQL, but instead of using the console
gcloud
to create the necessary service accounts and binding, using terraform with very limited success.I was able to create a service account no problem with:
but trying to bind it with the
roles/cloudsql.client
role was not successful at all:or
Logs
verbose logging shows the API request and response:
Wrong/Misused Terraform Resource?
I have a feeling I'm using the wrong terraform resource to achieve the goal. But I'm not sure which other resource is more fitting.
I also don't understand what is the
service_account_id
field in those resources. I've tried using the id of the service account I'm trying to bind and also the terraform service account with no success. Similar guide usinggloud
nor the API requires it.Resolution with
gcloud
I was able to proceed with just the
gcloud
command for creating the binding, so I'm going with that for now.Version Info
The text was updated successfully, but these errors were encountered: