Skip to content

Commit 13714c1

Browse files
Andrew SmykMaxrovr
authored andcommitted
Added - Support for IPv6-Prefix-for-Subnet & Flexible CIDR support for secondary IPs on VNIC Multi-Prefix-for-Subnet & Flexible CIDR support for secondary IP addresses on VNIC
1 parent d93893b commit 13714c1

File tree

9 files changed

+78
-14
lines changed

9 files changed

+78
-14
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
# Create flex cidr with vnic
5+
resource "oci_core_ipv6" "test_flex_cidr" {
6+
vnic_id = data.oci_core_vnic_attachments.instance_vnics.vnic_attachments[0]["vnic_id"]
7+
display_name = "flex_cidr"
8+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
9+
cidr_prefix_length = 80
10+
}
11+
12+
# List IPv6s
13+
data "oci_core_ipv6s" "flex_cidr_datasource" {
14+
vnic_id = oci_core_ipv6.test_flex_cidr.vnic_id
15+
}
16+
17+
output "flex_cidrs" {
18+
value = [data.oci_core_ipv6s.flex_cidr_datasource.ipv6s]
19+
}

examples/networking/ipv6/ipv6.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ data "oci_core_images" "test_images" {
5555
compartment_id = var.compartment_ocid
5656
operating_system = "Oracle Linux"
5757
operating_system_version = "8"
58+
shape = var.instance_shape
5859
sort_by = "TIMECREATED"
5960
sort_order = "DESC"
6061
}
@@ -103,7 +104,6 @@ resource "oci_core_ipv6" "test_ipv6" {
103104

104105
# List IPv6s
105106
data "oci_core_ipv6s" "ipv6_datasource" {
106-
depends_on = [oci_core_ipv6.test_ipv6]
107107
vnic_id = oci_core_ipv6.test_ipv6.vnic_id
108108
}
109109

examples/networking/ipv6/reserve_ipv6.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ resource "oci_core_ipv6" "test_reserve_ipv6_available" {
2020

2121
# List IPv6s
2222
data "oci_core_ipv6s" "reserve_ipv6_datasource" {
23-
depends_on = [oci_core_ipv6.test_reserve_ipv6,oci_core_ipv6.test_reserve_ipv6_available]
2423
subnet_id = oci_core_subnet.example_subnet.id
2524
}
2625

internal/integrationtest/core_ipv6_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ var (
5252
}
5353

5454
CoreIpv6Representation = map[string]interface{}{
55-
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
56-
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
57-
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
58-
"lifetime": acctest.Representation{RepType: acctest.Optional, Create: `EPHEMERAL`, Update: `RESERVED`},
59-
"route_table_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_core_route_table.test_route_table.id}`},
60-
"vnic_id": acctest.Representation{RepType: acctest.Required, Create: `${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0], "vnic_id")}`},
55+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
56+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
57+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
58+
"lifetime": acctest.Representation{RepType: acctest.Optional, Create: `EPHEMERAL`, Update: `RESERVED`},
59+
"route_table_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_core_route_table.test_route_table.id}`},
60+
"cidr_prefix_length": acctest.Representation{RepType: acctest.Optional, Create: `80`},
61+
"vnic_id": acctest.Representation{RepType: acctest.Required, Create: `${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0], "vnic_id")}`},
6162
}
6263

6364
CoreIpv6Representation2 = map[string]interface{}{
@@ -69,7 +70,9 @@ var (
6970
}
7071

7172
CoreIpv6ResourceDependencies = utils.OciImageIdsVariable +
72-
acctest.GenerateResourceFromRepresentationMap("oci_core_instance", "test_instance", acctest.Required, acctest.Create, CoreInstanceRepresentation) +
73+
acctest.GenerateResourceFromRepresentationMap("oci_core_instance", "test_instance", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreInstanceRepresentation, map[string]interface{}{
74+
"image": acctest.Representation{RepType: acctest.Required, Create: `${lookup(data.oci_core_images.supported_shape_images.images[0], "id")}`},
75+
})) +
7376
acctest.GenerateResourceFromRepresentationMap("oci_core_route_table", "test_route_table", acctest.Required, acctest.Create, CoreRouteTableRepresentation) +
7477
acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreSubnetRepresentation, map[string]interface{}{
7578
"dns_label": acctest.Representation{RepType: acctest.Required, Create: `dnslabel`},
@@ -138,6 +141,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
138141
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
139142
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
140143
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
144+
resource.TestCheckResourceAttr(resourceName, "cidr_prefix_length", "80"),
141145
resource.TestCheckResourceAttrSet(resourceName, "vnic_id"),
142146

143147
func(s *terraform.State) (err error) {
@@ -157,6 +161,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
157161
Config: config + compartmentIdVariableStr + CoreIpv6ResourceDependencies +
158162
acctest.GenerateResourceFromRepresentationMap("oci_core_ipv6", "test_ipv6", acctest.Optional, acctest.Update, CoreIpv6Representation),
159163
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
164+
resource.TestCheckResourceAttr(resourceName, "cidr_prefix_length", "80"),
160165
resource.TestCheckResourceAttrSet(resourceName, "compartment_id"),
161166
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
162167
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
@@ -227,6 +232,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
227232
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.ip_address"),
228233
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.subnet_id"),
229234
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.time_created"),
235+
resource.TestCheckResourceAttr(datasourceName, "ipv6s.0.cidr_prefix_length", "80"),
230236
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.vnic_id"),
231237
),
232238
},
@@ -237,7 +243,6 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
237243
compartmentIdVariableStr + CoreIpv6ResourceConfig,
238244
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
239245
resource.TestCheckResourceAttrSet(singularDatasourceName, "ipv6id"),
240-
241246
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "displayName2"),
242247
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
243248
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
@@ -246,6 +251,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
246251
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
247252
resource.TestCheckResourceAttrSet(singularDatasourceName, "ip_address"),
248253
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
254+
resource.TestCheckResourceAttr(singularDatasourceName, "cidr_prefix_length", "80"),
249255
resource.TestCheckResourceAttrSet(singularDatasourceName, "route_table_id"),
250256
),
251257
},

