I have written terraform for creating the user, resource group, and roledefinition.
I need to have the scope of resource definition be the resource group that I created.
I don't know how to do that. It would be great if someone could help on this.
########### 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 = "[email protected]"
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"
]
}
Getting following error while executing above code:
Error: authorization.RoleDefinitionsClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="MissingSubscription" Message="The request did not have a subscription or a valid tenant level resource provider."
How do I make the scope of a custom role be Resourcegroup in azure?