Skip to content

Commit

Permalink
azuread_application: correctly set prevent_duplicate_names on read to…
Browse files Browse the repository at this point in the history
… prevent unwanted diff, improve test cases
  • Loading branch information
manicminer committed Nov 26, 2020
1 parent f66b2f2 commit 66edeed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
6 changes: 4 additions & 2 deletions internal/services/aadgraph/application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ func applicationResourceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("setting `owners`: %+v", err)
}

if preventDuplicates := d.Get("prevent_duplicate_names").(bool); !preventDuplicates {
d.Set("prevent_duplicate_names", false)
preventDuplicates := false
if v := d.Get("prevent_duplicate_names").(bool); v {
preventDuplicates = v
}
d.Set("prevent_duplicate_names", preventDuplicates)

return nil
}
Expand Down
35 changes: 32 additions & 3 deletions internal/services/aadgraph/application_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestAccApplication_oauth2PermissionsUpdate(t *testing.T) {
})
}

func TestAccApplication_preventDuplicateNames(t *testing.T) {
func TestAccApplication_preventDuplicateNamesOk(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application", "test")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -487,7 +487,27 @@ func TestAccApplication_preventDuplicateNames(t *testing.T) {
CheckDestroy: testCheckApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccApplication_duplicateName(data.RandomInteger),
Config: testAccApplication_preventDuplicateNamesOk(data.RandomInteger),
Check: resource.ComposeTestCheckFunc(
testCheckApplicationExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest-APP-%[1]d", data.RandomInteger)),
),
},
data.ImportStep("prevent_duplicate_names"),
},
})
}

func TestAccApplication_preventDuplicateNamesFail(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccApplication_preventDuplicateNamesFail(data.RandomInteger),
ExpectError: regexp.MustCompile("existing Application .+ was found"),
},
},
Expand Down Expand Up @@ -904,7 +924,16 @@ resource "azuread_application" "test" {
`, ri)
}

func testAccApplication_duplicateName(ri int) string {
func testAccApplication_preventDuplicateNamesOk(ri int) string {
return fmt.Sprintf(`
resource "azuread_application" "test" {
name = "acctest-APP-%[1]d"
prevent_duplicate_names = true
}
`, ri)
}

func testAccApplication_preventDuplicateNamesFail(ri int) string {
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit 66edeed

Please sign in to comment.