0

I have two azure application registrations which are used for authentication & authorization. I would like to know how I can export them into terraform code with keeping their settings and configurations. I have been checking Azure/Aztfexport however I could not export my existing app registrations. Is there a way to do this? If so, how?

This is one of the app registrations that I have for demo purpose: enter image description here

Serhat
  • 216
  • 2
  • 17

2 Answers2

0

I have been checking Azure/Aztfexport however I could not export my existing app registrations. Is there a way to do this? If so, how?

Yes, you can export an existing Azure AD Application to terraform.tfstate using the below Terraform code.

Here is the Terraform code to export the Azure AD Application.

provider "azurerm" {
  features {}
}
resource "azuread_application" "existingADapplicationname" {
}
output "azuread_application" {
  value = azuread_application.existingADapplicationname
}

Terraform Result.

enter image description here

terraform.tfstate

enter image description here

Reference: azuread_application

Venkat V
  • 2,197
  • 1
  • 1
  • 10
  • I think there is a misunderstanding here. I was asking how to export my app registrations as terraform code, not exporting them into a terraform state – Serhat May 04 '23 at 11:07
  • Where you want to export the Azure AD Application? The terraform import azuread_application.aksapp xxxxxxxxxxxxxxxxx-xxxxxxx-xxxxx will import the application to Terraform state. – Venkat V May 04 '23 at 11:16
  • I want to export the application registration into TERRAFORM CODE DEFINITION, not the STATE. Like after exporting, I will have something like `resource "azuread_application" "myapplication" { ....... } ` – Serhat May 04 '23 at 11:42
  • You want to use the existing Azure AD Application, you can use data "azuread_application" block. https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/application – Venkat V May 04 '23 at 11:55
  • I honestly am not sure whether or not you understood the question. Please take a look at what `aztfexport` does. Your last comment is not relevant. – Serhat May 04 '23 at 13:11
  • I already know what to use, I just want a tool (in this case `aztfexport`) to create the terraform code without me explicitly re-writing all the configurations of application registration into terraform code. – Serhat May 04 '23 at 13:13
0

As per answer from aztfexport developers that you can find here:

The azuread_application belongs to the azuread provider, while aztfexport currently only support azurerm resources and they didn't plan to support azuread at this moment as it is not ARM based, but uses MS Graph API.

Which means it is currently not possible to export an azuread application registration as terraform code

Serhat
  • 216
  • 2
  • 17