Skip to content

IAM policy for Billing Account

Three different resources help you manage IAM policies on billing accounts. Each of these resources serves a different use case:

  • googleBillingAccountIamPolicy: Authoritative. Sets the IAM policy for the billing accounts and replaces any existing policy already attached.
  • googleBillingAccountIamBinding: 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 table are preserved.
  • googleBillingAccountIamMember: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role of the billing accounts are preserved.

\~> Note: googleBillingAccountIamPolicy cannot be used in conjunction with googleBillingAccountIamBinding and googleBillingAccountIamMember or they will fight over what your policy should be. In addition, be careful not to accidentally unset ownership of the billing account as googleBillingAccountIamPolicy replaces the entire policy.

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

googleBillingAccountIamPolicy

/*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/billing.viewer",
      },
    ],
  });
new google.billingAccountIamPolicy.BillingAccountIamPolicy(this, "editor", {
  billing_account_id: "00AA00-000AAA-00AA0A",
  policy_data: dataGoogleIamPolicyAdmin.policyData,
});

googleBillingAccountIamBinding

/*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.billingAccountIamBinding.BillingAccountIamBinding(this, "editor", {
  billing_account_id: "00AA00-000AAA-00AA0A",
  members: ["user:jane@example.com"],
  role: "roles/billing.viewer",
});

googleBillingAccountIamMember

/*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.billingAccountIamMember.BillingAccountIamMember(this, "editor", {
  billing_account_id: "00AA00-000AAA-00AA0A",
  member: "user:jane@example.com",
  role: "roles/billing.viewer",
});

Argument Reference

The following arguments are supported:

  • billingAccountId - (Required) The billing account id.

For googleBillingAccountIamMember or googleBillingAccountIamBinding:

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

    • 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 googleBillingAccountIamBinding can be used per role. Note that custom roles must be of the format [projects|organizations]/{parentName}/roles/{roleName}. Read more about roles here.

googleBillingAccountIamPolicy only:

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

Attributes Reference

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

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

Import

Instance IAM resources can be imported using the project, table name, role and/or member.

$ terraform import google_billing_account_iam_policy.binding "your-billing-account-id"

$ terraform import google_billing_account_iam_binding.binding "your-billing-account-id roles/billing.user"

$ terraform import google_billing_account_iam_member.binding "your-billing-account-id roles/billing.user user: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. organizations/myOrgId/roles/myCustomRole.