Skip to content

Commit 998d6bf

Browse files
Harshil JhaveriNagaRajuPasunuri
authored andcommitted
Adding Security Attributes feature to Load Balancer Service
1 parent 747b37b commit 998d6bf

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

internal/integrationtest/load_balancer_load_balancer_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454

5555
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
5656
"is_private": acctest.Representation{RepType: acctest.Optional, Create: `false`},
57+
"security_attributes": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"oracle-zpr.sa-test-lbaas.mode": "enforce", "oracle-zpr.sa-test-lbaas.value": "create-zpr-tersi-lbaas"}, Update: map[string]string{"oracle-zpr.sa-test-lbaas.value": "update-zpr-tersi-lbaas", "oracle-zpr.sa-test-lbaas.mode": "enforce"}},
5758
"is_request_id_enabled": acctest.Representation{RepType: acctest.Optional, Create: `true`, Update: `true`},
5859
"request_id_header": acctest.Representation{RepType: acctest.Optional, Create: ``, Update: `X-MyRequestB-Id`},
5960
"is_delete_protection_enabled": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
@@ -145,13 +146,13 @@ var (
145146
"test_network_security_group1", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreNetworkSecurityGroupRepresentation, map[string]interface{}{
146147
"vcn_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_vcn.test_lb_vcn.id}`},
147148
})) // +
148-
// For laptop testing comment out this line
149-
// Failure to do so results in
150-
// test_helpers.go:535: Step 1/7 error: Error running apply: exit status 1
151-
// [DEBUG] Using modified User-Agent: Terraform/0.12.31 HashiCorp-terraform-exec/0.14.0
152-
// Error: 404-NotAuthorizedOrNotFound, Authorization failed or requested resource not found.
153-
// Suggestion: Either the resource has been deleted or service Identity Tag Namespace need policy to access this resource.
154-
// DefinedTagsDependencies
149+
// For laptop testing comment out this line
150+
// Failure to do so results in
151+
// test_helpers.go:535: Step 1/7 error: Error running apply: exit status 1
152+
// [DEBUG] Using modified User-Agent: Terraform/0.12.31 HashiCorp-terraform-exec/0.14.0
153+
// Error: 404-NotAuthorizedOrNotFound, Authorization failed or requested resource not found.
154+
// Suggestion: Either the resource has been deleted or service Identity Tag Namespace need policy to access this resource.
155+
// DefinedTagsDependencies
155156
)
156157

