@@ -52,6 +52,11 @@ func ResourceIBMEnCustomEmailDestination() *schema.Resource {
5252 Optional : true ,
5353 Description : "Whether to collect the failed event in Cloud Object Storage bucket" ,
5454 },
55+ "verification_type" : & schema.Schema {
56+ Type : schema .TypeString ,
57+ Optional : true ,
58+ Description : "Verification Method spf/dkim." ,
59+ },
5560 "config" : {
5661 Type : schema .TypeList ,
5762 MaxItems : 1 ,
@@ -61,7 +66,6 @@ func ResourceIBMEnCustomEmailDestination() *schema.Resource {
6166 Schema : map [string ]* schema.Schema {
6267 "params" : {
6368 Type : schema .TypeList ,
64- MaxItems : 1 ,
6569 Optional : true ,
6670 Elem : & schema.Resource {
6771 Schema : map [string ]* schema.Schema {
@@ -70,6 +74,54 @@ func ResourceIBMEnCustomEmailDestination() *schema.Resource {
7074 Required : true ,
7175 Description : "Domain for the Custom Domain Email Destination" ,
7276 },
77+ "dkim" : & schema.Schema {
78+ Type : schema .TypeList ,
79+ Computed : true ,
80+ Description : "The DKIM attributes." ,
81+ Elem : & schema.Resource {
82+ Schema : map [string ]* schema.Schema {
83+ "public_key" : & schema.Schema {
84+ Type : schema .TypeString ,
85+ Computed : true ,
86+ Description : "dkim public key." ,
87+ },
88+ "selector" : & schema.Schema {
89+ Type : schema .TypeString ,
90+ Computed : true ,
91+ Description : "dkim selector." ,
92+ },
93+ "verification" : & schema.Schema {
94+ Type : schema .TypeString ,
95+ Computed : true ,
96+ Description : "dkim verification." ,
97+ },
98+ },
99+ },
100+ },
101+ "spf" : & schema.Schema {
102+ Type : schema .TypeList ,
103+ Computed : true ,
104+ Description : "The SPF attributes." ,
105+ Elem : & schema.Resource {
106+ Schema : map [string ]* schema.Schema {
107+ "txt_name" : & schema.Schema {
108+ Type : schema .TypeString ,
109+ Computed : true ,
110+ Description : "spf text name." ,
111+ },
112+ "txt_value" : & schema.Schema {
113+ Type : schema .TypeString ,
114+ Computed : true ,
115+ Description : "spf text value." ,
116+ },
117+ "verification" : & schema.Schema {
118+ Type : schema .TypeString ,
119+ Computed : true ,
120+ Description : "spf verification." ,
121+ },
122+ },
123+ },
124+ },
73125 },
74126 },
75127 },
@@ -222,6 +274,7 @@ func resourceIBMEnCustomEmailDestinationUpdate(context context.Context, d *schem
222274 }
223275
224276 options := & en.UpdateDestinationOptions {}
277+ verifyCustomEmailDestinationConfiguration := & en.UpdateVerifyDestinationOptions {}
225278
226279 parts , err := flex .SepIdParts (d .Id (), "/" )
227280 if err != nil {
@@ -231,6 +284,12 @@ func resourceIBMEnCustomEmailDestinationUpdate(context context.Context, d *schem
231284
232285 options .SetInstanceID (parts [0 ])
233286 options .SetID (parts [1 ])
287+ verifyCustomEmailDestinationConfiguration .SetType (d .Get ("verification_type" ).(string ))
288+ verifyCustomEmailDestinationConfiguration .SetInstanceID (parts [0 ])
289+ verifyCustomEmailDestinationConfiguration .SetID (parts [1 ])
290+ hasChangeverification := false
291+
292+ verifyCustomEmailDestinationConfiguration .SetType (d .Get ("verification_type" ).(string ))
234293
235294 if ok := d .HasChanges ("name" , "description" , "collect_failed_events" , "config" ); ok {
236295 options .SetName (d .Get ("name" ).(string ))
@@ -244,6 +303,11 @@ func resourceIBMEnCustomEmailDestinationUpdate(context context.Context, d *schem
244303 }
245304
246305 destinationtype := d .Get ("type" ).(string )
306+
307+ if d .HasChange ("verification_type" ) {
308+ verifyCustomEmailDestinationConfiguration .SetType (d .Get ("verification_type" ).(string ))
309+ hasChangeverification = true
310+ }
247311 if _ , ok := d .GetOk ("config" ); ok {
248312 config := CustomEmaildestinationConfigMapToDestinationConfig (d .Get ("config.0.params.0" ).(map [string ]interface {}), destinationtype )
249313 options .SetConfig (& config )
@@ -255,6 +319,13 @@ func resourceIBMEnCustomEmailDestinationUpdate(context context.Context, d *schem
255319 return tfErr .GetDiag ()
256320 }
257321
322+ if hasChangeverification {
323+ _ , _ , err = enClient .UpdateVerifyDestinationWithContext (context , verifyCustomEmailDestinationConfiguration )
324+ if err != nil {
325+ return diag .FromErr (err )
326+ }
327+ }
328+
258329 return resourceIBMEnCustomEmailDestinationRead (context , d , meta )
259330 }
260331
@@ -302,7 +373,44 @@ func CustomEmaildestinationConfigMapToDestinationConfig(configParams map[string]
302373 params .Domain = core .StringPtr (configParams ["domain" ].(string ))
303374 }
304375
376+ if configParams ["dkim" ] != nil && len (configParams ["dkim" ].([]interface {})) > 0 {
377+ DkimModel , _ := resourceIBMEnDestinationMapToDkimAttributes (configParams ["dkim" ].([]interface {})[0 ].(map [string ]interface {}))
378+ params .Dkim = & DkimModel
379+ }
380+ if configParams ["spf" ] != nil && len (configParams ["spf" ].([]interface {})) > 0 {
381+ SpfModel , _ := resourceIBMEnDestinationMapToSpfAttributes (configParams ["spf" ].([]interface {})[0 ].(map [string ]interface {}))
382+ params .Spf = & SpfModel
383+ }
384+
305385 destinationConfig := new (en.DestinationConfig )
306386 destinationConfig .Params = params
307387 return * destinationConfig
308388}
389+
390+ func resourceIBMEnDestinationMapToDkimAttributes (modelMap map [string ]interface {}) (en.DkimAttributes , error ) {
391+ model := new (en.DkimAttributes )
392+ if modelMap ["public_key" ] != nil && modelMap ["public_key" ].(string ) != "" {
393+ model .PublicKey = core .StringPtr (modelMap ["public_key" ].(string ))
394+ }
395+ if modelMap ["selector" ] != nil && modelMap ["selector" ].(string ) != "" {
396+ model .Selector = core .StringPtr (modelMap ["selector" ].(string ))
397+ }
398+ if modelMap ["verification" ] != nil && modelMap ["verification" ].(string ) != "" {
399+ model .Verification = core .StringPtr (modelMap ["verification" ].(string ))
400+ }
401+ return * model , nil
402+ }
403+
404+ func resourceIBMEnDestinationMapToSpfAttributes (modelMap map [string ]interface {}) (en.SpfAttributes , error ) {
405+ model := new (en.SpfAttributes )
406+ if modelMap ["txt_name" ] != nil && modelMap ["txt_name" ].(string ) != "" {
407+ model .TxtName = core .StringPtr (modelMap ["txt_name" ].(string ))
408+ }
409+ if modelMap ["txt_value" ] != nil && modelMap ["txt_value" ].(string ) != "" {
410+ model .TxtValue = core .StringPtr (modelMap ["txt_value" ].(string ))
411+ }
412+ if modelMap ["verification" ] != nil && modelMap ["verification" ].(string ) != "" {
413+ model .Verification = core .StringPtr (modelMap ["verification" ].(string ))
414+ }
415+ return * model , nil
416+ }
0 commit comments