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
165 stars 83 forks source link

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

Open jacobkretz-bf opened 1 week ago

jacobkretz-bf commented 1 week ago

Checklist

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

jacobkretz-bf commented 1 week ago

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.