in terraform-modules/cloud-functions/src/provide-billing-permissions/main.py [0:0]
def set_policy(billing_ac,policy):
"""Function to set the policy of the billing account.
Args:
billing_ac(string); billing account
policy (dict); generated IAM policy of the billing account that needs to be set.
Returns:
new IAM policy.
"""
from google.cloud import billing_v1
from google.iam.v1 import iam_policy_pb2
from google.iam.v1 import policy_pb2
from google.protobuf.json_format import MessageToDict
from google.protobuf.json_format import ParseDict
client = billing_v1.CloudBillingClient()
policy = ParseDict(policy,policy_pb2.Policy())
request = iam_policy_pb2.SetIamPolicyRequest(
resource="billingAccounts/" + billing_ac,
policy=policy,
)
response = client.set_iam_policy(request=request)
return(MessageToDict(response))