auth0 / terraform-provider-auth0

The Auth0 Terraform Provider is the official plugin for managing Auth0 tenant configuration through the Terraform tool.
https://registry.terraform.io/providers/auth0/auth0/latest/docs
Mozilla Public License 2.0
167 stars 86 forks source link

Can't add basic properties to auth0_form #1055

Closed Flaaj closed 4 weeks ago

Flaaj commented 1 month ago

Checklist

Description

I tried adding a form through terraform.

this is the config:

resource "auth0_form" "marketing_opt_ins_form" {
  name = "Marketing Opt-Ins Form"

  start = jsonencode({
    coordinates = {
      x = 0
      y = 0
    }
    next_node = "step_marketing_opt_ins_form"
  })

  nodes = jsonencode([
    {
      alias = "OptIns Screen"
      config = {
        components = [
          {
            category = "BLOCK"
            config   = { content = "We'll send you marketing emails. Agree?" }
            id       = "rich_text_hdem"
            type     = "RICH_TEXT"
          },
          {
            category  = "FIELD"
            config    = { text = "<p>Yes and continue</p>" }
            required  = false
            transient = false
            id        = "marketing_consent_yes"
            type      = "LEGAL"
          },
          {
            category  = "FIELD"
            config    = { text = "<p>No and continue</p>" }
            required  = false
            transient = false
            id        = "marketing_consent_no"
            type      = "LEGAL"
          },
          {
            category = "BLOCK"
            config   = { text = "Submit" }
            id       = "next_button_feFY"
            type     = "NEXT_BUTTON"
          }
        ]
        next_node = "$ending"
      }
      coordinates = {
        x = 500
        y = 0
      }
      id   = "step_marketing_opt_ins_form"
      type = "STEP"
    }
  ])

  ending = jsonencode({
    coordinates = {
      x = 1500
      y = 0
    }
    resume_flow = true
  })

  languages {
    default = "en"
    primary = "en"
  }
}

Terraform errored, giving below error message.

Error: 400 Bad Request: Payload validation error: 'None of the valid schemas were met' on property nodes[0] ({description}). Inner errors: [ Payload validation error: 'Additional properties not allowed: components' on property nodes[0].config ({description}). (also) Payload validation error: 'Invalid value "STEP"' on property nodes[0].type. (also) Payload validation error: 'Additional properties not allowed: next_node,components' on property nodes[0].config ({description}). (also) Payload validation error: 'None of the valid schemas were met' on property nodes[0].config.components[2] ({description}). Inner errors: [ Payload validation error: 'Additional properties not allowed: transient,required' on property config.components[2] ({description}). (also) Payload validation error: 'Additional properties not allowed: transient' on property config.components[2] ({description}). ]. ].

It seems like I can't use any property name. Is it a bug or am I doing something wrong?

Expectation

The plan should succeed.

Reproduction

  1. Paste the above auth0_form resource code fragment into your terraform file
  2. Run a terraform plan from your terraform file.

Auth0 Terraform Provider version

1.7.1

Terraform version

1.2.0

kushalshit27 commented 4 weeks ago

Hi, @Flaaj is the "Marketing Opt-Ins Form" created via UI, or is it created from scratch with Terraform?

Flaaj commented 4 weeks ago

@kushalshit27 We used to add this manually in the UI, but since we have multiple tenants, we want to move to terraform. The code snippet from above is my attempt at doing this.

To generate the terraform config for nodes property I exported the existing form from the UI and pasted it here. I couldn't find any documentation regarding what properties are allowed in the "nodes" field so i figured that maybe it's the same or similar to what is currently used by the UI.

I also checked if it's correct according to the example and it seems like it should work.

I can't figure out why the errors are saying that for instance I can't have "components" property in nodes[0]. It's like this in the example

kushalshit27 commented 4 weeks ago

Hi, @Flaaj Can you please try this ?

