Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to issue: 1296 azuread_application_pre_authorized does not properly destroy #1299

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ func applicationPreAuthorizedResourceDelete(ctx context.Context, d *pluginsdk.Re
return tf.ErrorDiagPathF(err, "id", "Parsing pre-authorized application ID %q", d.Id())
}

tf.LockByName(applicationResourceName, id.ObjectId)
defer tf.UnlockByName(applicationResourceName, id.ObjectId)

app, status, err := client.Get(ctx, id.ObjectId, odata.Query{})
if err != nil {
if status == http.StatusNotFound {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ func TestAccApplicationPreAuthorized_deprecatedId2(t *testing.T) {
})
}

func TestAccApplicationPreAuthorized_multipleCreateDestroy(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application_pre_authorized", "authorize_1")
data2 := acceptance.BuildTestData(t, "azuread_application", "authorizer")
r := ApplicationPreAuthorizedResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.multiple(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.multipleDestroy(data2),
},
{
// This step should catch any failed destroys from the previous step by throwing an ImportAsExists error
Config: r.multiple(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (ApplicationPreAuthorizedResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
client := clients.Applications.ApplicationsClientBeta
client.BaseClient.DisableRetries = true
Expand Down Expand Up @@ -249,3 +276,83 @@ resource "azuread_application_pre_authorized" "test" {
}
`, data.RandomInteger, data.UUID(), data.UUID())
}

func (ApplicationPreAuthorizedResource) multiple(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_application" "authorized_1" {
display_name = "acctestApp-authorized-1-%[1]d"
}

resource "azuread_application" "authorized_2" {
display_name = "acctestApp-authorized-2-%[1]d"
}

resource "azuread_application" "authorized_3" {
display_name = "acctestApp-authorized-3-%[1]d"
}

resource "azuread_application" "authorizer" {
display_name = "acctestApp-authorizer-%[1]d"

api {
oauth2_permission_scope {
admin_consent_description = "Administer the application"
admin_consent_display_name = "Administer"
enabled = true
id = "11111111-1111-1111-1111-111111111111"
type = "Admin"
value = "administer"
}
}
}

resource "azuread_application_pre_authorized" "authorize_1" {
application_id = azuread_application.authorizer.id
authorized_client_id = azuread_application.authorized_1.client_id
permission_ids = ["11111111-1111-1111-1111-111111111111"]
}

resource "azuread_application_pre_authorized" "authorize_2" {
application_id = azuread_application.authorizer.id
authorized_client_id = azuread_application.authorized_2.client_id
permission_ids = ["11111111-1111-1111-1111-111111111111"]
}

resource "azuread_application_pre_authorized" "authorize_3" {
application_id = azuread_application.authorizer.id
authorized_client_id = azuread_application.authorized_3.client_id
permission_ids = ["11111111-1111-1111-1111-111111111111"]
}
`, data.RandomInteger)
}

func (ApplicationPreAuthorizedResource) multipleDestroy(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_application" "authorized_1" {
display_name = "acctestApp-authorized-1-%[1]d"
}

resource "azuread_application" "authorized_2" {
display_name = "acctestApp-authorized-2-%[1]d"
}

resource "azuread_application" "authorized_3" {
display_name = "acctestApp-authorized-3-%[1]d"
}

resource "azuread_application" "authorizer" {
display_name = "acctestApp-authorizer-%[1]d"

api {
oauth2_permission_scope {
admin_consent_description = "Administer the application"
admin_consent_display_name = "Administer"
enabled = true
id = "11111111-1111-1111-1111-111111111111"
type = "Admin"
value = "administer"
}
}
}
`, data.RandomInteger)
}
Loading