internal/service/core/core_ipv6_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (s *CoreIpv6DataSourceCrud) SetData() error {
6666

6767
s.D.SetId(*s.Res.Id)
6868

69+
if s.Res.CidrPrefixLength != nil {
70+
s.D.Set("cidr_prefix_length", *s.Res.CidrPrefixLength)
71+
}
72+
6973
if s.Res.CompartmentId != nil {
7074
s.D.Set("compartment_id", *s.Res.CompartmentId)
7175
}

internal/service/core/core_ipv6_resource.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package core
55

66
import (
77
"context"
8+
"net"
9+
"strings"
810

911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012

@@ -28,6 +30,12 @@ func CoreIpv6Resource() *schema.Resource {
2830
// Required
2931

3032
// Optional
33+
"cidr_prefix_length": {
34+
Type: schema.TypeInt,
35+
Optional: true,
36+
Computed: true,
37+
ForceNew: true,
38+
},
3139
"defined_tags": {
3240
Type: schema.TypeMap,
3341
Optional: true,
@@ -47,10 +55,11 @@ func CoreIpv6Resource() *schema.Resource {
4755
Elem: schema.TypeString,
4856
},
4957
"ip_address": {
50-
Type: schema.TypeString,
51-
Optional: true,
52-
Computed: true,
53-
ForceNew: true,
58+
Type: schema.TypeString,
59+
Optional: true,
60+
Computed: true,
61+
ForceNew: true,
62+
DiffSuppressFunc: ipDiffSuppressFunc,
5463
},
5564
"ipv6subnet_cidr": {
5665
Type: schema.TypeString,
@@ -170,6 +179,11 @@ func (s *CoreIpv6ResourceCrud) DeletedTarget() []string {
170179
func (s *CoreIpv6ResourceCrud) Create() error {
171180
request := oci_core.CreateIpv6Request{}
172181

182+
if cidrPrefixLength, ok := s.D.GetOkExists("cidr_prefix_length"); ok {
183+
tmp := cidrPrefixLength.(int)
184+
request.CidrPrefixLength = &tmp
185+
}
186+
173187
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
174188
convertedDefinedTags, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
175189
if err != nil {
@@ -351,6 +365,10 @@ func (s *CoreIpv6ResourceCrud) Delete() error {
351365
}
352366

353367
func (s *CoreIpv6ResourceCrud) SetData() error {
368+
if s.Res.CidrPrefixLength != nil {
369+
s.D.Set("cidr_prefix_length", *s.Res.CidrPrefixLength)
370+
}
371+
354372
if s.Res.CompartmentId != nil {
355373
s.D.Set("compartment_id", *s.Res.CompartmentId)
356374
}
@@ -413,3 +431,13 @@ func (s *CoreIpv6ResourceCrud) Ipv6VnicDetach() error {
413431

414432
return nil
415433
}
434+
435+
func ipDiffSuppressFunc(key string, old string, new string, d *schema.ResourceData) bool {
436+
if old == "" || new == "" {
437+
return false
438+
}
439+
440+
oldParsedIp := net.ParseIP(old)
441+
newParsedIp := net.ParseIP(new)
442+
return strings.EqualFold(oldParsedIp.String(), newParsedIp.String())
443+
}

internal/service/core/core_ipv6s_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func (s *CoreIpv6sDataSourceCrud) SetData() error {
109109
for _, r := range s.Res.Items {
110110
ipv6 := map[string]interface{}{}
111111

112+
if r.CidrPrefixLength != nil {
113+
ipv6["cidr_prefix_length"] = *r.CidrPrefixLength
114+
}
115+
112116
if r.CompartmentId != nil {
113117
ipv6["compartment_id"] = *r.CompartmentId
114118
}

website/docs/d/core_ipv6.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The following arguments are supported:
3636

3737
The following attributes are exported:
3838

39+
* `cidr_prefix_length` - Length of cidr range. Optional field to specify flexible cidr.
3940
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment containing the IPv6. This is the same as the VNIC's compartment.
4041
* `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"}`
4142
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.

website/docs/r/core_ipv6.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Creates an IPv6 for the specified VNIC.
1919
resource "oci_core_ipv6" "test_ipv6" {
2020
2121
#Optional
22+
cidr_prefix_length = var.ipv6_cidr_prefix_length
2223
defined_tags = {"Operations.CostCenter"= "42"}
2324
display_name = var.ipv6_display_name
2425
freeform_tags = {"Department"= "Finance"}
@@ -35,6 +36,7 @@ resource "oci_core_ipv6" "test_ipv6" {
3536

3637
The following arguments are supported:
3738

39+
* `cidr_prefix_length` - (Optional) Length of cidr range. Optional field to specify flexible cidr.
3840
* `defined_tags` - (Optional) (Updatable) 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"}`
3941
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
4042
* `freeform_tags` - (Optional) (Updatable) 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"}`
@@ -55,6 +57,7 @@ Any change to a property that does not support update will force the destruction
5557

5658
The following attributes are exported:
5759

60+
* `cidr_prefix_length` - Length of cidr range. Optional field to specify flexible cidr.
5861
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment containing the IPv6. This is the same as the VNIC's compartment.
5962
* `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"}`
6063
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.

0 commit comments

Comments
 (0)