resource "auth0_form" "marketing_opt_ins_form" {
  name = "New-Marketing Opt-Ins Form"
  start = jsonencode({
    coordinates = {
      x = 0
      y = 0
    }
    next_node = "step_yxSb"
  })
  nodes = jsonencode([{
    alias = "OptIns Screen"
    config = {
      components = [
        {
        category = "BLOCK"
        config = {
          content = "<p>We'll send you marketing emails. Agree?</p>"
        }
        id   = "rich_text_iieY"
        type = "RICH_TEXT"
        }, 
        {
        category = "FIELD"
        config = {
          text = "<p>Yes and continue</p>"
        }
        id        = "legal_0ekb"
        required  = false
        sensitive = false
        type      = "LEGAL"
        }, 
        {
        category = "FIELD"
        config = {
          text = "<p>No and continue</p>"
        }
        id        = "legal_Bcln"
        required  = false
        sensitive = false
        type      = "LEGAL"
        }, 
        {
        category = "BLOCK"
        config = {
          text = "Submit"
        }
        id   = "next_button_MoC0"
        type = "NEXT_BUTTON"
      }]
      next_node = "$ending"
    }
    coordinates = {
      x = 500
      y = 0
    }
    id   = "step_yxSb"
    type = "STEP"
  }])
  ending = jsonencode({
    coordinates = {
      x = 1250
      y = 0
    }
    resume_flow = true
  })
  languages {
    default = "en"
    primary = "en"
  }
}

Foms resources are complex due to their nested JSON nature. I recommend using UI first to create a form. Then, if it looks good, export it as a Terraform file; the generated Terraform is ready to be used on any tenant without using UI.

Flaaj commented 4 weeks ago

@kushalshit27 Hey, thank you very much, this worked. I don't understand though why? Can you point to a line in my code that caused an error?

Also, how can I export as terraform file? I only have option to export as json.

msinstil commented 4 weeks ago

This issue persists for IMAGE Component, it seems to be not supported yet from terraform:

{
              id= "image_YTvB"
              type= "IMAGE"
              config= {
                src      = "someURL"
                width    = 200
                height   = 76
                position ="CENTER"
              }
              category = "BLOCK"
            },

Heres the error when adding an Image component to Form: Error: 400 Bad Request: Payload validation error: 'None of the valid schemas were met' on property nodes[0] ({description}). Inner errors: [ Payload validation error: 'Additional properties not allowed: components' on property nodes[0].config ({description}). (also) Payload validation error: 'Invalid value "STEP"' on property nodes[0].type. (also) Payload validation error: 'Additional properties not allowed: next_node,components' on property nodes[0].config ({description}). (also) Payload validation error: 'None of the valid schemas were met' on property nodes[0].config.components[0] ({description}). Inner errors: [ Payload validation error: 'None of the valid schemas were met' on property config.components[0] ({description}). Inner errors: [ Payload validation error: 'Additional properties not allowed: width,src,position,height' on property config ({description}). (also) Payload validation error: 'Invalid value "IMAGE"' on property type. (also) Payload validation error: 'Additional properties not allowed: width' on property config ({description}). ]. (also) Payload validation error: 'None of the valid schemas were met' on property config.components[0] ({description}). Inner errors: [ Payload validation error: 'Additional properties not allowed: width,src,position,height' on property config ({description}). (also) Payload validation error: 'Invalid value "IMAGE"' on property type. ]. ]. ].

kushalshit27 commented 4 weeks ago

Hi, @Flaaj Thanks for updating, we will check that.

Export existing form to terraform file

Please use Terraform version 1.9.x for better support of jsonencode

[This resource can be imported using the form ID.]

main.tf

terraform {
  required_providers {
    auth0 = {
      source  = "auth0/auth0"
      version = ">= 1.7.1"
    }
  }
}
import {
  id = "ap_ojkKbiPMG6J5E5VCKdeCzK"
  to = auth0_form. my_form
}

run command:

terraform plan -generate-config-out=terraform_generated.tf

terraform_generated.tf will contain Exported auth0_form.my_form resource.