Skip to content

Commit b40f782

Browse files
sreesaiteja-lankavarmax2511
authored andcommitted
Added - Support for Encrypted FastConnect
1 parent 99fe501 commit b40f782

33 files changed

+871
-49
lines changed

examples/fast_connect/cross_connect.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ output "cross_connects" {
3333
value = data.oci_core_cross_connects.cross_connects.cross_connects
3434
}
3535

36+
37+

examples/fast_connect/cross_connect_group.tf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ variable "cross_connect_group_state" {
99
default = "AVAILABLE"
1010
}
1111

12+
variable "secret_ocid_ckn" {
13+
14+
}
15+
16+
variable "secret_version_cak" {
17+
18+
}
19+
20+
variable "secret_ocid_cak" {
21+
22+
}
23+
24+
variable "secret_version_ckn" {
25+
26+
}
27+
1228
resource "oci_core_cross_connect_group" "cross_connect_group" {
1329
#Required
1430
compartment_id = var.compartment_ocid
@@ -30,3 +46,48 @@ output "cross_connect_groups" {
3046
value = data.oci_core_cross_connect_groups.cross_connect_groups.cross_connect_groups
3147
}
3248

49+
resource "oci_core_cross_connect_group" "test_cross_connect_group" {
50+
#Required
51+
compartment_id = "${var.compartment_ocid}"
52+
#Optional
53+
customer_reference_name = "customerReferenceName"
54+
defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}"
55+
display_name = "displayName"
56+
freeform_tags = {
57+
"Department" = "Finance"
58+
}
59+
macsec_properties {
60+
#Required
61+
state = "ENABLED"
62+
#Optional
63+
encryption_cipher = "AES256_GCM"
64+
primary_key {
65+
#Required
66+
connectivity_association_key_secret_id = "${var.secret_ocid_ckn}"
67+
connectivity_association_key_secret_version = "${var.secret_version_cak}"
68+
connectivity_association_name_secret_id = "${var.secret_ocid_cak}"
69+
connectivity_association_name_secret_version = "${var.secret_version_ckn}"
70+
}
71+
72+
}
73+
}
74+
75+
variable defined_tag_namespace_name { default = "" }
76+
resource "oci_identity_tag_namespace" "tag-namespace1" {
77+
#Required
78+
compartment_id = "${var.tenancy_ocid}"
79+
description = "example tag namespace"
80+
name = "${var.defined_tag_namespace_name != "" ? var.defined_tag_namespace_name : "example-tag-namespace-all"}"
81+
82+
is_retired = false
83+
}
84+
85+
resource "oci_identity_tag" "tag1" {
86+
#Required
87+
description = "example tag"
88+
name = "example-tag"
89+
tag_namespace_id = "${oci_identity_tag_namespace.tag-namespace1.id}"
90+
91+
is_retired = false
92+
}
93+

oci/core_cross_connect_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func (s *CoreCrossConnectDataSourceCrud) SetData() error {
9393
s.D.Set("location_name", *s.Res.LocationName)
9494
}
9595

96+
if s.Res.MacsecProperties != nil {
97+
s.D.Set("macsec_properties", []interface{}{MacsecPropertiesToMap(s.Res.MacsecProperties)})
98+
} else {
99+
s.D.Set("macsec_properties", nil)
100+
}
101+
96102
if s.Res.PortName != nil {
97103
s.D.Set("port_name", *s.Res.PortName)
98104
}

oci/core_cross_connect_group_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ func (s *CoreCrossConnectGroupDataSourceCrud) SetData() error {
8585

8686
s.D.Set("freeform_tags", s.Res.FreeformTags)
8787

88+
if s.Res.MacsecProperties != nil {
89+
s.D.Set("macsec_properties", []interface{}{MacsecPropertiesToMap(s.Res.MacsecProperties)})
90+
} else {
91+
s.D.Set("macsec_properties", nil)
92+
}
93+
8894
s.D.Set("state", s.Res.LifecycleState)
8995

9096
if s.Res.TimeCreated != nil {

oci/core_cross_connect_group_resource.go

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package oci
55

66
import (
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+
301486
func (s *CoreCrossConnectGroupResourceCrud) updateCompartment(compartment interface{}) error {
302487
changeCompartmentRequest := oci_core.ChangeCrossConnectGroupCompartmentRequest{}
303488

0 commit comments

Comments
 (0)