How to mimic az ad sp create-for-rbac in terraform?

According to this github issue, Once could successfully use terraform to automate az ad sp create-for-rbac and automate the sp creation that would allow the sp to manage related resources.

Does this no longer work? That code is old, and I updated my code as best I could. Here it is decorated with links to the resources I used, for reference.

Note, I am the owner of my subscription. I can run the az cli commands no problem

data "azurerm_subscription" "current" {}
data "azuread_client_config" "current" {}

resource "random_id" "current" {
  byte_length = 8
  prefix      = "ExternalDnsTf"

# Create Azure AD App.
resource "azuread_application" "current" {
  display_name = random_id.current.hex
  owners       = [data.azuread_client_config.current.object_id]


# Create Service Principal associated with the Azure AD App
resource "azuread_service_principal" "current" {
  application_id               = azuread_application.current.application_id
  app_role_assignment_required = false
  owners                       = [data.azuread_client_config.current.object_id]

# Create Service Principal password
resource "azuread_application_password" "current" {
  application_object_id = azuread_application.current.object_id

# Create role assignment for service principal
resource "azurerm_role_assignment" "current" {
  scope                =
  role_definition_name = "Contributor"

  # When assigning to a SP, use the object_id, not the appId
  # see:
  principal_id = azuread_service_principal.current.object_id