'Error: 409 Conflict: That action name has already been taken' when trying to use terraform to modify a custom action

I am in the process of making it so that my team uses Terraform to carry out Auth0 changes instead of doing so in the browser. I made modules for email templates and custom_text_prompts and successfully tested, meaning I can now edit these resources through vs code and terraform apply and the changes show up in the dashboard. However,my module for custom actions has not been so successful: I tried to do a terraform apply for various custom actions and get ‘│ Error: 409 Conflict: That action name has already been taken.

│ with module.test_action.auth0_action.this,
│ on modules\custom_actions\main.tf line 11, in resource “auth0_action” “this”:
│ 11: resource “auth0_action” “this” {
│‘. The block in the main.tf where it is invoked is ‘module “test_action” {
source = “./modules/custom_actions”
name = “test”
code = file(“scripts/test_action.js”)
runtime = “node18”
trigger_id = “pre-user-registration”
trigger_version = “v2”

}‘, my main.tf file in the ‘custom actions’ folder is ‘terraform {
required_version = “>= 1.5.0”
required_providers {
auth0 = {
source = “auth0/auth0”
version = “>= 1.0.0”
}
}
}

resource “auth0_action” “this” {
name = var.name
code = var.code
runtime = var.runtime
deploy = var.deploy

supported_triggers {
id = var.trigger_id
version = var.trigger_version
}

Use for_each with list of objects

dynamic “dependencies” {
for_each = var.dependencies
content {
name = dependencies.value.name
version = dependencies.value.version
}
}

# Similarly for secrets

dynamic “secrets” {
for_each = var.secrets
content {
name = secrets.value.name
value = secrets.value.value
}
}
}‘ and my variables.tf file for it is ‘variable “name” {
type = string
description = “Name of the custom action”
}

variable “code” {
type = string
description = “The code of the custom action”
}

variable “runtime” {
type = string
default = “node18”
description = “Node runtime (node12, node16, node18, node22)”
}

variable “deploy” {
type = bool
default = true
}

variable “trigger_id” {
type = string
description = “ID of the trigger, e.g., ‘post-login’”
}

variable “trigger_version” {
type = string
default = “v3”
description = “Version of the trigger, e.g., ‘v3’”
}

variable “dependencies” {
description = “List of dependencies”
type = list(object({
name = string
version = string
}))
default =
}

variable “secrets” {
description = “List of secrets”
type = list(object({
name = string
value = string
}))
default =
}‘

Hi @shayan.bhattacharya,

Welcome to the Auth0 Community!

Thank you for reaching out. The error Error: 409 Conflict: That action name has already been taken indicates that an Action with the name “test” already exists in your Auth0 tenant. This is a common Terraform state management issue that happens when a resource is already created outside of your current Terraform workspace, causing a mismatch between what Terraform expects and what actually exists in your tenant.

This happens because Terraform keeps a record of the resources it manages (its “state file”). While performing a resource "auth0_action" "this", since there isn’t an existing “test” action in its records, Terraform’s behavior is to try and create it, which causes the conflict.

The solution for actions that can be deleted from the dashboard ( unlike “custom phone provider” actions ) is to simply delete it from the Actions Library and retry.

I hope this helps, and if you have further questions please let me know!
Kind regards,
Remus