Skip to content

IAM policy for Pubsub Subscription

Three different resources help you manage your IAM policy for pubsub subscription. Each of these resources serves a different use case:

  • googlePubsubSubscriptionIamPolicy: Authoritative. Sets the IAM policy for the subscription and replaces any existing policy already attached.
  • googlePubsubSubscriptionIamBinding: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the subscription are preserved.
  • googlePubsubSubscriptionIamMember: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the subscription are preserved.

\~> Note: googlePubsubSubscriptionIamPolicy cannot be used in conjunction with googlePubsubSubscriptionIamBinding and googlePubsubSubscriptionIamMember or they will fight over what your policy should be.

\~> Note: googlePubsubSubscriptionIamBinding resources can be used in conjunction with googlePubsubSubscriptionIamMember resources only if they do not grant privilege to the same role.

googlePubsubSubscriptionIamPolicy

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleIamPolicyAdmin =
  new google.dataGoogleIamPolicy.DataGoogleIamPolicy(this, "admin", {
    binding: [
      {
        members: ["user:jane@example.com"],
        role: "roles/editor",
      },
    ],
  });
new google.pubsubSubscriptionIamPolicy.PubsubSubscriptionIamPolicy(
  this,
  "editor",
  {
    policy_data: dataGoogleIamPolicyAdmin.policyData,
    subscription: "your-subscription-name",
  }
);

googlePubsubSubscriptionIamBinding

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.pubsubSubscriptionIamBinding.PubsubSubscriptionIamBinding(
  this,
  "editor",
  {
    members: ["user:jane@example.com"],
    role: "roles/editor",
    subscription: "your-subscription-name",
  }
);

googlePubsubSubscriptionIamMember

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.pubsubSubscriptionIamMember.PubsubSubscriptionIamMember(
  this,
  "editor",
  {
    member: "user:jane@example.com",
    role: "roles/editor",
    subscription: "your-subscription-name",
  }
);

Argument Reference

The following arguments are supported:

  • subscription - (Required) The subscription name or id to bind to attach IAM policy to.

  • member/members - (Required) Identities that will be granted the privilege in role. Each entry can have one of the following values:

    • allUsers: A special identifier that represents anyone who is on the internet; with or without a Google account.
    • allAuthenticatedUsers: A special identifier that represents anyone who is authenticated with a Google account or a service account.
    • user:{emailid}: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com.
    • serviceAccount:{emailid}: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
    • group:{emailid}: An email address that represents a Google group. For example, admins@example.com.
    • domain:{domain}: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
  • role - (Required) The role that should be applied. Only one googlePubsubSubscriptionIamBinding can be used per role. Note that custom roles must be of the format [projects|organizations]/{parentName}/roles/{roleName}.

  • policyData - (Required only by googlePubsubSubscriptionIamPolicy) The policy data generated by a googleIamPolicy data source.


  • project - (Optional) The project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • etag - (Computed) The etag of the subscription's IAM policy.

Import

Pubsub subscription IAM resources can be imported using the project, subscription name, role and member.

$ terraform import google_pubsub_subscription_iam_policy.editor projects/{your-project-id}/subscriptions/{your-subscription-name}

$ terraform import google_pubsub_subscription_iam_binding.editor "projects/{your-project-id}/subscriptions/{your-subscription-name} roles/editor"

$ terraform import google_pubsub_subscription_iam_member.editor "projects/{your-project-id}/subscriptions/{your-subscription-name} roles/editor jane@example.com"

-> Custom Roles: If you're importing a IAM resource with a custom role, make sure to use the full name of the custom role, e.g. [projects/myProject|organizations/myOrg]/roles/myCustomRole.