'How to remove 'allow unauthenticated' flag of existing GCP cloud function using Terraform?

I've been trying to look for ways to remove the invocation using Terraform but I can't seem to find it. I can't remove an existing cloud function as it is live in production. I know the manual way of removing the 'allUsers' role in a cloud function to remove the 'allow unauthenticated' in GCP console but this won't do as it will take a lot of time so it needs to be automated. Also, I tried it using cloud shell using the command below but there are almost 100 functions per environment so it needs to be automated. Hoping someone has an idea. Thanks!

glcloud alpha functions remove-iam-policy-binding FunctionName --region=us-central1 --member=allUsers --role=roles/cloudfunctions.invoker


Solution 1:[1]

Use that Terraform definition. Pick the first one: google_cloudfunctions_function_iam_policy. It's authoritative and will override any existing policies. Be sure to allow the valid account on that Cloud Functions, and be sure that the allUsers is not granted as cloudfunctions.invoker.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 guillaume blaquiere