diff --git a/vault/resource_identity_entity.go b/vault/resource_identity_entity.go index 6674c6594..287a2d8a1 100644 --- a/vault/resource_identity_entity.go +++ b/vault/resource_identity_entity.go @@ -103,7 +103,7 @@ func identityEntityUpdateFields(d *schema.ResourceData, data map[string]interfac // should be configured on the entity. data["external_policies"] = d.Get("external_policies").(bool) if data["external_policies"].(bool) { - data["policies"] = nil + delete(data, "policies") } } } diff --git a/vault/resource_identity_entity_policies_test.go b/vault/resource_identity_entity_policies_test.go index abaa79983..ae38862cd 100644 --- a/vault/resource_identity_entity_policies_test.go +++ b/vault/resource_identity_entity_policies_test.go @@ -69,6 +69,16 @@ func TestAccIdentityEntityPoliciesNonExclusive(t *testing.T) { resource.TestCheckResourceAttr("vault_identity_entity_policies.test", "policies.0", "foo"), ), }, + { + Config: testAccIdentityEntityPoliciesConfigNonExclusiveUpdateEntity(entity), + Check: resource.ComposeTestCheckFunc( + testAccIdentityEntityPoliciesCheckLogical("vault_identity_entity.entity", []string{"dev", "foo"}), + resource.TestCheckResourceAttr("vault_identity_entity_policies.dev", "policies.#", "1"), + resource.TestCheckResourceAttr("vault_identity_entity_policies.dev", "policies.0", "dev"), + resource.TestCheckResourceAttr("vault_identity_entity_policies.test", "policies.#", "1"), + resource.TestCheckResourceAttr("vault_identity_entity_policies.test", "policies.0", "foo"), + ), + }, }, }) } @@ -266,6 +276,31 @@ resource "vault_identity_entity_policies" "dev" { } +resource "vault_identity_entity_policies" "test" { + entity_id = vault_identity_entity.entity.id + exclusive = false + policies = ["foo"] +} +`, entity) +} + +func testAccIdentityEntityPoliciesConfigNonExclusiveUpdateEntity(entity string) string { + return fmt.Sprintf(` +resource "vault_identity_entity" "entity" { + name = "%s" + external_policies = true + metadata = { + version = "1" + } +} + +resource "vault_identity_entity_policies" "dev" { + entity_id = vault_identity_entity.entity.id + exclusive = false + policies = ["dev"] +} + + resource "vault_identity_entity_policies" "test" { entity_id = vault_identity_entity.entity.id exclusive = false