Upgrade Auth0 Terraform Provider from Version v0.x to v1.x and Avoiding Conflicts

Overview

This article explains how to upgrade the Auth0 Terraform provider from version v0.x to v1.x.

Deleting the state and rerunning returns the following error when testing with the latest version.

Error: 409 Conflict: A connection with the same name already exists
157│
158│ with auth0_connection.CONNECTION_NAME,
159│ on main.tf line 47, in resource “auth0_connection” “CONNECTION_NAME”:
160│ 47: resource “auth0_connection” “CONNECTION_NAME” {

This forces the database to be deleted, which is not feasible for production tenants.

Solution

  1. Use the latest Auth0 Terraform provider to generate the tenant configuration of the tenant.
    Once the [auth0 tf generate ](https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/generate_terraform_config)command creates the artifact, it is recommended to spot-check it to ensure all expected resources are present and no egregious errors exist. It may be a good idea to compare it with the previous artifact to see if anything needs to be added. There is [a migration guide](https://github.com/auth0/terraform-provider-auth0/blob/main/MIGRATION_GUIDE.md#upgrading-from-v0x--v10) that may help while comparing the artifacts.
  1. The terraform state rm command can help forget the connection’s existing setting. The next call to import the connection can then be used to update the Terraform artifact with the existing connection. This helps to update the artifacts to the latest version without the need to delete the connection in the tenant. However, this approach doesn’t guarantee getting a different error for another component once this error is resolved.
terraform state rm auth0_connection.<resource name> <connID> && terraform import auth0_connection.<resource name> <connID>

NOTE: Both options above should be first tested on a non-production tenant to avoid any risk it may cause to the configuration on the production tenant.

1 Like