我已经编写了用于创建用户、资源组和角色定义的terraform。
我需要资源定义的范围是我创建的资源组。
我不知道该怎么做。如果有人能帮上忙那就太好了。
########### for creating user ####
# Configure the Azure Provider
provider "azurerm" {
version = "~> 1.30"
subscription_id="723604be-b74b-4473-9d11-1802dbfdb787"
}
provider "azuread" {
version = "~> 0.4"
subscription_id="723604be-b74b-4473-9d11-1802dbfdb787"
}
resource "azuread_user" "test" {
user_principal_name = "user1@catch.whizlabstesting.com"
display_name = "User1"
mail_nickname = "User1"
password = "Muneeshpandi@17"
force_password_change = "false"
}
##### creating resource group #####
resource "azurerm_resource_group" "terraform_rg" {
name = "user1_rgp"
location = "East US"
}
########## creating role definition ##########
data "azurerm_subscription" "primary" {}
resource "azurerm_role_definition" "sql_role" {
name = "sql_role"
scope = "data.azurerm_subscription.primary.id"
description = "This is a custom role to create sql database"
permissions {
actions = ["*"]
not_actions = []
}
assignable_scopes = [
"/subscriptions/723604be-b74b-4473-9d11-1802dbfdb787/resourceGroups/user1_rgp"
]
}
在执行上述代码时获取以下错误:
authorization.RoleDefinitionsClient#CreateOrUpdate:错误:响应请求的
失败: StatusCode=404 --原始错误: autorest/azure:返回了一个错误。Status=404 Code="MissingSubscription“Message=请求没有订阅或有效的租户级资源提供程序。
如何使自定义角色的作用域成为蔚蓝中的Resourcegroup?
发布于 2020-06-22 06:11:30
要为资源组创建自定义角色,需要有权限Microsoft.Authorization/roleDefinitions/write
,而要将自定义角色分配给用户,则需要有权限Microsoft.Authorization/roleAssignments/write
。最简单的方法是您拥有订阅的Onwer
角色。
并创建Azure AD用户:
要添加或删除用户,您必须是用户管理员或全局管理员。
当你得到了所有必要的许可。让我们专注于您的代码。还需要将自定义角色分配给您使用资源组的作用域创建的用户。然后,您可以这样修改代码:
resource "azurerm_role_definition" "sql_role" {
name = "sql_role"
scope = data.azurerm_subscription.primary.id
description = "This is a custom role to create sql database"
permissions {
actions = ["*"]
not_actions = []
}
assignable_scopes = [
data.azurerm_subscription.primary.id
]
}
resource "azurerm_role_assignment" "example" {
scope = azurerm_resource_group.terraform_rg.id
role_definition_id = azurerm_role_definition.sql_role.id
principal_id = azuread_user.test.id
}
如果只希望资源组可用的自定义,则可以将资源组Id更改为assignable_scopes
为azurerm_resource_group.terraform_rg.id
。
https://stackoverflow.com/questions/62500416
复制相似问题