Skip to content

Commit 818fdf9

Browse files
Kumar dhirajMaxrovr
authored andcommitted
Added nlb-cp zpr support
1 parent 56efaf5 commit 818fdf9

6 files changed

+97
-2
lines changed

internal/integrationtest/network_load_balancer_network_load_balancer_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var (
6363
"reserved_ips": acctest.RepresentationGroup{RepType: acctest.Optional, Group: networkLoadBalancerReservedIpsRepresentation},
6464
"network_security_group_ids": acctest.Representation{RepType: acctest.Optional, Create: []string{`${oci_core_network_security_group.test_network_security_group.id}`}},
6565
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: NetworkLoadBalancerIgnoreChangesRepresentation},
66+
"security_attributes": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"secAttriZprNlbIAD.secAttriIAD.mode": "enforce", "secAttriZprNlbIAD.secAttriIAD.value": "someVal"}},
6667
}
6768

6869
NetworkLoadBalancerSubnetIpv6CidrRepresentation = map[string]interface{}{
@@ -231,6 +232,7 @@ func TestNetworkLoadBalancerNetworkLoadBalancerResource_basic(t *testing.T) {
231232
resource.TestCheckResourceAttr(resourceName, "ip_addresses.0.is_public", "true"),
232233
resource.TestCheckResourceAttrSet(resourceName, "ip_addresses.0.ip_address"),
233234
resource.TestCheckResourceAttrSet(resourceName, "ip_addresses.0.reserved_ip.0.id"),
235+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
234236
resource.TestCheckResourceAttrSet(resourceName, "state"),
235237
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
236238
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -266,6 +268,7 @@ func TestNetworkLoadBalancerNetworkLoadBalancerResource_basic(t *testing.T) {
266268
resource.TestCheckResourceAttr(resourceName, "nlb_ip_version", "IPV4"),
267269
resource.TestCheckResourceAttrSet(resourceName, "ip_addresses.0.ip_address"),
268270
resource.TestCheckResourceAttrSet(resourceName, "ip_addresses.0.reserved_ip.0.id"),
271+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
269272
resource.TestCheckResourceAttrSet(resourceName, "state"),
270273
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
271274
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -295,6 +298,7 @@ func TestNetworkLoadBalancerNetworkLoadBalancerResource_basic(t *testing.T) {
295298
resource.TestCheckResourceAttr(resourceName, "is_preserve_source_destination", "false"),
296299
resource.TestCheckResourceAttr(resourceName, "is_private", "false"),
297300
resource.TestCheckResourceAttr(resourceName, "nlb_ip_version", "IPV4"),
301+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
298302
resource.TestCheckResourceAttrSet(resourceName, "state"),
299303
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
300304
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -374,6 +378,7 @@ func TestNetworkLoadBalancerNetworkLoadBalancerResource_basic(t *testing.T) {
374378
resource.TestCheckResourceAttr(singularDatasourceName, "is_private", "false"),
375379
resource.TestCheckResourceAttr(singularDatasourceName, "is_symmetric_hash_enabled", "false"),
376380
resource.TestCheckResourceAttr(singularDatasourceName, "nlb_ip_version", "IPV4"),
381+
resource.TestCheckResourceAttr(singularDatasourceName, "security_attributes.%", "2"),
377382
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
378383
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
379384
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_updated"),

internal/service/network_load_balancer/network_load_balancer_network_load_balancer_data_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func (s *NetworkLoadBalancerNetworkLoadBalancerDataSourceCrud) SetData() error {
104104

105105
s.D.Set("network_security_group_ids", s.Res.NetworkSecurityGroupIds)
106106
s.D.Set("nlb_ip_version", s.Res.NlbIpVersion)
107+
108+
if s.Res.SecurityAttributes != nil {
109+
s.D.Set("security_attributes", SecurityAttributesToMap(s.Res.SecurityAttributes))
110+
}
111+
107112
s.D.Set("state", s.Res.LifecycleState)
108113

109114
if s.Res.SubnetId != nil {

internal/service/network_load_balancer/network_load_balancer_network_load_balancer_resource.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package network_load_balancer
66
import (
77
"context"
88
"fmt"
9+
"reflect"
910
"strings"
1011
"time"
1112

@@ -121,6 +122,12 @@ func NetworkLoadBalancerNetworkLoadBalancerResource() *schema.Resource {
121122
},
122123
},
123124
},
125+
"security_attributes": {
126+
Type: schema.TypeMap,
127+
Optional: true,
128+
Computed: true,
129+
Elem: schema.TypeString,
130+
},
124131
"subnet_ipv6cidr": {
125132
Type: schema.TypeString,
126133
Optional: true,
@@ -348,6 +355,11 @@ func (s *NetworkLoadBalancerNetworkLoadBalancerResourceCrud) Create() error {
348355
}
349356
}
350357

358+
if securityAttributes, ok := s.D.GetOkExists("security_attributes"); ok {
359+
convertedAttributes := MapToSecurityAttributes(securityAttributes.(map[string]interface{}))
360+
request.SecurityAttributes = convertedAttributes
361+
}
362+
351363
if subnetId, ok := s.D.GetOkExists("subnet_id"); ok {
352364
tmp := subnetId.(string)
353365
request.SubnetId = &tmp
@@ -567,6 +579,15 @@ func (s *NetworkLoadBalancerNetworkLoadBalancerResourceCrud) Update() error {
567579
request.NlbIpVersion = oci_network_load_balancer.NlbIpVersionEnum(nlbIpVersion.(string))
568580
}
569581

582+
//if securityAttributes, ok := s.D.GetOkExists("security_attributes"); ok {
583+
//request.SecurityAttributes = securityAttributes.(map[string]map[string]interface{})
584+
//}
585+
586+
if securityAttributes, ok := s.D.GetOkExists("security_attributes"); ok {
587+
convertedAttributes := MapToSecurityAttributes(securityAttributes.(map[string]interface{}))
588+
request.SecurityAttributes = convertedAttributes
589+
}
590+
570591
if subnetIpv6Cidr, ok := s.D.GetOkExists("subnet_ipv6cidr"); ok &&
571592
s.D.HasChange("subnet_ipv6cidr") {
572593
tmp := subnetIpv6Cidr.(string)
@@ -647,6 +668,10 @@ func (s *NetworkLoadBalancerNetworkLoadBalancerResourceCrud) SetData() error {
647668
}
648669
s.D.Set("network_security_group_ids", schema.NewSet(tfresource.LiteralTypeHashCodeForSets, networkSecurityGroupIds))
649670
s.D.Set("nlb_ip_version", s.Res.NlbIpVersion)
671+
672+
//s.D.Set("security_attributes", s.Res.SecurityAttributes)
673+
s.D.Set("security_attributes", SecurityAttributesToMap(s.Res.SecurityAttributes))
674+
650675
s.D.Set("state", s.Res.LifecycleState)
651676

652677
if s.Res.SubnetId != nil {
@@ -739,6 +764,9 @@ func NetworkLoadBalancerSummaryToMap(obj oci_network_load_balancer.NetworkLoadBa
739764
result["network_security_group_ids"] = schema.NewSet(tfresource.LiteralTypeHashCodeForSets, networkSecurityGroupIds)
740765
}
741766
result["nlb_ip_version"] = string(obj.NlbIpVersion)
767+
768+
result["security_attributes"] = obj.SecurityAttributes
769+
742770
result["state"] = string(obj.LifecycleState)
743771

744772
if obj.SubnetId != nil {
@@ -830,3 +858,55 @@ func (s *NetworkLoadBalancerNetworkLoadBalancerResourceCrud) updateCompartment(c
830858
workId := response.OpcWorkRequestId
831859
return s.getNetworkLoadBalancerFromWorkRequest(workId, tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "network_load_balancer"), oci_network_load_balancer.ActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate))
832860
}
861+
862+
func MapToSecurityAttributes(rawMap map[string]interface{}) map[string]map[string]interface{} {
863+
result := make(map[string]map[string]interface{})
864+
for fullKey, value := range rawMap {
865+
keys := strings.Split(fullKey, ".")
866+
if len(keys) < 2 {
867+
continue
868+
}
869+
outerKey := keys[0]
870+
innerKey := strings.Join(keys[1:], ".")
871+
if result[outerKey] == nil {
872+
result[outerKey] = make(map[string]interface{})
873+
}
874+
unflattenHelper(result[outerKey], innerKey, value)
875+
}
876+
877+
return result
878+
}
879+
880+
func unflattenHelper(currentMap map[string]interface{}, key string, value interface{}) {
881+
keys := strings.Split(key, ".")
882+
for i, k := range keys {
883+
if i == len(keys)-1 {
884+
currentMap[k] = value
885+
} else {
886+
if _, ok := currentMap[k]; !ok {
887+
currentMap[k] = make(map[string]interface{})
888+
}
889+
currentMap = currentMap[k].(map[string]interface{})
890+
}
891+
}
892+
}
893+
894+
func SecurityAttributesToMap(rm map[string]map[string]interface{}) map[string]interface{} {
895+
result := make(map[string]interface{})
896+
for outerKey, innerMap := range rm {
897+
flattenHelper(result, outerKey, innerMap)
898+
}
899+
900+
return result
901+
}
902+
903+
func flattenHelper(flat map[string]interface{}, prefix string, nested map[string]interface{}) {
904+
for key, value := range nested {
905+
fullKey := prefix + "." + key
906+
if reflect.TypeOf(value).Kind() == reflect.Map {
907+
flattenHelper(flat, fullKey, value.(map[string]interface{}))
908+
} else {
909+
flat[fullKey] = value
910+
}
911+
}
912+
}

website/docs/d/network_load_balancer_network_load_balancer.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ The following attributes are exported:
155155

156156
Example: ["ocid1.nsg.oc1.phx.unique_ID"]
157157
* `nlb_ip_version` - IP version associated with the NLB.
158+
* `security_attributes` - ZPR tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{ "oracle-zpr": { "td": { "value": "42", "mode": "audit" } } }`
158159
* `state` - The current state of the network load balancer.
159160
* `subnet_id` - The subnet in which the network load balancer is spawned [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm)."
160161
* `system_tags` - Key-value pair representing system tags' keys and values scoped to a namespace. Example: `{"bar-key": "value"}`

website/docs/d/network_load_balancer_network_load_balancers.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ The following attributes are exported:
133133
* Network security groups define network security rules to govern ingress and egress traffic for the network load balancer.
134134
* The network security rules of other resources can reference the network security groups associated with the network load balancer to ensure access.
135135

136-
Example: ["ocid1.nsg.oc1.phx.unique_ID"]
136+
Example: ["ocid1.nsg.oc1.phx.unique_ID"]
137+
* `security_attributes` - ZPR tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{ "oracle-zpr": { "td": { "value": "42", "mode": "audit" } } }`
137138
* `state` - The current state of the network load balancer.
138139
* `subnet_id` - The subnet in which the network load balancer is spawned [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm)."
139140
* `nlb_ip_version` - IP version associated with the NLB.

website/docs/r/network_load_balancer_network_load_balancer.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ resource "oci_network_load_balancer_network_load_balancer" "test_network_load_ba
140140
#Optional
141141
id = var.network_load_balancer_reserved_ips_id
142142
}
143+
security_attributes = var.network_load_balancer_security_attributes
143144
subnet_ipv6cidr = var.network_load_balancer_subnet_ipv6cidr
144145
}
145146
```
@@ -230,7 +231,8 @@ The following arguments are supported:
230231

231232
Reserved public IP addresses are not deleted when the network load balancer is deleted. The IP addresses become unattached from the network load balancer.
232233

233-
Example: "ocid1.publicip.oc1.phx.unique_ID"
234+
Example: "ocid1.publicip.oc1.phx.unique_ID"
235+
* `security_attributes` - (Optional) (Updatable) ZPR tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"oracle-zpr": {"td": {"value": "42", "mode": "audit"}}}`
234236
* `subnet_id` - (Required) The subnet in which the network load balancer is spawned [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
235237
* `subnet_ipv6cidr` - (Optional) IPv6 subnet prefix selection. If Ipv6 subnet prefix is passed, Nlb Ipv6 Address would be assign within the cidr block. NLB has to be dual or single stack ipv6 to support this.
236238

@@ -334,6 +336,7 @@ The following attributes are exported:
334336

335337
Example: ["ocid1.nsg.oc1.phx.unique_ID"]
336338
* `nlb_ip_version` - IP version associated with the NLB.
339+
* `security_attributes` - ZPR tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{ "oracle-zpr": { "td": { "value": "42", "mode": "audit" } } }`
337340
* `state` - The current state of the network load balancer.
338341
* `subnet_id` - The subnet in which the network load balancer is spawned [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm)."
339342
* `system_tags` - Key-value pair representing system tags' keys and values scoped to a namespace. Example: `{"bar-key": "value"}`

0 commit comments

Comments
 (0)