Using Terraform To Update auth0_prompt_custom_text Based On Screen

Hi all. I am trying to make it so my team uses Terraform to carry out our Auth0 tasks rather than using the dashboard. One thing I am doing right now is creating modules for branding changes, so I’m using the resource ‘auth0_prompt_custom_text’ as per the docs (auth0_prompt_custom_text | Resources | auth0/auth0 | Terraform | Terraform Registry). It’s good that there is the ‘language’ field to distinguish between the same prompt for different for languages, but is there a way to do this for screen? In the dashboard for our mfa-sms prompt, there is of course a drop-down menu for ‘language’ but also one one for ‘screen’ with options like ‘mfa-sms-list’ and ‘mfa-sms-challenge‘. Given that different screens for the same prompts have different JSON schema, I want to be able to update any one of them via terraform. This is what I have so far, so please let me know if it can be refined accordingly: ‘module “mfa_sms_es” {
source = “./modules/prompt_custom_text”
prompt = “mfa-sms”
language = “es”
body = “{}”
}‘

Hi @shayan.bhattacharya

I am sorry about the delayed response to your inquiry!

There is no screen attribute in the auth0_prompt_custom_text resource.

Instead, the screen name is defined inside the JSON payload that you pass to the body attribute. The Auth0 Management API expects a single JSON object for a given prompt and language , where the top-level keys of that JSON object are the specific screen names.

Here is an example of how you should structure your Terraform code to handle multiple screens for the mfa-sms prompt in Spanish:

module "mfa_sms_es" {
  source   = "./modules/prompt_custom_text"
  prompt   = "mfa-sms"
  language = "es"
  
  body = jsonencode(
 {    
    # Screen 1: mfa-sms-challenge
    "mfa-sms-challenge" = {
      "pageTitle" = "Autenticación segura",
      "title"     = "Ingrese el código"
    },
    
    # Screen 2: mfa-sms-list
    "mfa-sms-list" = {
      "pageTitle" = "Opciones de verificación",
      "title"     = "Elija un número de teléfono"
    }    
 })
}

As a piece of advise, in the case that your team scales this out, these JSON payloads can become quite massive, making your .tf files difficult to read. A best practice for managing Auth0 custom text in Terraform is to move the actual JSON payloads into external .json files and use Terraform’s file() function to read them.
Example JSON file:

{
  "mfa-sms-challenge": {
    "pageTitle": "Autenticación segura"
  },
  "mfa-sms-list": {
    "pageTitle": "Opciones de verificación"
  }
}

Example reference:

module "mfa_sms_es" {
  source   = "./modules/prompt_custom_text"
  prompt   = "mfa-sms"
  language = "es"
  body     = file("${path.module}/locales/mfa-sms-es.json")
}

You can check out the terraform documentation for the respective resource here.

If you have any other questions, let me know!

Kind Regards,
Nik

1 Like

Thank you very much. I do wonder how it knows which screen to act upon. I see you have the screen name above the JSON payload, but it doesn’t throw an error if you use a screen name for a screen that doesn’t exist in the dashboard. What would happen if you applied a change where the name you cited was for a screen that does not exist? Would it create a new one?

Hi again

No, it does not create a new screen.

If you supply a screen name (JSON key) that does not exist, the Auth0 API will silently accept the payload and store it in your tenant’s database, but it will have absolutely zero effect on your application. The Auth0 Universal Login engine will simply never ask for that text, so it will never be rendered.

Kind Regards,
Nik