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
- Go
- Python
- Java
- C#
- C++
Delete a service account
Demonstrates deleting a service account.
- Identity and Access Management
- Google Cloud
- C++
- Java
- Python
- C#
- Go
Query testable permissions
Demonstrates listing the permissions that are valid for a resource.
- Google Cloud
- Identity and Access Management
- C++
- C#
- Go
- Python
- 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
- Go
- Terraform
- Node JS
- JavaScript
- Python
Test permissions
Demonstrates testing whether the caller has specified permissions.
- Identity and Access Management
- Google Cloud
- Python
- Java
- C++
- C#
Delete a deny policy
Delete the policy if you no longer want to enforce the rules in a deny policy.
- Identity and Access Management
- Google Cloud
- Java
- Node JS
- JavaScript
- Python
- Go
Create a service account key
Demonstrates creating a service account key.
- Identity and Access Management
- Google Cloud
- C#
- Java
- C++
- Go
- Python
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
- Java
- Go
- C#
- Python
Update a deny policy
Update the deny rules and/ or its display name after policy creation.
- Google Cloud
- Identity and Access Management
- Java
- Python
- JavaScript
- Go
- Node JS
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.
- Identity and Access Management
- Google Cloud
- Python
- C++
- C#
- Java
Delete a custom role
Demonstrates deleting a custom role.
- Google Cloud
- Identity and Access Management
- C#
- Java
- Go
- C++
- Python
Get a service account
Demonstrates retrieving a service account.
- Google Cloud
- Identity and Access Management
- C++
List service account keys
Demonstrates listing service account keys.
- Google Cloud
- Identity and Access Management
- Java
- Go
- C#
- C++
- Python
Delete a service account key
Demonstrates deleting a service account key.
- Identity and Access Management
- Google Cloud
- C#
- Python
- Go
- C++
- Java
Disable a service account
Demonstrates disabling a service account.
- Identity and Access Management
- Google Cloud
- Go
- Python
- Java
- C++
- C#
List deny policies
List the deny policies in the resource provided.
- Google Cloud
- Identity and Access Management
- Node JS
- Go
- Java
- JavaScript
- Python
Enable a service account key
Demonstrates enabling a disabled IAM service account key.
- Google Cloud
- Identity and Access Management
- Java
Update a policy
Demonstrates updating a policy.
- Google Cloud
- Identity and Access Management
- C++
- Python
- C#
- Java
Enable a service account
Demonstrates enabling a service account.
- Identity and Access Management
- Google Cloud
- Python
- C#
- Java
- C++
- Go
Create project-level service agents
Create all project-level service agents for an API.
- Google Cloud
- Identity and Access Management
- Terraform
Get a deny policy
Retrieve information about a deny policy.
- Google Cloud
- Identity and Access Management
- Java
- Python
- JavaScript
- Node JS
- Go
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
- Java
- C#
- C++
- Python
- Go
View grantable roles
Demonstrates viewing the roles that you can grant on a specific resource.
- Identity and Access Management
- Google Cloud
- C#
- Python
- Go
- C++
- Java
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
- C#
- Java
- Python
- Go
- C++
Edit a custom role
Demonstrates editing a custom role.
- Google Cloud
- Identity and Access Management
- Python
- C++
- Java
- Go
- C#
Create a custom role
Demonstrates creating a custom role.
- Google Cloud
- Identity and Access Management
- Java
- Python
- C#
- C++
- Go
Add a principal to a role binding
Demonstrates adding a principal to an existing role binding in an IAM policy.
- Identity and Access Management
- Google Cloud
- Go
- Java
- Python
- C#
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.
- Identity and Access Management
- Google Cloud
- Java
- C#
- C++
- Go
- Python
Create a service account
Demonstrates creating a service account.
- Identity and Access Management
- Google Cloud
- C#
- Java
- Go
- Python
- C++
Get a role
Demonstrates retrieving a role.
- Identity and Access Management
- Google Cloud
- Python
- Go
- C#
- Java
- C++