Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Managed Identity users #129

Open
waylew50 opened this issue Jun 29, 2023 · 3 comments
Open

Issues with Managed Identity users #129

waylew50 opened this issue Jun 29, 2023 · 3 comments

Comments

@waylew50
Copy link

I am trying to figure out what I am doing wrong when I try to create a user from an azure resource system managed identity, I tried using the mssql_azuread_service_principal which says it supports managed identity. It will create the user, but when I test that resources access I get a login failed for principal.

here is the terraform I am using:

resource "mssql_azuread_service_principal" "principal" {
        name        = data.azurerm_virtual_machine_scale_set.WriterBuildAgent.name
       client_id   = data.azurerm_virtual_machine_scale_set.WriterBuildAgent.identity[0].principal_id
       database_id = var.azure_sql_database_id
}

I noticed when I compare the outputs from the azurerm principal_id and the mssql_azuread_service_principal.client_id they do not match. the client_id produces a value that I cannot find on the resource. I also tried the mssql_azuread_user resource, but it produced the same error.

other then that, I love the provider!

please advise.
Thanks.

@devicenul1
Copy link

I'm having a similar issue, wondering if support for System Managed Identities isn't supported? Basically just trying to cover the first line of the below coding scenario with this provider:

create user [az-resource-name] from external provider
ALTER role db_owner add member [az-resource-name]

@tiwood
Copy link

tiwood commented Sep 12, 2023

The resource property is client_id (aka application id) but you are referencing the principal_id (object id). Could this be the problem?

@l33tCod-er
Copy link

I think @tiwood is right:

You need to do:

data "azuread_service_principal" "your_identity" {
  object_id = data.azurerm_virtual_machine_scale_set.WriterBuildAgent.identity[0].principal_id
}

And then:

resource "mssql_azuread_service_principal" "principal" {
       name       = data.azurerm_virtual_machine_scale_set.WriterBuildAgent.name
       client_id   = data.azuread_service_principal.your_identity.application_id
       database_id = var.azure_sql_database_id
}

application_id -> client_id with latest AzureAd TF provider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants