auth0/terraform-provider-auth0

Import of an auth0_resource_server_scopes unable to use existing scopes due to reorder

Opened this issue · 1 comments

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of this provider and the issue still persists.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I'm trying to import auth0_resource_server_scopes resource and it appears that the resources is alphabetizing the scopes which leads to it want to delete all the scopes and recreate them. This would break any clients and may break association resources as the underlying ids would like change.

Expectation

Scopes should not be recreated on import if they already exist on the resource server.

Reproduction

~ resource "auth0_resource_server_scopes" "scopes" {
id = "foo"
resource_server_identifier = "foo"

  - scopes {
      - description = "b description" -> null
      - name        = "b" -> null
    }
  - scopes {
      - description = "a description" -> null
      - name        = "a" -> null
    }
  + scopes {
      + description = "a description"
      + name        = "a"
    }
  + scopes {
      + description = "b description"
      + name        = "b"
    }

Auth0 Terraform Provider version

1.7.1

Terraform version

1.7.3

For those that find this ticket. Here is the path to successfully import the scopes into the auth0_resoruce_server_scopes resource.

  1. Import each of the scopes using the auth0_resource_server_scope resource first. This is clearly doing something within Auth0 to add additional metadata on the scopes to enable the auth0_resource_server_scopes to behave appropriately.
  2. After you apply the import from 1. Import the scopes into the auth0_resource_service_scopes resource. In you plan you should see a successful import. The trick is what to do with the newly imported auth0_resource_service_scope resources you imported in step1. You can either use a removed block or you can manually remove them from the state file.