Allow deployments only from Terraform using Azure Policy

Logan 0 Reputation points
2025-03-26T14:00:40.9233333+00:00

Hi Team,

Is it possible to block all deployments and allow it only from Terraform? I tried this but it didn't work.

{
          "not": {
            "anyOf": [
              {
                "field": "Microsoft.Authorization/roleAssignments/principalId",
                "equals": "[parameters('allowedServicePrincipal')]"
              }
            ]
          }
        }
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
994 questions
{count} votes

1 answer

Sort by: Most helpful
  1. guilherme rodrigues 390 Reputation points
    2025-05-02T13:04:45.25+00:00

    Hi, Logan!

    It is not possible to fully manage deployment permissions using Terraform alone, especially when the goal is to restrict deployments to a specific service principal. Azure Policy does not have the capability to enforce policies based on who is performing the deployment action at runtime, it only evaluates the state of the resources being deployed or modified.

    The best approach in this scenario is to manage access control through Azure RBAC (Role-Based Access Control). By assigning the required Contributor (or equivalent) role only to the Terraform service principal and limiting all other users/groups to Reader or minimal permissions, you can effectively ensure that only Terraform is allowed to deploy and modify resources.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.