All IAM code samples
This page contains code samples for Identity and Access Management. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Quickstart
Demonstrates basic usage of IAM.
- Google Cloud
- Identity and Access Management
- Python
- Go
- C#
- Java
- C++
Delete a service account
Demonstrates deleting a service account.
- Google Cloud
- Identity and Access Management
- C++
- C#
- Java
- Python
- Go
Query testable permissions
Demonstrates listing the permissions that are valid for a resource.
- Identity and Access Management
- Google Cloud
- Python
- Go
- C++
- C#
- Java
Add a new role binding
Demonstrates adding a new role binding to an IAM policy.
- Identity and Access Management
- Google Cloud
- Python
- Java
- C#
Create a deny policy
Creates a deny policy based on the configuration provided.
- Google Cloud
- Identity and Access Management
- Java
- Python
- Go
- Terraform
- Node JS
- JavaScript
Test permissions
Demonstrates testing whether the caller has specified permissions.
- Google Cloud
- Identity and Access Management
- Python
- C++
- C#
- Java
Delete a deny policy
Delete the policy if you no longer want to enforce the rules in a deny policy.
- Google Cloud
- Identity and Access Management
- Go
- JavaScript
- Java
- Node JS
- Python
Create a service account key
Demonstrates creating a service account key.
- Google Cloud
- Identity and Access Management
- Python
- Go
- C#
- Java
- C++
Remove a member from a role binding
Demonstrates removing a member from a role binding in an IAM policy.
- Identity and Access Management
- Google Cloud
- Python
- Go
- Java
- C#
Update a deny policy
Update the deny rules and/ or its display name after policy creation.
- Identity and Access Management
- Google Cloud
- JavaScript
- Python
- Java
- Node JS
- Go
Disable a service account key
Demonstrates disabling an IAM service account key.
- Google Cloud
- Identity and Access Management
- Java
Get an IAM policy
Demonstrates retrieving an IAM policy.
- Google Cloud
- Identity and Access Management
- C#
- C++
- Java
- Python
Delete a custom role
Demonstrates deleting a custom role.
- Identity and Access Management
- Google Cloud
- Python
- C++
- Go
- Java
- C#
Get a service account
Demonstrates retrieving a service account.
- Identity and Access Management
- Google Cloud
- C++
List service account keys
Demonstrates listing service account keys.
- Google Cloud
- Identity and Access Management
- C++
- C#
- Java
- Go
- Python
Delete a service account key
Demonstrates deleting a service account key.
- Google Cloud
- Identity and Access Management
- Go
- Java
- Python
- C#
- C++
Disable a service account
Demonstrates disabling a service account.
- Identity and Access Management
- Google Cloud
- C#
- C++
- Go
- Java
- Python
List deny policies
List the deny policies in the resource provided.
- Google Cloud
- Identity and Access Management
- Python
- Java
- Go
- JavaScript
- Node JS
Enable a service account key
Demonstrates enabling a disabled IAM service account key.
- Identity and Access Management
- Google Cloud
- Java
Update a policy
Demonstrates updating a policy.
- Google Cloud
- Identity and Access Management
- C#
- Python
- Java
- C++
Enable a service account
Demonstrates enabling a service account.
- Identity and Access Management
- Google Cloud
- Go
- C#
- Python
- C++
- Java
Create project-level service agents
Create all project-level service agents for an API.
- Identity and Access Management
- Google Cloud
- Terraform
Get a deny policy
Retrieve information about a deny policy.
- Identity and Access Management
- Google Cloud
- Java
- Node JS
- Go
- JavaScript
- Python
Get a service account key
Demonstrates retrieving a service account key.
- Identity and Access Management
- Google Cloud
- C++
Restore a deleted custom role
Demonstrates restoring a custom role.
- Google Cloud
- Identity and Access Management
- C#
- Java
- Python
- Go
- C++
View grantable roles
Demonstrates viewing the roles that you can grant on a specific resource.
- Identity and Access Management
- Google Cloud
- C++
- Python
- Java
- Go
- C#
Disable a custom role
Demonstrates disabling a custom role.
- Identity and Access Management
- Google Cloud
- Java
- Python
List service accounts
Demonstrates listing service accounts.
- Google Cloud
- Identity and Access Management
- Java
- Python
- Go
- C++
- C#
Edit a custom role
Demonstrates editing a custom role.
- Identity and Access Management
- Google Cloud
- C++
- C#
- Python
- Java
- Go
Create a custom role
Demonstrates creating a custom role.
- Identity and Access Management
- Google Cloud
- C#
- Go
- Python
- Java
- C++
Add a principal to a role binding
Demonstrates adding a principal to an existing role binding in an IAM policy.
- Google Cloud
- Identity and Access Management
- C#
- Go
- Python
- Java
Create a token for Workload Identity Federation with AWS
Creates a token that IAM Workload Identity Federation can verify without revealing the AWS secret access key.
- Google Cloud
- Identity and Access Management
- Python
Rename a service account
Demonstrates renaming a service account.
- Google Cloud
- Identity and Access Management
- C++
- Java
- Go
- C#
- Python
Create a service account
Demonstrates creating a service account.
- Identity and Access Management
- Google Cloud
- C#
- Python
- C++
- Go
- Java
Get a role
Demonstrates retrieving a role.
- Google Cloud
- Identity and Access Management
- C++
- Java
- Python
- Go
- C#