-
Notifications
You must be signed in to change notification settings - Fork 307
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
Add equivalent of CLI "--create-cert" option in azuread_service_principal #410
Comments
Hi @wawrzek, thanks for requesting. Are you perhaps looking for the azuread_service_principal_certificate resource, or more likely the azuread_application_certificate resource? |
@manicminer AFAIK none of them allows to create a certificate, only load one. Maybe Terraform native workaround would be to create self sign TLS certificate (starting from here https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) and load it to Azure SP. |
As you note there is already an official provider "azuread" {}
provider "tls" {}
resource "azuread_application" "example" {
display_name = "example"
}
resource "azuread_service_principal" "example" {
application_id = azuread_application.example.application_id
}
resource "azuread_application_certificate" "example" {
application_object_id = azuread_application.example.object_id
type = "AsymmetricX509Cert"
end_date_relative = "4320h"
value = tls_self_signed_cert.example.cert_pem
}
resource "tls_self_signed_cert" "example" {
key_algorithm = "RSA"
private_key_pem = tls_private_key.example.private_key_pem
subject {
common_name = azuread_application.example.name
organization = "Example Corp"
}
allowed_uses = ["client_auth", "server_auth"]
validity_period_hours = 4320
}
resource "tls_private_key" "example" {
algorithm = "RSA"
rsa_bits = 2048
}
output "private_key" {
value = tls_private_key.example.private_key_pem
} Hope this helps! Generally speaking, we don't just mirror Azure CLI, Powershell or Azure Portal features in Terraform as they often do not translate well. |
@manicminer thanks for help. I had to change only one line: Otherwise, I would get:
|
@wawrzek Great! I've also added this to the create-for-rbac example in the repo as it's a useful pattern. I'll close this one for now, but if you have any problems with this please feel free to comment further. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
Community Note
Description
I would like to have azuread_service_principal option to create a certificate when creating SP. I don't see such option in https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal
CLI examples:
https://docs.microsoft.com/en-us/cli/azure/ad/sp?view=azure-cli-latest#az_ad_sp_create_for_rbac-examples
New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: