Skip to content

Commit

Permalink
Fix issue with organization.metadata field not getting set to empty
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jul 16, 2022
1 parent 6f32c87 commit e5b0d5c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
13 changes: 7 additions & 6 deletions auth0/resource_auth0_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 23 additions & 3 deletions auth0/resource_auth0_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -81,17 +85,25 @@ 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 = {
primary = "#e3e2f0"
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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit e5b0d5c

Please sign in to comment.