我正在尝试使用Azure管理SDK动态创建资源组以下是我的azure配置详细信息
subscription=<private-data>
client=<private-data>
key=<private-data>
tenant=<private-data>
managementURI=https://management.core.windows.net/
baseURL=https://management.azure.com/
authURL=https://login.windows.net/
graphURL=https://graph.windows.net/
以下是创建资源的代码
// Credentials
AzureCredentials credentials = new AzureCredentialsFactory()
.FromFile("azureauth.properties");
string resourceName = GetRandomString();
// Create Azure Instance
var azure = Azure
.Configure()
.Authenticate(credentials)
.WithDefaultSubscription();
// Create a Resource Group
azure.ResourceGroups
.Define(resourceName)
.WithRegion(Region.USWest)
.Create();
我得到的错误是:
具有对象id的客户端"ae8bc2ea-9680-4f66-934c-ad40b82c30ac"ae8bc2ea-9680-4f66-934c-ad40b82c30ac"无权执行操作作用域上的"Microsoft.Resources/subscriptions/resourcegroups/write"/订阅/e9d61100-a82a-48ca-b6f8-51b06a1eeb6/resourcegroups/5oxjhjic"。
我已遵循上指定的步骤https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal
我正在尝试使用我的全球管理员帐户
你可以使用门户网站或azure powershell:
New-AzRoleAssignment -ObjectId 'ae8bc2ea-9680-4f66-934c-ad40b82c30ac' -Scope '/subscriptions/e9d61100-a82a-48ca-b6f8-51b06a1eebe6' -RoleDefinitionName contributor
等效的Azure CLI命令是:
az role assignment create --assignee-object-id ae8bc2ea-9680-4f66-934c-ad40b82c30ac --scope subscriptions/e9d61100-a82a-48ca-b6f8-51b06a1eebe6 --role contributor