Search code examples
postgresqlazureterraformazure-active-directoryterraform-provider-azure

How to Terraform import azurerm_postgresql_active_directory_administrator for a postgresql flexible server on Azure


I created a PostgreSQL flexible server on Azure manually, since there is an error creating it through Terraform. When creating the flexible server, there is an option to select AAD Server admin:

enter image description here

After creating the whole resource, I am trying to import it into Terraform. For specifying the AAD Server admin, I tried using the following resource: "azurerm_postgresql_active_directory_administrator". For that resource, the import command that is available inside the documentation would be: terraform import azurerm_postgresql_active_directory_administrator.administrator /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.DBforPostgreSQL/servers/myserver

My question is, is there an alternative for this, can this "azurerm_postgresql_active_directory_administrator.administrator" resource even be used for flexible servers? Does it need to be used?

I tried using my flexible servers resource ID, but I get the following error:

Expected a Server ID that matched: │ │ > /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/servers/serverValue │ │ However this value was provided: │ │ > /subscriptions/<my__sensitive_subscription_id>/resourceGroups/hrpap-dev-db-postgres-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/hrpap-dev-db-postgres-database-flex/administrators/<object_id> │ │ The parsed Resource ID was missing a value for the segment at position 6 │ (which should be the literal value "servers").


Solution

  • Apparently, there is a new resource for that, with a little bit different configuration required:

    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_active_directory_administrator