terraform-provider-azureservice-principal

Service Principal Creation by Terraform doesn't provide password/secret in the output


when generating Service Principal in Azure manually, as a result of the operation I'm provided a password.

It's not the case however if I create service principal with Terraform, the password is not among the outputs of this module:

  + azuread_service_principal.k8s_principal
      id:                <computed>
      application_id:    "${azuread_application.app.application_id}"
      display_name:      <computed>

Is there anything I missed? Why does the Terraform behavior differs in the output compared to CLI?


Solution

  • to who using newer version of Terraform, you don't need to preset the password, following code is working fine:

        resource "azuread_service_principal_password" "auth_pwd" {
          service_principal_id = azuread_service_principal.auth.id
        }
        
        output "auth_client_secret" {
          value = azuread_service_principal_password.auth_pwd.value
          description = "output password"
          sensitive = true
        }
    

    then you can run the following cli to retrieve the password:

    terraform output -raw auth_client_secret
    

    tested on terraform 1.0.10, hashicorp/azuread provider 2.11