Skip to content

Commit

Permalink
Bugfix: allow service principal with no features / all features disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Sep 27, 2021
1 parent 0b5c517 commit cb3d624
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 17 deletions.
46 changes: 32 additions & 14 deletions .github/ISSUE_TEMPLATE/Bug_Report.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,62 @@
---
name: 🐛 Bug Report
about: If something isn't working as expected 🤔.
about: If something isn't working as expected 🤔

---

<!---
<!--
Thank you for reporting a bug to the Terraform AzureAD Provider! We're grateful for your effort and any information you can provide that will help us improve the provider.
Please note the following potential times when an issue might be in Terraform core:
* [Configuration Language](https://www.terraform.io/docs/configuration/index.html) or resource ordering issues
* [State](https://www.terraform.io/docs/state/index.html) and [State Backend](https://www.terraform.io/docs/backends/index.html) issues
* [Provisioner](https://www.terraform.io/docs/provisioners/index.html) issues
* [Registry](https://registry.terraform.io/) issues
* Spans resources across multiple providers
* Configuration Language or ordering issues: https://www.terraform.io/docs/configuration/index.html
* State issues: https://www.terraform.io/docs/state/index.html
* State Backend issues: https://www.terraform.io/docs/backends/index.html
* Provisioner issues: https://www.terraform.io/docs/provisioners/index.html
* Registry issues: https://registry.terraform.io/
* Any resources which do not belong to this provider, e.g. should begin with `azuread_`
If you are running into one of these scenarios, we recommend opening an issue in the [Terraform core repository](https://github.com/hashicorp/terraform/) instead.
--->
If you are running into one of these scenarios, we recommend instead opening an issue in the Terraform core repository (https://github.com/hashicorp/terraform/),
or if your issue is about a resource from another provider, open an issue in that provider's GitHub repository.
-->

<!--- Please keep this note for the community --->
<!-- Please keep the following note for the community -->

### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritise this request
* Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritise the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment

<!--- Thank you for keeping this note for the community --->
<!-- Thank you for keeping this note for the community! -->

### Terraform (and AzureAD Provider) Version

<!--- Please run `terraform -v` to show the Terraform core version and provider version(s). If you are not running the latest version of Terraform or the provider, please upgrade because your issue may have already been fixed. [Terraform documentation on provider versioning](https://www.terraform.io/docs/configuration/providers.html#provider-versions). --->
<!--
Please run `terraform -v` to show the Terraform core version and provider version(s). If you are not running the latest version of Terraform or the provider, please upgrade because your issue may have already been fixed.
Terraform documentation on provider versioning: https://www.terraform.io/docs/configuration/providers.html#provider-versions
-->

### Affected Resource(s)

<!--- Please list the affected resources and data sources. --->
<!-- Please list the affected resources and data sources -->

* `azuread_XXXXX`

### Terraform Configuration Files

<!--- Information about code formatting: https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code --->
<!--
Please format your code using markdown syntax. Code that is not formatted does not display correctly and is difficult to read.
Information about code formatting: https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code
-->

```hcl
# Copy-paste your Terraform configurations here - for large Terraform configs,
Expand Down
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 cb3d624

Please sign in to comment.