Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
fix: Fixed DN modification
Browse files Browse the repository at this point in the history
This fixes the modification of the DN which resulted in a wrong ID change.
  • Loading branch information
dploeger committed Feb 22, 2023
1 parent 942e7b5 commit eb75e3a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/provider/ldap_object_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ func (L *LDAPObjectResource) ModifyPlan(ctx context.Context, request resource.Mo
// don't ignore any attributes on create and delete
return
}

if stateData != nil && planData != nil && stateData.DN != planData.DN {
response.Diagnostics.Append(response.Plan.SetAttribute(ctx, path.Root("id"), types.StringUnknown())...)
if response.Diagnostics.HasError() {
return
}
}

var planAttributes map[string][]string
response.Diagnostics.Append(planData.Attributes.ElementsAs(ctx, &planAttributes, false)...)
var stateAttributes map[string][]string
Expand Down
37 changes: 36 additions & 1 deletion internal/provider/ldap_object_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestLDAPObjectResource(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
// Create test
{
Config: testCreateConfig,
Check: resource.ComposeAggregateTestCheckFunc(
Expand All @@ -22,18 +22,21 @@ func TestLDAPObjectResource(t *testing.T) {
resource.TestCheckResourceAttr("ldap_object.test", "attributes.userPassword.0", "password"),
),
},
// Update test
{
Config: testUpdateConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ldap_object.test", "attributes.sn.0", "test2"),
),
},
// Update an ignored attribute
{
Config: testUpdateIgnoreConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ldap_object.test", "attributes.userPassword.0", "password"),
),
},
// Update an ignored attribute which was changed externally
{
Config: testUpdateIgnoreConfig,
PreConfig: testChangePasswordExternally,
Expand All @@ -51,6 +54,25 @@ func TestLDAPObjectResource(t *testing.T) {
resource.TestCheckResourceAttr("ldap_object.importtest", "attributes.sn.0", "test"),
),
},
// Update DN
{
Config: testUpdateDN,
PreConfig: testChangePasswordExternally,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ldap_object.test", "dn", "cn=test2,dc=example,dc=com"),
),
},
// Test import
{
Config: testImport,
PreConfig: testImportPreConfig,
ImportState: true,
ImportStateId: "cn=importtest,dc=example,dc=com",
ResourceName: "ldap_object.importtest",
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ldap_object.importtest", "attributes.sn.0", "test"),
),
},
}},
)
}
Expand Down Expand Up @@ -113,6 +135,19 @@ resource "ldap_object" "test" {
}
`

const testUpdateDN = `
resource "ldap_object" "test" {
dn = "cn=test2,dc=example,dc=com"
object_classes = ["person"]
attributes = {
"cn" = ["test2"]
"sn" = ["test2"]
"userPassword" = ["password"]
}
ignore_changes = ["userPassword"]
}
`

const testImport = `
resource "ldap_object" "importtest" {
}
Expand Down

0 comments on commit eb75e3a

Please sign in to comment.