Skip to content

Commit 0809715

Browse files
jotruonvarmax2511
authored andcommitted
Add 'description' field to route rules
1 parent 0d7cbe8 commit 0809715

11 files changed

+101
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 3.58.0 (Unreleased)
2+
3+
### Added
4+
- Support for `description` field in networking routing rules in `oci_core_route_table` and `oci_core_security_list`
5+
26
## 3.57.0 (January 09, 2020)
37

48
### Added

examples/networking/route_table/route_table.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ variable "private_key_path" {}
77
variable "compartment_ocid" {}
88
variable "region" {}
99

10+
variable "route_table_route_rules_description" {
11+
default = "description"
12+
}
13+
1014
provider "oci" {
1115
tenancy_ocid = "${var.tenancy_ocid}"
1216
user_ocid = "${var.user_ocid}"
@@ -34,6 +38,7 @@ resource "oci_core_route_table" "example_route_table" {
3438
display_name = "exampleRouteTable"
3539

3640
route_rules {
41+
description = "${var.route_table_route_rules_description}"
3742
destination = "0.0.0.0/0"
3843
destination_type = "CIDR_BLOCK"
3944
network_entity_id = "${oci_core_internet_gateway.example_ig.id}"

examples/networking/security_list/security_list.tf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ variable "private_key_path" {}
99
variable "compartment_ocid" {}
1010
variable "region" {}
1111

12+
variable "security_list_egress_security_rules_description" {
13+
default = "description"
14+
}
15+
16+
variable "security_list_ingress_security_rules_description" {
17+
default = "description"
18+
}
19+
1220
provider "oci" {
1321
tenancy_ocid = "${var.tenancy_ocid}"
1422
user_ocid = "${var.user_ocid}"
@@ -40,8 +48,9 @@ resource "oci_core_security_list" "example_security_list" {
4048

4149
// allow outbound udp traffic on a port range
4250
egress_security_rules {
51+
description = "${var.security_list_egress_security_rules_description}"
4352
destination = "0.0.0.0/0"
44-
protocol = "17" // udp
53+
protocol = "17" // udp
4554
stateless = true
4655

4756
udp_options {
@@ -71,9 +80,10 @@ resource "oci_core_security_list" "example_security_list" {
7180

7281
// allow inbound icmp traffic of a specific type
7382
ingress_security_rules {
74-
protocol = 1
75-
source = "0.0.0.0/0"
76-
stateless = true
83+
description = "${var.security_list_ingress_security_rules_description}"
84+
protocol = 1
85+
source = "0.0.0.0/0"
86+
stateless = true
7787

7888
icmp_options {
7989
type = 3

oci/core_route_table_resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ func CoreRouteTableResource() *schema.Resource {
7777
Computed: true,
7878
Deprecated: FieldDeprecatedForAnother("cidr_block", "destination"),
7979
},
80+
"description": {
81+
Type: schema.TypeString,
82+
Optional: true,
83+
Computed: true,
84+
},
8085
"destination": {
8186
Type: schema.TypeString,
8287
Optional: true,
@@ -367,6 +372,11 @@ func (s *CoreRouteTableResourceCrud) mapToRouteRule(fieldKeyFormat string) (oci_
367372
result.DestinationType = tmp
368373
}
369374

375+
if description, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "description")); ok {
376+
tmp := description.(string)
377+
result.Description = &tmp
378+
}
379+
370380
cidrBlockChanged := false
371381
cidrBlock, cidrBlockPresent := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cidr_block"))
372382
if cidrBlockPresent && s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "cidr_block")) {
@@ -406,6 +416,10 @@ func RouteRuleToMap(obj oci_core.RouteRule) map[string]interface{} {
406416
result["cidr_block"] = string(*obj.CidrBlock)
407417
}
408418

419+
if obj.Description != nil {
420+
result["description"] = string(*obj.Description)
421+
}
422+
409423
if obj.Destination != nil {
410424
result["destination"] = string(*obj.Destination)
411425
}
@@ -434,6 +448,9 @@ func routeRulesHashCodeForSets(v interface{}) int {
434448
} else if destinationPresent && destination != "" {
435449
buf.WriteString(fmt.Sprintf("%v-", destination))
436450
}
451+
if description, ok := m["description"]; ok && description != "" {
452+
buf.WriteString(fmt.Sprintf("%v-", description))
453+
}
437454
if destinationPresent && destination != "" {
438455
buf.WriteString(fmt.Sprintf("%v-", destination))
439456
} else if cidrBlockPresent && cidrBlock != "" {

oci/core_route_table_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
}
4747
routeTableRouteRulesRepresentation = map[string]interface{}{
4848
"network_entity_id": Representation{repType: Required, create: `${oci_core_internet_gateway.test_internet_gateway.id}`},
49+
"description": Representation{repType: Optional, create: `description`, update: `description2`},
4950
"destination": Representation{repType: Optional, create: `0.0.0.0/0`, update: `10.0.0.0/8`},
5051
"destination_type": Representation{repType: Optional, create: `CIDR_BLOCK`},
5152
}
@@ -111,6 +112,7 @@ func TestCoreRouteTableResource_basic(t *testing.T) {
111112
resource.TestCheckResourceAttrSet(resourceName, "id"),
112113
resource.TestCheckResourceAttr(resourceName, "route_rules.#", "1"),
113114
CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
115+
"description": "description",
114116
"destination": "0.0.0.0/0",
115117
"destination_type": "CIDR_BLOCK",
116118
},
@@ -147,6 +149,7 @@ func TestCoreRouteTableResource_basic(t *testing.T) {
147149
resource.TestCheckResourceAttrSet(resourceName, "id"),
148150
resource.TestCheckResourceAttr(resourceName, "route_rules.#", "1"),
149151
CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
152+
"description": "description",
150153
"destination": "0.0.0.0/0",
151154
"destination_type": "CIDR_BLOCK",
152155
},
@@ -178,6 +181,7 @@ func TestCoreRouteTableResource_basic(t *testing.T) {
178181
resource.TestCheckResourceAttrSet(resourceName, "id"),
179182
resource.TestCheckResourceAttr(resourceName, "route_rules.#", "1"),
180183
CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
184+
"description": "description2",
181185
"destination": "10.0.0.0/8",
182186
"destination_type": "CIDR_BLOCK",
183187
},
@@ -216,6 +220,7 @@ func TestCoreRouteTableResource_basic(t *testing.T) {
216220
resource.TestCheckResourceAttrSet(datasourceName, "route_tables.0.id"),
217221
resource.TestCheckResourceAttr(datasourceName, "route_tables.0.route_rules.#", "1"),
218222
CheckResourceSetContainsElementWithProperties(datasourceName, "route_tables.0.route_rules", map[string]string{
223+
"description": "description2",
219224
"destination": "10.0.0.0/8",
220225
"destination_type": "CIDR_BLOCK",
221226
},

oci/core_security_list_resource.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func CoreSecurityListResource() *schema.Resource {
6868
},
6969

7070
// Optional
71+
"description": {
72+
Type: schema.TypeString,
73+
Optional: true,
74+
Computed: true,
75+
},
7176
"destination_type": {
7277
Type: schema.TypeString,
7378
Optional: true,
@@ -230,6 +235,11 @@ func CoreSecurityListResource() *schema.Resource {
230235
},
231236

232237
// Optional
238+
"description": {
239+
Type: schema.TypeString,
240+
Optional: true,
241+
Computed: true,
242+
},
233243
"icmp_options": {
234244
Type: schema.TypeList,
235245
Optional: true,
@@ -675,6 +685,11 @@ func (s *CoreSecurityListResourceCrud) SetData() error {
675685
func (s *CoreSecurityListResourceCrud) mapToEgressSecurityRule(fieldKeyFormat string) (oci_core.EgressSecurityRule, error) {
676686
result := oci_core.EgressSecurityRule{}
677687

688+
if description, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "description")); ok {
689+
tmp := description.(string)
690+
result.Description = &tmp
691+
}
692+
678693
if destination, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "destination")); ok && destination != "" {
679694
tmp := destination.(string)
680695
result.Destination = &tmp
@@ -733,6 +748,10 @@ func (s *CoreSecurityListResourceCrud) mapToEgressSecurityRule(fieldKeyFormat st
733748
func EgressSecurityRuleToMap(obj oci_core.EgressSecurityRule) map[string]interface{} {
734749
result := map[string]interface{}{}
735750

751+
if obj.Description != nil {
752+
result["description"] = string(*obj.Description)
753+
}
754+
736755
if obj.Destination != nil {
737756
result["destination"] = string(*obj.Destination)
738757
}
@@ -799,6 +818,11 @@ func IcmpOptionsToMap(obj *oci_core.IcmpOptions) map[string]interface{} {
799818
func (s *CoreSecurityListResourceCrud) mapToIngressSecurityRule(fieldKeyFormat string) (oci_core.IngressSecurityRule, error) {
800819
result := oci_core.IngressSecurityRule{}
801820

821+
if description, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "description")); ok {
822+
tmp := description.(string)
823+
result.Description = &tmp
824+
}
825+
802826
if icmpOptions, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "icmp_options")); ok {
803827
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 {
804828
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "icmp_options"), 0)
@@ -857,6 +881,10 @@ func (s *CoreSecurityListResourceCrud) mapToIngressSecurityRule(fieldKeyFormat s
857881
func IngressSecurityRuleToMap(obj oci_core.IngressSecurityRule) map[string]interface{} {
858882
result := map[string]interface{}{}
859883

884+
if obj.Description != nil {
885+
result["description"] = string(*obj.Description)
886+
}
887+
860888
if obj.IcmpOptions != nil {
861889
result["icmp_options"] = []interface{}{IcmpOptionsToMap(obj.IcmpOptions)}
862890
}
@@ -1013,6 +1041,9 @@ func UdpOptionsToMap(obj *oci_core.UdpOptions) map[string]interface{} {
10131041
func egressSecurityRulesHashCodeForSets(v interface{}) int {
10141042
var buf bytes.Buffer
10151043
m := v.(map[string]interface{})
1044+
if description, ok := m["description"]; ok && description != "" {
1045+
buf.WriteString(fmt.Sprintf("%v-", description))
1046+
}
10161047
if destination, ok := m["destination"]; ok && destination != "" {
10171048
buf.WriteString(fmt.Sprintf("%v-", destination))
10181049
}
@@ -1097,6 +1128,9 @@ func egressSecurityRulesHashCodeForSets(v interface{}) int {
10971128
func ingressSecurityRulesHashCodeForSets(v interface{}) int {
10981129
var buf bytes.Buffer
10991130
m := v.(map[string]interface{})
1131+
if description, ok := m["description"]; ok && description != "" {
1132+
buf.WriteString(fmt.Sprintf("%v-", description))
1133+
}
11001134
if icmpOptions, ok := m["icmp_options"]; ok {
11011135
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
11021136
buf.WriteString("icmp_options-")

oci/core_security_list_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
securityListEgressSecurityRulesICMPRepresentation = map[string]interface{}{
4646
"destination": Representation{repType: Required, create: `10.0.2.0/24`, update: `${lookup(data.oci_core_services.test_services.services[0], "cidr_block")}`},
4747
"protocol": Representation{repType: Required, create: `1`},
48+
"description": Representation{repType: Optional, create: `description`, update: `description2`},
4849
"destination_type": Representation{repType: Optional, create: `CIDR_BLOCK`, update: `SERVICE_CIDR_BLOCK`},
4950
"icmp_options": RepresentationGroup{Optional, securityListEgressSecurityRulesIcmpOptionsRepresentation},
5051
"stateless": Representation{repType: Optional, create: `false`, update: `true`},
@@ -65,6 +66,7 @@ var (
6566
}
6667
securityListIngressSecurityRulesICMPRepresentation = map[string]interface{}{
6768
"protocol": Representation{repType: Required, create: `1`},
69+
"description": Representation{repType: Optional, create: `description`, update: `description2`},
6870
"source": Representation{repType: Required, create: `10.0.1.0/24`, update: `${lookup(data.oci_core_services.test_services.services[0], "cidr_block")}`},
6971
"icmp_options": RepresentationGroup{Optional, securityListIngressSecurityRulesIcmpOptionsRepresentation},
7072
"source_type": Representation{repType: Optional, create: `CIDR_BLOCK`, update: `SERVICE_CIDR_BLOCK`},
@@ -201,6 +203,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
201203
resource.TestCheckResourceAttr(resourceName, "egress_security_rules.#", "3"),
202204
CheckResourceSetContainsElementWithProperties(resourceName, "egress_security_rules", map[string]string{
203205
"destination": "10.0.2.0/24",
206+
"description": "description",
204207
"destination_type": "CIDR_BLOCK",
205208
"icmp_options.#": "1",
206209
"icmp_options.0.code": "4",
@@ -242,6 +245,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
242245
"icmp_options.#": "1",
243246
"icmp_options.0.code": "4",
244247
"icmp_options.0.type": "3",
248+
"description": "description",
245249
"protocol": "1",
246250
"source": "10.0.1.0/24",
247251
"source_type": "CIDR_BLOCK",
@@ -303,6 +307,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
303307
resource.TestCheckResourceAttr(resourceName, "display_name", "MyPrivateSubnetSecurityList"),
304308
resource.TestCheckResourceAttr(resourceName, "egress_security_rules.#", "3"),
305309
CheckResourceSetContainsElementWithProperties(resourceName, "egress_security_rules", map[string]string{
310+
"description": "description",
306311
"destination": "10.0.2.0/24",
307312
"destination_type": "CIDR_BLOCK",
308313
"icmp_options.#": "1",
@@ -316,6 +321,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
316321
resource.TestCheckResourceAttrSet(resourceName, "id"),
317322
resource.TestCheckResourceAttr(resourceName, "ingress_security_rules.#", "3"),
318323
CheckResourceSetContainsElementWithProperties(resourceName, "ingress_security_rules", map[string]string{
324+
"description": "description",
319325
"icmp_options.#": "1",
320326
"icmp_options.0.code": "4",
321327
"icmp_options.0.type": "3",
@@ -349,6 +355,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
349355
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
350356
resource.TestCheckResourceAttr(resourceName, "egress_security_rules.#", "3"),
351357
CheckResourceSetContainsElementWithProperties(resourceName, "egress_security_rules", map[string]string{
358+
"description": "description2",
352359
"destination_type": "SERVICE_CIDR_BLOCK",
353360
"icmp_options.#": "1",
354361
"icmp_options.0.code": "0",
@@ -391,6 +398,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
391398
resource.TestCheckResourceAttrSet(resourceName, "id"),
392399
resource.TestCheckResourceAttr(resourceName, "ingress_security_rules.#", "3"),
393400
CheckResourceSetContainsElementWithProperties(resourceName, "ingress_security_rules", map[string]string{
401+
"description": "description2",
394402
"icmp_options.#": "1",
395403
"icmp_options.0.code": "0",
396404
"icmp_options.0.type": "3",
@@ -460,6 +468,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
460468
resource.TestCheckResourceAttr(datasourceName, "security_lists.0.display_name", "displayName2"),
461469
resource.TestCheckResourceAttr(datasourceName, "security_lists.0.egress_security_rules.#", "3"),
462470
CheckResourceSetContainsElementWithProperties(datasourceName, "security_lists.0.egress_security_rules", map[string]string{
471+
"description": "description2",
463472
"destination_type": "SERVICE_CIDR_BLOCK",
464473
"icmp_options.#": "1",
465474
"icmp_options.0.code": "0",
@@ -502,6 +511,7 @@ func TestCoreSecurityListResource_basic(t *testing.T) {
502511
resource.TestCheckResourceAttrSet(datasourceName, "security_lists.0.id"),
503512
resource.TestCheckResourceAttr(datasourceName, "security_lists.0.ingress_security_rules.#", "3"),
504513
CheckResourceSetContainsElementWithProperties(datasourceName, "security_lists.0.ingress_security_rules", map[string]string{
514+
"description": "description2",
505515
"icmp_options.#": "1",
506516
"icmp_options.0.code": "0",
507517
"icmp_options.0.type": "3",

website/docs/d/core_route_tables.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The following attributes are exported:
6262
Cannot be an IPv6 CIDR.
6363

6464
Example: `0.0.0.0/0`
65+
* `description` - An optional description of your choice for the rule.
6566
* `destination` - Conceptually, this is the range of IP addresses used for matching when routing traffic. Required if you provide a `destinationType`.
6667

6768
Allowed values:

website/docs/d/core_security_lists.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The following attributes are exported:
5151
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
5252
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
5353
* `egress_security_rules` - Rules for allowing egress IP packets.
54+
* `description` - An optional description of your choice for the rule.
5455
* `destination` - Conceptually, this is the range of IP addresses that a packet originating from the instance can go to.
5556

5657
Allowed values:
@@ -87,6 +88,7 @@ The following attributes are exported:
8788
* `freeform_tags` - Free-form 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: `{"Department": "Finance"}`
8889
* `id` - The security list's Oracle Cloud ID (OCID).
8990
* `ingress_security_rules` - Rules for allowing ingress IP packets.
91+
* `description` - An optional description of your choice for the rule.
9092
* `icmp_options` - Optional and valid only for ICMP and ICMPv6. Use to specify a particular ICMP type and code as defined in:
9193
* [ICMP Parameters](http://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml)
9294
* [ICMPv6 Parameters](https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml)

website/docs/r/core_route_table.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ resource "oci_core_route_table" "test_route_table" {
4646
4747
#Optional
4848
cidr_block = "${var.route_table_route_rules_cidr_block}"
49+
description = "${var.route_table_route_rules_description}"
4950
destination = "${var.route_table_route_rules_destination}"
5051
destination_type = "${var.route_table_route_rules_destination_type}"
5152
}
@@ -68,6 +69,7 @@ The following arguments are supported:
6869
Cannot be an IPv6 CIDR.
6970

7071
Example: `0.0.0.0/0`
72+
* `description` - (Optional) (Updatable) An optional description of your choice for the rule.
7173
* `destination` - (Optional) (Updatable) Conceptually, this is the range of IP addresses used for matching when routing traffic. Required if you provide a `destinationType`.
7274

7375
Allowed values:
@@ -100,6 +102,7 @@ The following attributes are exported:
100102
Cannot be an IPv6 CIDR.
101103

102104
Example: `0.0.0.0/0`
105+
* `description` - An optional description of your choice for the rule.
103106
* `destination` - Conceptually, this is the range of IP addresses used for matching when routing traffic. Required if you provide a `destinationType`.
104107

105108
Allowed values:

0 commit comments

Comments
 (0)