Skip to content

Commit

Permalink
GH-593: Fix import issue on auth0_connection_clients (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored May 24, 2023
1 parent bf352fa commit 07399b6
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/auth0/connection/resource_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func readConnectionClients(_ context.Context, data *schema.ResourceData, meta in
}

result := multierror.Append(
data.Set("connection_id", connection.GetID()),
data.Set("name", connection.GetName()),
data.Set("strategy", connection.GetStrategy()),
data.Set("enabled_clients", connection.GetEnabledClients()),
Expand Down
68 changes: 68 additions & 0 deletions internal/auth0/connection/resource_clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package connection_test

import (
"fmt"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"

"github.com/auth0/terraform-provider-auth0/internal/acctest"
)
Expand Down Expand Up @@ -137,3 +139,69 @@ func TestAccConnectionClients(t *testing.T) {
},
})
}

const testAccConnectionClientsImport = `
resource "auth0_connection" "my_conn" {
name = "Acceptance-Test-{{.testName}}"
strategy = "auth0"
}
resource "auth0_client" "my_client-1" {
depends_on = [ auth0_connection.my_conn ]
name = "Acceptance-Test-Client-1-{{.testName}}"
}
resource "auth0_connection_clients" "my_conn_client_assoc" {
depends_on = [ auth0_client.my_client-1 ]
connection_id = auth0_connection.my_conn.id
enabled_clients = [ auth0_client.my_client-1.id ]
}
`

func TestAccConnectionClientsImport(t *testing.T) {
if os.Getenv("AUTH0_DOMAIN") != acctest.RecordingsDomain {
// The test runs only with recordings as it requires an initial setup.
t.Skip()
}

acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Config: acctest.ParseTestName(testAccConnectionClientsImport, t.Name()),
ResourceName: "auth0_connection.my_conn",
ImportState: true,
ImportStateId: "con_ouKiPbGv6eONERfA",
ImportStatePersist: true,
},
{
Config: acctest.ParseTestName(testAccConnectionClientsImport, t.Name()),
ResourceName: "auth0_client.my_client-1",
ImportState: true,
ImportStateId: "TGIXl1IBOpFmwBpxuCLsoXwl5OQBa1Z7",
ImportStatePersist: true,
},
{
Config: acctest.ParseTestName(testAccConnectionClientsImport, t.Name()),
ResourceName: "auth0_connection_clients.my_conn_client_assoc",
ImportState: true,
ImportStateId: "con_ouKiPbGv6eONERfA",
ImportStatePersist: true,
},
{
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
Config: acctest.ParseTestName(testAccConnectionClientsImport, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_connection_clients.my_conn_client_assoc", "strategy", "auth0"),
resource.TestCheckResourceAttr("auth0_connection_clients.my_conn_client_assoc", "name", fmt.Sprintf("Acceptance-Test-%s", t.Name())),
resource.TestCheckResourceAttr("auth0_connection_clients.my_conn_client_assoc", "enabled_clients.#", "1"),
),
},
},
})
}
Loading

0 comments on commit 07399b6

Please sign in to comment.