Importing Authentik objects into Terraform
This is a super small note more for myself as i forget how to do this everytime ive wanted to do. There isnt really much documentation on the internet about how to import objects into Terraform when using the Authentik provider. As i have recently done this, i figured id note down how i did it. Ideally the docs would be updated to include this, but at time of writing they dont.
My usual flow is create the resource in Terraform, import the resource then try a terraform plan
to see what terraform wants to change. Then i can go through and modify the resource so terraform no longer wants to make changes.
System Settings
This is the one area that the Authentik documentation does have an example on their github
For the very basic resource i just used:
1
2
3
resource "authentik_system_settings" "settings" {
}
Then when im ready to try an import, its just terraform import authentik_system_settings.settings system_settings
Then you run a terraform plan
and it should complete. You can now add all your settings as they are in Authentik.
Outposts
There is no documentation for importing outposts. So this is how i managed it:
Firstly, you want to load up the API Browser then add your API key you are using for terraform. Once thats in the, search for “Outposts” in the serach box on the left.
The endpoint you want to be using is GET /outposts/instances/
. Just hit the “Try” button and it should output all the data you need about your outposts.
Now we just need to create the resource in teraform. Again i use a really basic outpost just to import it then see what i need to configure.
1
2
3
resource "authentik_outpost" "outpost-docker" {
name = "docker"
}
Now when you are ready to import we need to go back to the API browser and look for the “PK” field. Then we construct the import command using our new resource data and the PK:
terraform import authentik_outpost.outpost-docker 513c77a9-xxxx-xxx-xxxx-2b2f9124e384
Proxy Provider
This is a simpler one, we are able to grab the “id” of the provider from the URL. Again we are starting with a basic provider resource:
1
2
3
resource "authentik_provider_proxy" "proxy-alertmanager" {
name = "Provider for Alertmanager"
}
Nothing special, now for the import:
terraform import authentik_provider_proxy.proxy-alertmanager 9
Again we are referencing our nw resource, then the 9
is the “id” in Authentik which is taken from the URL:
https://authentik.blah.io/if/admin/#/core/providers/9;blahblahblah
You can see we have /core/providers/9;
in the URL, thats your “id” for the provider.
Applications
Applications are the easiest ones to import, they just use the slug of the application. So again we make a simple resource:
1
2
3
resource "authentik_application" "alertmanager" {
slug = "alertmanager"
}
Then do the import:
terraform import authentik_application.alertmanager alertmanager
Thats all there is for applications.
End
Thats really it, with this information and more importantly with access to the API Browser in Authentik, you should be able to import all the settings and configs that you want. This may be wildly known knowledge already, but my googling didnt really turn up much about importing into Terraform from Authentik, so i created my own notes to share.