diff --git a/auth0/resource_auth0_organization.go b/auth0/resource_auth0_organization.go index 5025424d..0af333da 100644 --- a/auth0/resource_auth0_organization.go +++ b/auth0/resource_auth0_organization.go @@ -144,12 +144,11 @@ func updateOrganization(ctx context.Context, d *schema.ResourceData, m interface func deleteOrganization(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { api := m.(*management.Management) if err := api.Organization.Delete(d.Id()); err != nil { - if mErr, ok := err.(management.Error); ok { - if mErr.Status() == http.StatusNotFound { - d.SetId("") - return nil - } + if err, ok := err.(management.Error); ok && err.Status() == http.StatusNotFound { + d.SetId("") + return nil } + return diag.FromErr(err) } return nil @@ -202,10 +201,12 @@ func updateOrganizationConnections(d *schema.ResourceData, api *management.Manag } func expandOrganization(d *schema.ResourceData) *management.Organization { + metadata := Map(d, "metadata") + organization := &management.Organization{ Name: String(d, "name"), DisplayName: String(d, "display_name"), - Metadata: Map(d, "metadata"), + Metadata: &metadata, } List(d, "branding").Elem(func(d ResourceData) { diff --git a/auth0/resource_auth0_organization_test.go b/auth0/resource_auth0_organization_test.go index 6ed9bf99..7003397b 100644 --- a/auth0/resource_auth0_organization_test.go +++ b/auth0/resource_auth0_organization_test.go @@ -71,6 +71,10 @@ resource auth0_organization acme { name = "test-{{.testName}}" display_name = "Acme Inc. {{.testName}}" + metadata = { + some_key = "some_value" + } + connections { connection_id = auth0_connection.acme.id } @@ -81,6 +85,12 @@ const testAccOrganizationUpdate = testAccOrganizationGiven2Connections + ` resource auth0_organization acme { name = "test-{{.testName}}" display_name = "Acme Inc. {{.testName}}" + + metadata = { + some_key = "some_value" + another_key = "another_value" + } + branding { logo_url = "https://acme.com/logo.svg" colors = { @@ -88,10 +98,12 @@ resource auth0_organization acme { page_background = "#e3e2ff" } } + connections { connection_id = auth0_connection.acme.id assign_membership_on_login = false } + connections { connection_id = auth0_connection.acmeinc.id assign_membership_on_login = true @@ -104,6 +116,10 @@ resource auth0_organization acme { name = "test-{{.testName}}" display_name = "Acme Inc. {{.testName}}" + metadata = { + some_key = "some_value" + } + branding { logo_url = "https://acme.com/logo.svg" colors = { @@ -151,7 +167,8 @@ func TestAccOrganization(t *testing.T) { resource.TestCheckResourceAttr("auth0_organization.acme", "name", fmt.Sprintf("test-%s", strings.ToLower(t.Name()))), resource.TestCheckResourceAttr("auth0_organization.acme", "display_name", fmt.Sprintf("Acme Inc. %s", strings.ToLower(t.Name()))), resource.TestCheckResourceAttr("auth0_organization.acme", "branding.#", "0"), - resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "0"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "1"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.some_key", "some_value"), resource.TestCheckResourceAttr("auth0_organization.acme", "connections.#", "1"), resource.TestCheckResourceAttrSet("auth0_organization.acme", "connections.0.connection_id"), resource.TestCheckResourceAttr("auth0_organization.acme", "connections.0.assign_membership_on_login", "false"), @@ -167,7 +184,9 @@ func TestAccOrganization(t *testing.T) { resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.%", "2"), resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.primary", "#e3e2f0"), resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.page_background", "#e3e2ff"), - resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "0"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "2"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.some_key", "some_value"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.another_key", "another_value"), resource.TestCheckResourceAttr("auth0_organization.acme", "connections.#", "2"), resource.TestCheckResourceAttrSet("auth0_organization.acme", "connections.0.connection_id"), resource.TestCheckResourceAttrSet("auth0_organization.acme", "connections.1.connection_id"), @@ -185,7 +204,8 @@ func TestAccOrganization(t *testing.T) { resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.%", "2"), resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.primary", "#e3e2f0"), resource.TestCheckResourceAttr("auth0_organization.acme", "branding.0.colors.page_background", "#e3e2ff"), - resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "0"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.%", "1"), + resource.TestCheckResourceAttr("auth0_organization.acme", "metadata.some_key", "some_value"), resource.TestCheckResourceAttr("auth0_organization.acme", "connections.#", "1"), resource.TestCheckResourceAttrSet("auth0_organization.acme", "connections.0.connection_id"), resource.TestCheckResourceAttr("auth0_organization.acme", "connections.0.assign_membership_on_login", "false"), diff --git a/go.mod b/go.mod index 3b7cf99f..c4516a07 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/auth0/terraform-provider-auth0 go 1.18 require ( - github.com/auth0/go-auth0 v0.9.1 + github.com/auth0/go-auth0 v0.0.0-20220716094447-e60ada72a1b4 github.com/dnaeon/go-vcr/v2 v2.0.1 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-multierror v1.1.1 diff --git a/go.sum b/go.sum index cd75b429..98daee4a 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJE github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/auth0/go-auth0 v0.9.1 h1:sc9w+Znl53KXdgYFCLbFz93mW9aJlNK49u/KBsfbmUc= -github.com/auth0/go-auth0 v0.9.1/go.mod h1:kxxGNgF592VPvWSNPVWNbmWHs+R9c0MZCTuW+T3NgZw= +github.com/auth0/go-auth0 v0.0.0-20220716094447-e60ada72a1b4 h1:H2ILaw5C8vZmb5CC3DGHBxZ++KWwE8x5o/Zk5Y8nmNc= +github.com/auth0/go-auth0 v0.0.0-20220716094447-e60ada72a1b4/go.mod h1:kxxGNgF592VPvWSNPVWNbmWHs+R9c0MZCTuW+T3NgZw= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=