Hello @Javed Asif
Welcome to the Microsoft Q&A and thank you for posting your questions here. Base on your question, you need help to resolve the permission to write and delete on resources of type 'Microsoft.Authorization/roleAssignments' is required on the subscription or its ancestors.
The error you're encountering indicates that the service principal or user running Terraform does not have sufficient permissions to manage role assignments within Azure.
To solve this issue:
- The service principal or user running Terraform needs the appropriate permissions to manage role assignments within Azure.
- Based on your error review, it shows that you have created a custom RBAC role, which is a good approach. However, ensure that this custom role is assigned at the appropriate scope (/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx in your case). NOTE: Make sure this assignment is performed at the subscription level.
- The scope of the custom role assignment must match the subscription where you're deploying resources.
if you do the above, you should be able to resolve the permission issue and successfully deploy your Azure Landing Zones using Terraform, but if you're still having this issues, you may need to further examine the followings:
- Your provided JSON seems to cover the required permissions for managing role assignments and management groups but double-check to be sure.
- Make sure to reauthenticate Terraform to ensure it's using the updated credentials.
- Check your Terraform provider configuration that you're using right credentials.
- Enable debugging in Terraform (TF_LOG=DEBUG) to get more detailed information about the API calls being made.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution. Best Regards, Sina