Stay organized with collections
Save and categorize content based on your preferences.
Sets the IAM access control policy for the specified Project. CAUTION:
This method will replace the existing policy, and cannot be used to
append additional IAM settings. NOTE: Removing service accounts from
policies or changing their roles can render services completely
inoperable. It is important to understand how the service account is
being used before removing or updating its roles. For additional
information about resource (e.g. my-project-id) structure and
identification, see Resource
Names. The
following constraints apply when using setIamPolicy(): + Project does
not support allUsers and allAuthenticatedUsers as members in a
Binding of a Policy. + The owner role can be granted to a user,
serviceAccount, or a group that is part of an organization. For
example, group@myownpersonaldomain.com could be added as an owner to a
project in the myownpersonaldomain.com organization, but not the
examplepetstore.com organization. + Service accounts can be made owners
of a project directly without any restrictions. However, to be added as
an owner, a user must be invited via Cloud Platform console and must
accept the invitation. + A user cannot be granted the owner role using
setIamPolicy(). The user must be granted the owner role using the
Cloud Platform Console and must explicitly accept the invitation. + You
can only grant ownership of a project to a member by using the GCP
Console. Inviting a member will deliver an invitation email that they
must accept. An invitation email is not generated if you are granting a
role other than owner, or if both the member you are inviting and the
project are part of your organization. + If the project is not part of
an organization, there must be at least one owner who has accepted the
Terms of Service (ToS) agreement in the policy. Calling setIamPolicy()
to remove the last ToS-accepted owner from the policy will fail. This
restriction also applies to legacy projects that no longer have owners
who have accepted the ToS. Edits to IAM policies will be rejected until
the lack of a ToS-accepting owner is rectified. If the project is part
of an organization, you can remove all owners, potentially making the
organization inaccessible. Authorization requires the Google IAM
permission resourcemanager.projects.setIamPolicy on the project
Arguments
Parameters
resource
string
REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Method: googleapis.cloudresourcemanager.v1.projects.setIamPolicy\n\nSets the IAM access control policy for the specified Project. CAUTION:\nThis method will replace the existing policy, and cannot be used to\nappend additional IAM settings. NOTE: Removing service accounts from\npolicies or changing their roles can render services completely\ninoperable. It is important to understand how the service account is\nbeing used before removing or updating its roles. For additional\ninformation about `resource` (e.g. my-project-id) structure and\nidentification, see [Resource\nNames](https://cloud.google.com/apis/design/resource_names). The\nfollowing constraints apply when using `setIamPolicy()`: + Project does\nnot support `allUsers` and `allAuthenticatedUsers` as `members` in a\n`Binding` of a `Policy`. + The owner role can be granted to a `user`,\n`serviceAccount`, or a group that is part of an organization. For\nexample, group@myownpersonaldomain.com could be added as an owner to a\nproject in the myownpersonaldomain.com organization, but not the\nexamplepetstore.com organization. + Service accounts can be made owners\nof a project directly without any restrictions. However, to be added as\nan owner, a user must be invited via Cloud Platform console and must\naccept the invitation. + A user cannot be granted the owner role using\n`setIamPolicy()`. The user must be granted the owner role using the\nCloud Platform Console and must explicitly accept the invitation. + You\ncan only grant ownership of a project to a member by using the GCP\nConsole. Inviting a member will deliver an invitation email that they\nmust accept. An invitation email is not generated if you are granting a\nrole other than owner, or if both the member you are inviting and the\nproject are part of your organization. + If the project is not part of\nan organization, there must be at least one owner who has accepted the\nTerms of Service (ToS) agreement in the policy. Calling `setIamPolicy()`\nto remove the last ToS-accepted owner from the policy will fail. This\nrestriction also applies to legacy projects that no longer have owners\nwho have accepted the ToS. Edits to IAM policies will be rejected until\nthe lack of a ToS-accepting owner is rectified. If the project is part\nof an organization, you can remove all owners, potentially making the\norganization inaccessible. Authorization requires the Google IAM\npermission `resourcemanager.projects.setIamPolicy` on the project\n\nArguments\n---------\n\nRaised exceptions\n-----------------\n\nResponse\n--------\n\nIf successful, the response contains an instance of [`Policy`](https://cloud.google.com/workflows/docs/reference/googleapis/cloudresourcemanager/v1/Overview#Policy).\n\nSubworkflow snippet\n-------------------\n\nSome fields might be optional or required.\nTo identify required fields, refer to the [API documentation](https://cloud.google.com/resource-manager/reference/rest/v1/projects/setIamPolicy). \n\n### YAML\n\n```yaml\n- setIamPolicy:\n call: googleapis.cloudresourcemanager.v1.projects.setIamPolicy\n args:\n resource: ...\n body:\n policy:\n auditConfigs: ...\n bindings: ...\n etag: ...\n version: ...\n updateMask: ...\n result: setIamPolicyResult\n```\n\n### JSON\n\n```json\n[\n {\n \"setIamPolicy\": {\n \"call\": \"googleapis.cloudresourcemanager.v1.projects.setIamPolicy\",\n \"args\": {\n \"resource\": \"...\",\n \"body\": {\n \"policy\": {\n \"auditConfigs\": \"...\",\n \"bindings\": \"...\",\n \"etag\": \"...\",\n \"version\": \"...\"\n },\n \"updateMask\": \"...\"\n }\n },\n \"result\": \"setIamPolicyResult\"\n }\n }\n]\n```"]]