Skip to content

Commit

Permalink
Merge pull request #142 from auth0/patch/issue#33
Browse files Browse the repository at this point in the history
Fix missing options when importing a connection object
  • Loading branch information
sergiught authored Apr 19, 2022
2 parents cb5ed0f + b107ecd commit b9ac671
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions auth0/resource_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var connectionSchema = map[string]*schema.Schema{
},
"options": {
Type: schema.TypeList,
Computed: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -789,8 +790,6 @@ func readConnection(ctx context.Context, d *schema.ResourceData, m interface{})
return diag.FromErr(err)
}

d.SetId(auth0.StringValue(connection.ID))

result := multierror.Append(
d.Set("name", connection.Name),
d.Set("display_name", connection.DisplayName),
Expand Down
8 changes: 7 additions & 1 deletion auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ func TestAccConnectionWithEnabledClients(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_connection.my_connection", "name", "Acceptance-Test-Connection-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "enabled_clients.#", "4"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.#", "1"), // Gets computed with defaults by the API.
),
},
},
Expand Down Expand Up @@ -1314,15 +1315,20 @@ func TestAccConnectionSAML(t *testing.T) {
Config: random.Template(testConnectionSAMLConfigCreate, rand),
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_connection.my_connection", "name", "Acceptance-Test-SAML-{{.random}}", rand),
random.TestCheckResourceAttr("auth0_connection.my_connection", "display_name", "Acceptance-Test-SAML-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "strategy", "samlp"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "show_as_button", "false"),
random.TestCheckResourceAttr("auth0_connection.my_connection", "display_name", "Acceptance-Test-SAML-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.#", "1"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.sign_out_endpoint", "https://saml.provider/sign_out"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.entity_id", ""),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.idp_initiated.0.client_authorize_query", "type=code&timeout=30"),
),
},
{
Config: random.Template(testConnectionSAMLConfigUpdate, rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_connection.my_connection", "show_as_button", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.#", "1"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.idp_initiated.0.client_authorize_query", "type=code&timeout=60"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.sign_out_endpoint", ""),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.entity_id", "example"),
Expand Down
7 changes: 1 addition & 6 deletions auth0/structure_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func flattenConnectionOptions(d ResourceData, options interface{}) []interface{} {
if options == nil || optionsBlockIsNotDefined(d) {
if options == nil {
return nil
}

Expand Down Expand Up @@ -54,11 +54,6 @@ func flattenConnectionOptions(d ResourceData, options interface{}) []interface{}
return []interface{}{m}
}

func optionsBlockIsNotDefined(d ResourceData) bool {
_, ok := d.GetOk("options")
return !ok
}

func flattenConnectionOptionsGitHub(options *management.ConnectionOptionsGitHub) interface{} {
return map[string]interface{}{
"client_id": options.GetClientID(),
Expand Down

0 comments on commit b9ac671

Please sign in to comment.