Skip to content

Commit

Permalink
Merge pull request hashicorp#1050 from Noel-Jones/bugfix/sp-owner-rem…
Browse files Browse the repository at this point in the history
…oval

Bugfix: serviceprincipal owner removal hashicorp#1049
  • Loading branch information
manicminer authored Mar 21, 2023
2 parents 0a250c5 + 6966539 commit 432ffb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ func servicePrincipalResourceUpdate(ctx context.Context, d *schema.ResourceData,
return tf.ErrorDiagF(err, "Updating service principal with object ID: %q", d.Id())
}

if v, ok := d.GetOk("owners"); ok && d.HasChange("owners") {
if d.HasChange("owners") {
owners, _, err := client.ListOwners(ctx, d.Id())
if err != nil {
return tf.ErrorDiagF(err, "Could not retrieve owners for service principal with object ID: %q", d.Id())
}

desiredOwners := *tf.ExpandStringSlicePtr(v.(*schema.Set).List())
desiredOwners := *tf.ExpandStringSlicePtr(d.Get("owners").(*schema.Set).List())
existingOwners := *owners
ownersForRemoval := utils.Difference(existingOwners, desiredOwners)
ownersToAdd := utils.Difference(desiredOwners, existingOwners)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestAccServicePrincipal_owners(t *testing.T) {
},
data.ImportStep(),
{
Config: r.basic(data),
Config: r.noOwners(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("owners.#").HasValue("0"),
Expand Down Expand Up @@ -534,19 +534,19 @@ resource "azuread_user" "testC" {
`, data.RandomInteger, data.RandomPassword)
}

func (ServicePrincipalResource) noOwners(data acceptance.TestData) string {
func (r ServicePrincipalResource) noOwners(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azuread" {}
%[1]s
resource "azuread_application" "test" {
display_name = "acctestServicePrincipal-%[1]d"
display_name = "acctestServicePrincipal-%[2]d"
}
resource "azuread_service_principal" "test" {
application_id = azuread_application.test.application_id
owners = []
}
`, data.RandomInteger)
`, r.templateThreeUsers(data), data.RandomInteger)
}

func (r ServicePrincipalResource) singleOwner(data acceptance.TestData) string {
Expand Down

0 comments on commit 432ffb9

Please sign in to comment.