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

regression: azuread_application - don't populate the password block unless specified in config #1422

Merged
merged 1 commit into from
Jun 28, 2024
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
16 changes: 8 additions & 8 deletions internal/services/applications/application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,15 +1626,15 @@ func applicationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, met
if len(currentPassword) == 1 {
keyIdToMatch = currentPassword[0].(map[string]interface{})["key_id"].(string)
existingValue = currentPassword[0].(map[string]interface{})["value"].(string)
}

for _, credential := range flattenApplicationPasswordCredentials(app.PasswordCredentials) {
// Match against the known key ID, or select the first returned password if not present in state
if keyIdToMatch == "" || credential["key_id"] == keyIdToMatch {
// Retain the value from state, if known
credential["value"] = existingValue
passwordToSave = append(passwordToSave, credential)
break
for _, credential := range flattenApplicationPasswordCredentials(app.PasswordCredentials) {
// Match against the known key ID, or select the first returned password if not present in state
if credential["key_id"] == keyIdToMatch {
// Retain the value from state, if known
credential["value"] = existingValue
passwordToSave = append(passwordToSave, credential)
break
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions internal/services/applications/application_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,27 @@ func TestAccApplication_passwordUpdate(t *testing.T) {
})
}

func TestAccApplication_passwordNotSet(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application", "test")
r := ApplicationResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: ApplicationPasswordResource{}.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
RefreshState: true,
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("password.#").HasValue("0"),
),
},
})
}

func (r ApplicationResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
client := clients.Applications.ApplicationsClientBeta
client.BaseClient.DisableRetries = true
Expand Down
Loading