@@ -14,6 +14,7 @@ package awx
1414
1515import (
1616 "context"
17+ "encoding/json"
1718 "fmt"
1819 "log"
1920 "strconv"
@@ -61,12 +62,24 @@ func resourceNotificationTemplateCreate(ctx context.Context, d *schema.ResourceD
6162 client := m .(* awx.AWX )
6263 awxService := client .NotificationTemplatesService
6364
65+ notificationConfigurationStr := d .Get ("notification_configuration" ).(string )
66+ notificationConfigurationMap := make (map [string ]interface {})
67+ err := json .Unmarshal ([]byte (notificationConfigurationStr ), & notificationConfigurationMap )
68+ if err != nil {
69+ diags = append (diags , diag.Diagnostic {
70+ Severity : diag .Error ,
71+ Summary : "Unable to create NotificationTemplate" ,
72+ Detail : fmt .Sprintf ("error while unmarshal notification_configuration: %s" , err .Error ()),
73+ })
74+ return diags
75+ }
76+
6477 result , err := awxService .Create (map [string ]interface {}{
6578 "name" : d .Get ("name" ).(string ),
6679 "description" : d .Get ("description" ).(string ),
6780 "organization" : d .Get ("organization_id" ).(string ),
6881 "notification_type" : d .Get ("notification_type" ).(string ),
69- "notification_configuration" : d . Get ( "notification_configuration" ).( string ) ,
82+ "notification_configuration" : notificationConfigurationMap ,
7083 }, map [string ]string {})
7184 if err != nil {
7285 log .Printf ("Fail to Create notification_template %v" , err )
@@ -97,12 +110,24 @@ func resourceNotificationTemplateUpdate(ctx context.Context, d *schema.ResourceD
97110 return buildDiagNotFoundFail ("notification_template" , id , err )
98111 }
99112
113+ notificationConfigurationStr := d .Get ("notification_configuration" ).(string )
114+ notificationConfigurationMap := make (map [string ]interface {})
115+ err = json .Unmarshal ([]byte (notificationConfigurationStr ), & notificationConfigurationMap )
116+ if err != nil {
117+ diags = append (diags , diag.Diagnostic {
118+ Severity : diag .Error ,
119+ Summary : "Unable to create NotificationTemplate" ,
120+ Detail : fmt .Sprintf ("error while unmarshal notification_configuration: %s" , err .Error ()),
121+ })
122+ return diags
123+ }
124+
100125 _ , err = awxService .Update (id , map [string ]interface {}{
101126 "name" : d .Get ("name" ).(string ),
102127 "description" : d .Get ("description" ).(string ),
103128 "organization" : d .Get ("organization_id" ).(string ),
104129 "notification_type" : d .Get ("notification_type" ).(string ),
105- "notification_configuration" : d . Get ( "notification_configuration" ).( string ) ,
130+ "notification_configuration" : notificationConfigurationMap ,
106131 }, map [string ]string {})
107132 if err != nil {
108133 diags = append (diags , diag.Diagnostic {
0 commit comments