Skip to content

Commit

Permalink
Add feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyTobi committed May 29, 2024
1 parent 61dcbcd commit aa16d31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
16 changes: 13 additions & 3 deletions internal/services/applications/application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,13 @@ func applicationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, m

// set the pw credentials to state
if app.PasswordCredentials != nil {
if credentials := flattenApplicationPasswordCredentials(app.PasswordCredentials, d); credentials != nil {
d.Set("password", credentials)
var cred map[string]interface{}
for _, password := range d.Get("password").(*pluginsdk.Set).List() {
cred = password.(map[string]interface{})
}

if credentials := flattenApplicationPasswordCredentials(app.PasswordCredentials, cred); credentials != nil {
tf.Set(d, "password", credentials)
}
}

Expand Down Expand Up @@ -1406,7 +1411,12 @@ func applicationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, met
}

if app.PasswordCredentials != nil {
if credentials := flattenApplicationPasswordCredentials(app.PasswordCredentials, d); credentials != nil {
var cred map[string]interface{}
for _, password := range d.Get("password").(*pluginsdk.Set).List() {
cred = password.(map[string]interface{})
}

if credentials := flattenApplicationPasswordCredentials(app.PasswordCredentials, cred); credentials != nil {
tf.Set(d, "password", credentials)
}
}
Expand Down
31 changes: 14 additions & 17 deletions internal/services/applications/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azuread/internal/helpers"
"github.com/hashicorp/terraform-provider-azuread/internal/tf"
"github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk"
Expand Down Expand Up @@ -854,26 +853,24 @@ func flattenApplicationSpa(in *msgraph.ApplicationSpa) []map[string]interface{}
}}
}

func flattenApplicationPasswordCredentials(passwordCredentials *[]msgraph.PasswordCredential, d *schema.ResourceData) []map[string]interface{} {
if v, ok := d.GetOk("password"); ok {
for _, cred := range v.(*pluginsdk.Set).List() {
keyId := cred.(map[string]interface{})["key_id"]

// update, read case
if keyId != nil {
if credRead := helpers.GetPasswordCredential(passwordCredentials, keyId.(string)); credRead != nil {
return helpers.FlattenCredential(credRead, cred.(map[string]interface{}))
}
}
func flattenApplicationPasswordCredentials(passwordCredentials *[]msgraph.PasswordCredential, d map[string]interface{}) []map[string]interface{} {
if d == nil {
return []map[string]interface{}{}
}

// create case
for _, appCred := range *passwordCredentials {
return helpers.FlattenCredential(&appCred, cred.(map[string]interface{}))
}
// update, read case
if d["key_id"] != nil {
if credRead := helpers.GetPasswordCredential(passwordCredentials, d["key_id"].(string)); credRead != nil {
return helpers.FlattenCredential(credRead, d)
}
}

return nil
// create case
for _, appCred := range *passwordCredentials {
return helpers.FlattenCredential(&appCred, d)
}

return []map[string]interface{}{}
}

func flattenApplicationWeb(in *msgraph.ApplicationWeb) []map[string]interface{} {
Expand Down

0 comments on commit aa16d31

Please sign in to comment.