Skip to content

Commit

Permalink
Merge pull request #1422 from hashicorp/bugfix/application-marked-sen…
Browse files Browse the repository at this point in the history
…sitive

regression: `azuread_application` - don't populate the `password` block unless specified in config
  • Loading branch information
manicminer committed Jun 28, 2024
2 parents 1ad927e + 0177c80 commit 747c29b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
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

0 comments on commit 747c29b

Please sign in to comment.