As the title states I'm assigning a role to a group using cloud resource mananger api using python client library. Here's the code :
from googleapiclient.discovery import build
from googleapiclient import errors
service = build('cloudresourcemanager', 'v1', credentials= delegated_credentials)
def assign_custom_role_to_group(project_id, role_name, group_email):
try:
# Define the request body
policy = service.projects().getIamPolicy(resource=project_id).execute()
#print("GET IAM", policy['version'])
bindings = policy.get('bindings', [])
# Add the custom role to the bindings
bindings.append({
"role": role_name,
"members": ["group:group_email"],
"etag" : "BwXy6qC04wk=",
"version" : 1
})
policy['bindings'] = bindings
# Execute the request
service.projects().setIamPolicy(resource=project_id, body=policy).execute()
print(f'Successfully assigned custom role {role_name} to group {group_email}')
except errors.HttpError as error:
print(f'An error occurred: {error}')
For this code I'm getting the following error. enter image description here. Thank you.