@@ -38,23 +38,25 @@ import (
3838)
3939
4040const (
41- deplTAndCAcceptedFieldName = "terms_and_conditions_accepted"
42- deplProjectFieldName = "project"
43- deplNameFieldName = "name"
44- deplDescriptionFieldName = "description"
45- deplLocationFieldName = "location"
46- deplLocationRegionFieldName = "region"
47- deplVersionFieldName = "version"
48- deplVersionDbVersionFieldName = "db_version"
49- deplSecurityFieldName = "security"
50- deplSecurityCaCertificateFieldName = "ca_certificate"
51- deplSecurityIpAllowlistFieldName = "ip_allowlist"
52- deplSecurityDisableFoxxAuthenticationFieldName = "disable_foxx_authentication"
53- deplConfigurationFieldName = "configuration"
54- deplConfigurationModelFieldName = "model"
55- deplConfigurationNodeSizeIdFieldName = "node_size_id"
56- deplConfigurationNodeCountFieldName = "node_count"
57- deplConfigurationNodeDiskSizeFieldName = "node_disk_size"
41+ deplTAndCAcceptedFieldName = "terms_and_conditions_accepted"
42+ deplProjectFieldName = "project"
43+ deplNameFieldName = "name"
44+ deplDescriptionFieldName = "description"
45+ deplLocationFieldName = "location"
46+ deplLocationRegionFieldName = "region"
47+ deplVersionFieldName = "version"
48+ deplVersionDbVersionFieldName = "db_version"
49+ deplSecurityFieldName = "security"
50+ deplSecurityCaCertificateFieldName = "ca_certificate"
51+ deplSecurityIpAllowlistFieldName = "ip_allowlist"
52+ deplSecurityDisableFoxxAuthenticationFieldName = "disable_foxx_authentication"
53+ deplConfigurationFieldName = "configuration"
54+ deplConfigurationModelFieldName = "model"
55+ deplConfigurationNodeSizeIdFieldName = "node_size_id"
56+ deplConfigurationNodeCountFieldName = "node_count"
57+ deplConfigurationNodeDiskSizeFieldName = "node_disk_size"
58+ deplNotificationConfigurationFieldName = "notification_settings"
59+ deplNotificationConfigurationEmailAddressesFieldName = "email_addresses"
5860)
5961
6062func resourceDeployment () * schema.Resource {
@@ -180,6 +182,25 @@ func resourceDeployment() *schema.Resource {
180182 },
181183 },
182184 },
185+ deplNotificationConfigurationFieldName : {
186+ Type : schema .TypeList ,
187+ Optional : true ,
188+ MaxItems : 1 ,
189+ DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
190+ return new == ""
191+ },
192+ Elem : & schema.Resource {
193+ Schema : map [string ]* schema.Schema {
194+ deplNotificationConfigurationEmailAddressesFieldName : {
195+ Type : schema .TypeList ,
196+ Optional : true ,
197+ Elem : & schema.Schema {
198+ Type : schema .TypeString ,
199+ },
200+ },
201+ },
202+ },
203+ },
183204 },
184205 }
185206}
@@ -330,13 +351,14 @@ type configuration struct {
330351func expandDeploymentResource (d * schema.ResourceData , defaultProject string ) (* data.Deployment , error ) {
331352 project := defaultProject
332353 var (
333- name string
334- description string
335- ver version
336- loc location
337- conf configuration
338- sec securityFields
339- err error
354+ name string
355+ description string
356+ ver version
357+ loc location
358+ conf configuration
359+ sec securityFields
360+ err error
361+ notificationSetting * data.Deployment_NotificationSettings
340362 )
341363 if v , ok := d .GetOk (deplNameFieldName ); ok {
342364 name = v .(string )
@@ -372,6 +394,12 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d
372394 return nil , fmt .Errorf ("unable to find parse field %s" , deplConfigurationFieldName )
373395 }
374396
397+ if v , ok := d .GetOk (deplNotificationConfigurationFieldName ); ok {
398+ if notificationSetting , err = expandNotificationSettings (v .([]interface {})); err != nil {
399+ return nil , err
400+ }
401+ }
402+
375403 return & data.Deployment {
376404 Name : name ,
377405 Description : description ,
@@ -387,6 +415,7 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d
387415 NodeDiskSize : int32 (conf .nodeDiskSize ),
388416 NodeSizeId : conf .nodeSizeId ,
389417 },
418+ NotificationSettings : notificationSetting ,
390419 }, nil
391420}
392421
@@ -455,6 +484,26 @@ func expandConfiguration(s []interface{}) (conf configuration, err error) {
455484 return
456485}
457486
487+ // expandNotificationSettings gathers notification settings data set in terraform schema
488+ func expandNotificationSettings (s []interface {}) (settings * data.Deployment_NotificationSettings , err error ) {
489+ for _ , v := range s {
490+ item := v .(map [string ]interface {})
491+ if emailAddresses , ok := item [deplNotificationConfigurationEmailAddressesFieldName ]; ok {
492+ emailAddresses , ok := emailAddresses .([]interface {})
493+ if ! ok {
494+ return nil , fmt .Errorf ("failed to parse field %s" , deplNotificationConfigurationEmailAddressesFieldName )
495+ }
496+ if settings == nil {
497+ settings = & data.Deployment_NotificationSettings {}
498+ }
499+ for _ , addr := range emailAddresses {
500+ settings .EmailAddresses = append (settings .EmailAddresses , addr .(string ))
501+ }
502+ }
503+ }
504+ return
505+ }
506+
458507// resourceDeploymentRead retrieves deployment information from terraform stores.
459508func resourceDeploymentRead (d * schema.ResourceData , m interface {}) error {
460509 client := m .(* Client )
@@ -486,8 +535,9 @@ func flattenDeployment(depl *data.Deployment) map[string]interface{} {
486535 loc := flattenLocationData (depl )
487536 ver := flattenVersion (depl )
488537 sec := flattenSecurity (depl )
538+ notificationSetting := flattenNotificationSettings (depl )
489539
490- return map [string ]interface {}{
540+ result := map [string ]interface {}{
491541 deplNameFieldName : depl .GetName (),
492542 deplProjectFieldName : depl .GetProjectId (),
493543 deplDescriptionFieldName : depl .GetDescription (),
@@ -496,6 +546,10 @@ func flattenDeployment(depl *data.Deployment) map[string]interface{} {
496546 deplVersionFieldName : ver ,
497547 deplSecurityFieldName : sec ,
498548 }
549+ if notificationSetting != nil {
550+ result [deplNotificationConfigurationFieldName ] = notificationSetting
551+ }
552+ return result
499553}
500554
501555// flattenVersion takes the version part of a deployment and creates a sub map for terraform schema.
@@ -539,6 +593,18 @@ func flattenConfigurationData(depl *data.Deployment) []interface{} {
539593 }
540594}
541595
596+ // flattenNotificationSettings takes the notification settings part of a deployment and creates a sub map for terraform schema.
597+ func flattenNotificationSettings (depl * data.Deployment ) []interface {} {
598+ if depl .GetNotificationSettings () == nil {
599+ return nil
600+ }
601+ return []interface {}{
602+ map [string ]interface {}{
603+ deplNotificationConfigurationEmailAddressesFieldName : depl .GetNotificationSettings ().GetEmailAddresses (),
604+ },
605+ }
606+ }
607+
542608// resourceDeploymentUpdate checks fields for differences and updates a deployment if necessary.
543609func resourceDeploymentUpdate (d * schema.ResourceData , m interface {}) error {
544610 client := m .(* Client )
@@ -597,6 +663,14 @@ func resourceDeploymentUpdate(d *schema.ResourceData, m interface{}) error {
597663 depl .Model .NodeCount = int32 (conf .nodeCount )
598664 }
599665 }
666+ // if we have change on NotificationSettings apply it
667+ if d .HasChange (deplNotificationConfigurationFieldName ) {
668+ settings , err := expandNotificationSettings (d .Get (deplNotificationConfigurationFieldName ).([]interface {}))
669+ if err != nil {
670+ return err
671+ }
672+ depl .NotificationSettings = settings
673+ }
600674
601675 if res , err := datac .UpdateDeployment (client .ctxWithToken , depl ); err != nil {
602676 client .log .Error ().Err (err ).Msg ("Failed to update deployment" )
0 commit comments