@@ -5,6 +5,8 @@ package oci
55
66import (
77 "context"
8+ "fmt"
9+ "strconv"
810
911 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
1012
@@ -56,6 +58,61 @@ func CoreCrossConnectGroupResource() *schema.Resource {
5658 Computed : true ,
5759 Elem : schema .TypeString ,
5860 },
61+ "macsec_properties" : {
62+ Type : schema .TypeList ,
63+ Optional : true ,
64+ Computed : true ,
65+ MaxItems : 1 ,
66+ MinItems : 1 ,
67+ Elem : & schema.Resource {
68+ Schema : map [string ]* schema.Schema {
69+ // Required
70+ "state" : {
71+ Type : schema .TypeString ,
72+ Required : true ,
73+ },
74+
75+ // Optional
76+ "encryption_cipher" : {
77+ Type : schema .TypeString ,
78+ Optional : true ,
79+ Computed : true ,
80+ },
81+ "primary_key" : {
82+ Type : schema .TypeList ,
83+ Optional : true ,
84+ Computed : true ,
85+ MaxItems : 1 ,
86+ MinItems : 1 ,
87+ Elem : & schema.Resource {
88+ Schema : map [string ]* schema.Schema {
89+ // Required
90+ "connectivity_association_key_secret_id" : {
91+ Type : schema .TypeString ,
92+ Required : true ,
93+ },
94+ "connectivity_association_name_secret_id" : {
95+ Type : schema .TypeString ,
96+ Required : true ,
97+ },
98+
99+ // Required
100+ "connectivity_association_key_secret_version" : {
101+ Type : schema .TypeString ,
102+ Required : true ,
103+ },
104+ "connectivity_association_name_secret_version" : {
105+ Type : schema .TypeString ,
106+ Required : true ,
107+ },
108+ },
109+ },
110+ },
111+
112+ // Computed
113+ },
114+ },
115+ },
59116
60117 // Computed
61118 "state" : {
@@ -182,6 +239,17 @@ func (s *CoreCrossConnectGroupResourceCrud) Create() error {
182239 request .FreeformTags = ObjectMapToStringMap (freeformTags .(map [string ]interface {}))
183240 }
184241
242+ if macsecProperties , ok := s .D .GetOkExists ("macsec_properties" ); ok {
243+ if tmpList := macsecProperties .([]interface {}); len (tmpList ) > 0 {
244+ fieldKeyFormat := fmt .Sprintf ("%s.%d.%%s" , "macsec_properties" , 0 )
245+ tmp , err := s .mapToCreateMacsecProperties (fieldKeyFormat )
246+ if err != nil {
247+ return err
248+ }
249+ request .MacsecProperties = & tmp
250+ }
251+ }
252+
185253 request .RequestMetadata .RetryPolicy = GetRetryPolicy (s .DisableNotFoundRetries , "core" )
186254
187255 response , err := s .Client .CreateCrossConnectGroup (context .Background (), request )
@@ -247,6 +315,17 @@ func (s *CoreCrossConnectGroupResourceCrud) Update() error {
247315 request .FreeformTags = ObjectMapToStringMap (freeformTags .(map [string ]interface {}))
248316 }
249317
318+ if macsecProperties , ok := s .D .GetOkExists ("macsec_properties" ); ok {
319+ if tmpList := macsecProperties .([]interface {}); len (tmpList ) > 0 {
320+ fieldKeyFormat := fmt .Sprintf ("%s.%d.%%s" , "macsec_properties" , 0 )
321+ tmp , err := s .mapToUpdateMacsecProperties (fieldKeyFormat )
322+ if err != nil {
323+ return err
324+ }
325+ request .MacsecProperties = & tmp
326+ }
327+ }
328+
250329 request .RequestMetadata .RetryPolicy = GetRetryPolicy (s .DisableNotFoundRetries , "core" )
251330
252331 response , err := s .Client .UpdateCrossConnectGroup (context .Background (), request )
@@ -289,6 +368,12 @@ func (s *CoreCrossConnectGroupResourceCrud) SetData() error {
289368
290369 s .D .Set ("freeform_tags" , s .Res .FreeformTags )
291370
371+ if s .Res .MacsecProperties != nil {
372+ s .D .Set ("macsec_properties" , []interface {}{MacsecPropertiesToMap (s .Res .MacsecProperties )})
373+ } else {
374+ s .D .Set ("macsec_properties" , nil )
375+ }
376+
292377 s .D .Set ("state" , s .Res .LifecycleState )
293378
294379 if s .Res .TimeCreated != nil {
@@ -298,6 +383,106 @@ func (s *CoreCrossConnectGroupResourceCrud) SetData() error {
298383 return nil
299384}
300385
386+ func (s * CoreCrossConnectGroupResourceCrud ) mapToCreateMacsecKey (fieldKeyFormat string ) (oci_core.CreateMacsecKey , error ) {
387+ result := oci_core.CreateMacsecKey {}
388+
389+ if connectivityAssociationKeySecretId , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_key_secret_id" )); ok {
390+ tmp := connectivityAssociationKeySecretId .(string )
391+ result .ConnectivityAssociationKeySecretId = & tmp
392+ }
393+
394+ if connectivityAssociationNameSecretId , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_name_secret_id" )); ok {
395+ tmp := connectivityAssociationNameSecretId .(string )
396+ result .ConnectivityAssociationNameSecretId = & tmp
397+ }
398+
399+ return result , nil
400+ }
401+
402+ func (s * CoreCrossConnectGroupResourceCrud ) mapToUpdateMacsecKey (fieldKeyFormat string ) (oci_core.UpdateMacsecKey , error ) {
403+ result := oci_core.UpdateMacsecKey {}
404+
405+ if connectivityAssociationKeySecretId , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_key_secret_id" )); ok {
406+ tmp := connectivityAssociationKeySecretId .(string )
407+ result .ConnectivityAssociationKeySecretId = & tmp
408+ }
409+
410+ if connectivityAssociationNameSecretId , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_name_secret_id" )); ok {
411+ tmp := connectivityAssociationNameSecretId .(string )
412+ result .ConnectivityAssociationNameSecretId = & tmp
413+ }
414+
415+ if connectivityAssociationKeySecretVersion , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_key_secret_version" )); ok {
416+ tmp := connectivityAssociationKeySecretVersion .(string )
417+ tmpInt64 , err := strconv .ParseInt (tmp , 10 , 64 )
418+ if err != nil {
419+ return result , fmt .Errorf ("unable to convert connectivityAssociationKeySecretVersion string: %s to an int64 and encountered error: %v" , tmp , err )
420+ }
421+ result .ConnectivityAssociationKeySecretVersion = & tmpInt64
422+ }
423+
424+ if connectivityAssociationNameSecretVersion , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "connectivity_association_name_secret_version" )); ok {
425+ tmp := connectivityAssociationNameSecretVersion .(string )
426+ tmpInt64 , err := strconv .ParseInt (tmp , 10 , 64 )
427+ if err != nil {
428+ return result , fmt .Errorf ("unable to convert connectivityAssociationNameSecretVersion string: %s to an int64 and encountered error: %v" , tmp , err )
429+ }
430+ result .ConnectivityAssociationNameSecretVersion = & tmpInt64
431+ }
432+
433+ return result , nil
434+ }
435+
436+ func (s * CoreCrossConnectGroupResourceCrud ) mapToCreateMacsecProperties (fieldKeyFormat string ) (oci_core.CreateMacsecProperties , error ) {
437+ result := oci_core.CreateMacsecProperties {}
438+
439+ if encryptionCipher , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "encryption_cipher" )); ok {
440+ result .EncryptionCipher = oci_core .MacsecEncryptionCipherEnum (encryptionCipher .(string ))
441+ }
442+
443+ if primaryKey , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "primary_key" )); ok {
444+ if tmpList := primaryKey .([]interface {}); len (tmpList ) > 0 {
445+ fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "primary_key" ), 0 )
446+ tmp , err := s .mapToCreateMacsecKey (fieldKeyFormatNextLevel )
447+ if err != nil {
448+ return result , fmt .Errorf ("unable to convert primary_key, encountered error: %v" , err )
449+ }
450+ result .PrimaryKey = & tmp
451+ }
452+ }
453+
454+ if state , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "state" )); ok {
455+ result .State = oci_core .MacsecStateEnum (state .(string ))
456+ }
457+
458+ return result , nil
459+ }
460+
461+ func (s * CoreCrossConnectGroupResourceCrud ) mapToUpdateMacsecProperties (fieldKeyFormat string ) (oci_core.UpdateMacsecProperties , error ) {
462+ result := oci_core.UpdateMacsecProperties {}
463+
464+ if encryptionCipher , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "encryption_cipher" )); ok {
465+ result .EncryptionCipher = oci_core .MacsecEncryptionCipherEnum (encryptionCipher .(string ))
466+ }
467+
468+ if primaryKey , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "primary_key" )); ok {
469+ if tmpList := primaryKey .([]interface {}); len (tmpList ) > 0 {
470+ fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "primary_key" ), 0 )
471+ tmp , err := s .mapToUpdateMacsecKey (fieldKeyFormatNextLevel )
472+ if err != nil {
473+ return result , fmt .Errorf ("unable to convert primary_key, encountered error: %v" , err )
474+ }
475+ result .PrimaryKey = & tmp
476+ }
477+ }
478+
479+ if state , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "state" )); ok {
480+ result .State = oci_core .MacsecStateEnum (state .(string ))
481+ }
482+
483+ return result , nil
484+ }
485+
301486func (s * CoreCrossConnectGroupResourceCrud ) updateCompartment (compartment interface {}) error {
302487 changeCompartmentRequest := oci_core.ChangeCrossConnectGroupCompartmentRequest {}
303488
0 commit comments