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 8c464f1
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 208 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
Loading

0 comments on commit 8c464f1

Please sign in to comment.