Skip to content

Commit

Permalink
Merge pull request #602 from hashicorp/bugfix/service-principal-no-fe…
Browse files Browse the repository at this point in the history
…atures

Bugfix: allow service principal with no features / all features disabled
  • Loading branch information
manicminer authored Sep 30, 2021
2 parents b7982c7 + f92c3a2 commit e28bc9c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func TestAccServicePrincipal_featuresUpdate(t *testing.T) {
r := ServicePrincipalResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.noFeatures(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("use_existing"),
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -178,6 +185,20 @@ func TestAccServicePrincipal_featuresUpdate(t *testing.T) {
),
},
data.ImportStep("use_existing"),
{
Config: r.noFeatures(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("use_existing"),
{
Config: r.features(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("use_existing"),
})
}

Expand Down Expand Up @@ -464,6 +485,35 @@ resource "azuread_service_principal" "test" {
`, r.templateComplete(data), data.RandomInteger)
}

func (r ServicePrincipalResource) noFeatures(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
resource "azuread_service_principal" "test" {
application_id = azuread_application.test.application_id
account_enabled = false
alternative_names = ["foo", "bar"]
app_role_assignment_required = true
description = "An internal app for testing"
login_url = "https://test-%[2]d.internal/login"
notes = "Just testing something"
preferred_single_sign_on_mode = "saml"
features {
custom_single_sign_on_app = false
enterprise_application = false
gallery_application = false
}
notification_email_addresses = [
"[email protected]",
"[email protected]",
]
}
`, r.templateComplete(data), data.RandomInteger)
}

func (ServicePrincipalResource) templateThreeUsers(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azuread" {}
Expand Down
8 changes: 5 additions & 3 deletions internal/services/serviceprincipals/serviceprincipals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/manicminer/hamilton/msgraph"
)

func expandFeatures(in []interface{}) (out []string) {
func expandFeatures(in []interface{}) []string {
out := make([]string, 0)

if len(in) == 0 || in[0] == nil {
return
return out
}

features := in[0].(map[string]interface{})
Expand All @@ -30,7 +32,7 @@ func expandFeatures(in []interface{}) (out []string) {
out = append(out, "HideApp")
}

return
return out
}

func expandSamlSingleSignOn(in []interface{}) *msgraph.SamlSingleSignOnSettings {
Expand Down

0 comments on commit e28bc9c

Please sign in to comment.