Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-593: Fix import issue on auth0_connection_clients #594

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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