157158
// issue-routing-tag: load_balancer/default
@@ -211,6 +212,9 @@ func TestLoadBalancerLoadBalancerResource_basic(t *testing.T) {
211212
resource.TestCheckResourceAttr(resourceName, "is_request_id_enabled", "true"),
212213
resource.TestCheckResourceAttr(resourceName, "request_id_header", "X-Request-Id"),
213214
resource.TestCheckResourceAttr(resourceName, "reserved_ips.#", "1"),
215+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
216+
resource.TestCheckResourceAttr(resourceName, "security_attributes.oracle-zpr.sa-test-lbaas.value", "create-zpr-tersi-lbaas"),
217+
resource.TestCheckResourceAttr(resourceName, "security_attributes.oracle-zpr.sa-test-lbaas.mode", "enforce"),
214218
resource.TestCheckResourceAttrSet(resourceName, "reserved_ips.0.id"),
215219
resource.TestCheckResourceAttr(resourceName, "network_security_group_ids.#", "1"),
216220
resource.TestCheckResourceAttr(resourceName, "shape", "100Mbps"),
@@ -247,6 +251,8 @@ func TestLoadBalancerLoadBalancerResource_basic(t *testing.T) {
247251
resource.TestCheckResourceAttr(resourceName, "is_request_id_enabled", "true"),
248252
resource.TestCheckResourceAttr(resourceName, "request_id_header", "X-Request-Id"),
249253
resource.TestCheckResourceAttr(resourceName, "reserved_ips.#", "1"),
254+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
255+
250256
resource.TestCheckResourceAttrSet(resourceName, "reserved_ips.0.id"),
251257
resource.TestCheckResourceAttr(resourceName, "shape", "100Mbps"),
252258
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -276,7 +282,10 @@ func TestLoadBalancerLoadBalancerResource_basic(t *testing.T) {
276282
resource.TestCheckResourceAttr(resourceName, "is_private", "false"),
277283
resource.TestCheckResourceAttr(resourceName, "is_request_id_enabled", "true"),
278284
resource.TestCheckResourceAttr(resourceName, "request_id_header", "X-MyRequestB-Id"),
279-
resource.TestCheckResourceAttr(resourceName, "reserved_ips.#", "1"),
285+
resource.TestCheckResourceAttr(resourceName, "reserved_ips.#", "1"),
286+
resource.TestCheckResourceAttr(resourceName, "security_attributes.%", "2"),
287+
resource.TestCheckResourceAttr(resourceName, "security_attributes.oracle-zpr.sa-test-lbaas.value", "update-zpr-tersi-lbaas"),
288+
resource.TestCheckResourceAttr(resourceName, "security_attributes.oracle-zpr.sa-test-lbaas.mode", "enforce"),
280289
resource.TestCheckResourceAttr(resourceName, "shape", "400Mbps"),
281290
resource.TestCheckResourceAttrSet(resourceName, "reserved_ips.0.id"),
282291
resource.TestCheckResourceAttr(resourceName, "network_security_group_ids.#", "0"),
@@ -315,6 +324,7 @@ func TestLoadBalancerLoadBalancerResource_basic(t *testing.T) {
315324
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.is_private", "false"),
316325
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.network_security_group_ids.#", "0"),
317326
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.is_request_id_enabled", "true"),
327+
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.security_attributes.%", "2"),
318328
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.request_id_header", "X-MyRequestB-Id"),
319329
resource.TestCheckResourceAttr(datasourceName, "load_balancers.0.shape", "400Mbps"),
320330
resource.TestCheckResourceAttrSet(datasourceName, "load_balancers.0.state"),

internal/service/load_balancer/load_balancer_load_balancer_resource.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func LoadBalancerLoadBalancerResource() *schema.Resource {
118118
},
119119
},
120120
},
121+
"security_attributes": {
122+
Type: schema.TypeMap,
123+
Optional: true,
124+
Computed: true,
125+
Elem: schema.TypeString,
126+
},
121127
"shape_details": {
122128
Type: schema.TypeList,
123129
Optional: true,
@@ -372,6 +378,11 @@ func (s *LoadBalancerLoadBalancerResourceCrud) Create() error {
372378
}
373379
}
374380

381+
if securityAttributes, ok := s.D.GetOkExists("security_attributes"); ok {
382+
convertedAttributes := tfresource.MapToSecurityAttributes(securityAttributes.(map[string]interface{}))
383+
request.SecurityAttributes = convertedAttributes
384+
}
385+
375386
if shape, ok := s.D.GetOkExists("shape"); ok {
376387
tmp := shape.(string)
377388
request.ShapeName = &tmp
@@ -527,12 +538,14 @@ func (s *LoadBalancerLoadBalancerResourceCrud) Update() error {
527538
request.LoadBalancerId = &tmp
528539

529540
if requestIdHeader, ok := s.D.GetOkExists("request_id_header"); ok {
530-
if requestIdHeader != nil {
531-
tmp := requestIdHeader.(string)
532-
request.RequestIdHeader = &tmp
533-
}
541+
tmp := requestIdHeader.(string)
542+
request.RequestIdHeader = &tmp
534543
}
535544

545+
if securityAttributes, ok := s.D.GetOkExists("security_attributes"); ok {
546+
convertedAttributes := tfresource.MapToSecurityAttributes(securityAttributes.(map[string]interface{}))
547+
request.SecurityAttributes = convertedAttributes
548+
}
536549
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "load_balancer")
537550

538551
response, err := s.Client.UpdateLoadBalancer(context.Background(), request)
@@ -648,6 +661,8 @@ func (s *LoadBalancerLoadBalancerResourceCrud) SetData() error {
648661
s.D.Set("request_id_header", *s.Res.RequestIdHeader)
649662
}
650663

664+
s.D.Set("security_attributes", tfresource.SecurityAttributesToMap(s.Res.SecurityAttributes))
665+
651666
if s.Res.ShapeName != nil {
652667
s.D.Set("shape", *s.Res.ShapeName)
653668
}

internal/service/load_balancer/load_balancer_load_balancers_data_source.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ func (s *LoadBalancerLoadBalancersDataSourceCrud) SetData() error {
171171
loadBalancer["request_id_header"] = *r.RequestIdHeader
172172
}
173173

174+
if r.SecurityAttributes != nil {
175+
loadBalancer["security_attributes"] = tfresource.SecurityAttributesToMap(r.SecurityAttributes)
176+
}
174177
if r.ShapeName != nil {
175178
loadBalancer["shape"] = *r.ShapeName
176179
}

website/docs/d/load_balancer_load_balancers.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ The following attributes are exported:
121121
* `name` - The name can be one of these values: `FORWARD_TO_BACKENDSET`
122122
* `condition` - A routing rule to evaluate defined conditions against the incoming HTTP request and perform an action.
123123
* `name` - A unique name for the routing policy rule. Avoid entering confidential information.
124+
* `security_attributes` - Extended Defined tags for ZPR for this resource. Each key is predefined and scoped to a namespace. Example: `{"Oracle-ZPR": {"MaxEgressCount": {"value":"42","mode":"audit", "usagetype" : "zpr"}}}`
124125
* `shape` - A template that determines the total pre-provisioned bandwidth (ingress plus egress). To get a list of available shapes, use the [ListShapes](https://docs.cloud.oracle.com/iaas/api/#/en/loadbalancer/20170115/LoadBalancerShape/ListShapes) operation. Example: `100Mbps`
125126
* `shape_details` - The configuration details to update load balancer to a different shape.
126127
* `maximum_bandwidth_in_mbps` - Bandwidth in Mbps that determines the maximum bandwidth (ingress plus egress) that the load balancer can achieve. This bandwidth cannot be always guaranteed. For a guaranteed bandwidth use the minimumBandwidthInMbps parameter.

website/docs/r/load_balancer_load_balancer.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ resource "oci_load_balancer_load_balancer" "test_load_balancer" {
6464
#Optional
6565
id = var.load_balancer_reserved_ips_id
6666
}
67+
security_attributes = var.load_balancer_security_attributes
6768
shape_details {
6869
#Required
6970
maximum_bandwidth_in_mbps = var.load_balancer_shape_details_maximum_bandwidth_in_mbps
@@ -142,6 +143,7 @@ The following arguments are supported:
142143
Reserved IPs will not be deleted when the Load balancer is deleted. They will be unattached from the Load balancer.
143144

144145
Example: "ocid1.publicip.oc1.phx.unique_ID" Ocid of the pre-created public IP that should be attached to this load balancer. The public IP will be attached to a private IP. **Note** If public IP resource is present in the config, the terraform plan will throw `After applying this step and refreshing, the plan was not empty` error, and `private_ip_id` needs to be added as an input argument to the public IP resource block or ignore from its lifecycle as shown in [examples](https://terraform-provider-oci/blob/507acd0ed6517dbca2fbcfb8100874929c8fd8e1/examples/load_balancer/lb_full/lb_full.tf#L133) to resolve this error.
146+
* `security_attributes` - (Optional) (Updatable) Extended Defined tags for ZPR for this resource. Each key is predefined and scoped to a namespace. Example: `{"Oracle-ZPR": {"MaxEgressCount": {"value":"42","mode":"audit", "usagetype" : "zpr"}}}`
145147
* `shape` - (Required) (Updatable) A template that determines the total pre-provisioned bandwidth (ingress plus egress). To get a list of available shapes, use the [ListShapes](https://docs.cloud.oracle.com/iaas/api/#/en/loadbalancer/20170115/LoadBalancerShape/ListShapes) operation. Example: `flexible` NOTE: After May 2023, Fixed shapes - 10Mbps, 100Mbps, 400Mbps, 8000Mbps would be deprecated and only shape allowed would be `Flexible` *Note: When updating shape for a load balancer, all existing connections to the load balancer will be reset during the update process. Also `10Mbps-Micro` shape cannot be updated to any other shape nor can any other shape be updated to `10Mbps-Micro`.
146148
* `shape_details` - (Optional) (Updatable) The configuration details to create load balancer using Flexible shape. This is required only if shapeName is `Flexible`.
147149
* `maximum_bandwidth_in_mbps` - (Required) (Updatable) Bandwidth in Mbps that determines the maximum bandwidth (ingress plus egress) that the load balancer can achieve. This bandwidth cannot be always guaranteed. For a guaranteed bandwidth use the minimumBandwidthInMbps parameter.
@@ -283,6 +285,7 @@ The following attributes are exported:
283285
* `name` - The name can be one of these values: `FORWARD_TO_BACKENDSET`
284286
* `condition` - A routing rule to evaluate defined conditions against the incoming HTTP request and perform an action.
285287
* `name` - A unique name for the routing policy rule. Avoid entering confidential information.
288+
* `security_attributes` - Extended Defined tags for ZPR for this resource. Each key is predefined and scoped to a namespace. Example: `{"Oracle-ZPR": {"MaxEgressCount": {"value":"42","mode":"audit", "usagetype" : "zpr"}}}`
286289
* `shape` - A template that determines the total pre-provisioned bandwidth (ingress plus egress). To get a list of available shapes, use the [ListShapes](https://docs.cloud.oracle.com/iaas/api/#/en/loadbalancer/20170115/LoadBalancerShape/ListShapes) operation. Example: `100Mbps`
287290
* `shape_details` - The configuration details to update load balancer to a different shape.
288291
* `maximum_bandwidth_in_mbps` - Bandwidth in Mbps that determines the maximum bandwidth (ingress plus egress) that the load balancer can achieve. This bandwidth cannot be always guaranteed. For a guaranteed bandwidth use the minimumBandwidthInMbps parameter.

0 commit comments

Comments
 (0)