Skip to content

Commit f93506e

Browse files
committed
Added - Source based routing support
1 parent eb32851 commit f93506e

33 files changed

+402
-96
lines changed

examples/networking/ipv6/ipv6.tf

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "region" {
8+
}
9+
10+
variable "compartment_ocid" {
11+
}
12+
13+
provider "oci" {
14+
auth = "SecurityToken"
15+
config_file_profile = "terraform-federation-test"
16+
}
17+
18+
data "oci_identity_availability_domain" "ad" {
19+
compartment_id = var.tenancy_ocid
20+
ad_number = 1
21+
}
22+
23+
resource "oci_core_vcn" "example_vcn" {
24+
cidr_block = "10.1.0.0/16"
25+
compartment_id = var.compartment_ocid
26+
is_ipv6enabled = true
27+
ipv6private_cidr_blocks = ["fc00::/48"]
28+
display_name = "exampleVCN"
29+
dns_label = "tfexamplevcn"
30+
}
31+
32+
resource "oci_core_subnet" "example_subnet" {
33+
availability_domain = data.oci_identity_availability_domain.ad.name
34+
cidr_block = "10.1.20.0/24"
35+
ipv6cidr_blocks = ["fc00::/64"]
36+
display_name = "exampleSubnet"
37+
dns_label = "tfexamplesubnet"
38+
security_list_ids = [oci_core_vcn.example_vcn.default_security_list_id]
39+
compartment_id = var.compartment_ocid
40+
vcn_id = oci_core_vcn.example_vcn.id
41+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
42+
dhcp_options_id = oci_core_vcn.example_vcn.default_dhcp_options_id
43+
}
44+
45+
variable "instance_shape" {
46+
default = "VM.Standard.E4.Flex"
47+
}
48+
49+
variable "instance_ocpus" { default = 1 }
50+
51+
variable "instance_shape_config_memory_in_gbs" { default = 6 }
52+
53+
# See https://docs.oracle.com/iaas/images/
54+
data "oci_core_images" "test_images" {
55+
compartment_id = var.compartment_ocid
56+
operating_system = "Oracle Linux"
57+
operating_system_version = "8"
58+
sort_by = "TIMECREATED"
59+
sort_order = "DESC"
60+
}
61+
62+
# Create Instance
63+
resource "oci_core_instance" "test_instance1" {
64+
availability_domain = data.oci_identity_availability_domain.ad.name
65+
compartment_id = var.compartment_ocid
66+
display_name = "testInstance"
67+
shape = var.instance_shape
68+
69+
shape_config {
70+
ocpus = var.instance_ocpus
71+
memory_in_gbs = var.instance_shape_config_memory_in_gbs
72+
}
73+
74+
create_vnic_details {
75+
subnet_id = oci_core_subnet.example_subnet.id
76+
hostname_label = "instance"
77+
}
78+
79+
source_details {
80+
source_type = "image"
81+
source_id = lookup(data.oci_core_images.test_images.images[0], "id")
82+
}
83+
}
84+
85+
# Gets a list of VNIC attachments on the instance
86+
data "oci_core_vnic_attachments" "instance_vnics" {
87+
compartment_id = var.compartment_ocid
88+
availability_domain = data.oci_identity_availability_domain.ad.name
89+
instance_id = oci_core_instance.test_instance1.id
90+
}
91+
92+
# Gets the OCID of the first (default) VNIC
93+
data "oci_core_vnic" "instance_vnic" {
94+
vnic_id = data.oci_core_vnic_attachments.instance_vnics.vnic_attachments[0]["vnic_id"]
95+
}
96+
97+
# Create IPv6
98+
resource "oci_core_ipv6" "test_ipv6" {
99+
vnic_id = data.oci_core_vnic_attachments.instance_vnics.vnic_attachments[0]["vnic_id"]
100+
display_name = "someIpv6DisplayName"
101+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
102+
}
103+
104+
# List IPv6s
105+
data "oci_core_ipv6s" "ipv6_datasource" {
106+
depends_on = [oci_core_ipv6.test_ipv6]
107+
vnic_id = oci_core_ipv6.test_ipv6.vnic_id
108+
}
109+
110+
output "ipv6s" {
111+
value = [data.oci_core_ipv6s.ipv6_datasource.ipv6s]
112+
}
113+

examples/networking/private_ip/private_ip.tf

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,15 @@
44
variable "tenancy_ocid" {
55
}
66

7-
variable "user_ocid" {
8-
}
9-
10-
variable "fingerprint" {
11-
}
12-
13-
variable "private_key_path" {
14-
}
15-
167
variable "region" {
178
}
189

1910
variable "compartment_ocid" {
2011
}
2112

22-
variable "ssh_public_key" {
23-
}
24-
25-
variable "ssh_private_key" {
26-
}
27-
28-
variable "instance_shape" {
29-
default = "VM.Standard2.1"
30-
}
31-
32-
variable "instance_image_ocid" {
33-
type = map(string)
34-
35-
default = {
36-
# See https://docs.us-phoenix-1.oraclecloud.com/images/
37-
# Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0"
38-
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa"
39-
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda"
40-
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma"
41-
uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa"
42-
}
43-
}
44-
4513
provider "oci" {
46-
tenancy_ocid = var.tenancy_ocid
47-
user_ocid = var.user_ocid
48-
fingerprint = var.fingerprint
49-
private_key_path = var.private_key_path
50-
region = var.region
14+
auth = "SecurityToken"
15+
config_file_profile = "terraform-federation-test"
5116
}
5217

5318
data "oci_identity_availability_domain" "ad" {
@@ -74,21 +39,43 @@ resource "oci_core_subnet" "example_subnet" {
7439
dhcp_options_id = oci_core_vcn.example_vcn.default_dhcp_options_id
7540
}
7641

42+
variable "instance_shape" {
43+
default = "VM.Standard.E4.Flex"
44+
}
45+
46+
variable "instance_ocpus" { default = 1 }
47+
48+
variable "instance_shape_config_memory_in_gbs" { default = 6 }
49+
50+
# See https://docs.oracle.com/iaas/images/
51+
data "oci_core_images" "test_images" {
52+
compartment_id = var.compartment_ocid
53+
operating_system = "Oracle Linux"
54+
operating_system_version = "8"
55+
sort_by = "TIMECREATED"
56+
sort_order = "DESC"
57+
}
58+
7759
# Create Instance
7860
resource "oci_core_instance" "test_instance1" {
7961
availability_domain = data.oci_identity_availability_domain.ad.name
8062
compartment_id = var.compartment_ocid
8163
display_name = "testInstance"
8264
shape = var.instance_shape
8365

66+
shape_config {
67+
ocpus = var.instance_ocpus
68+
memory_in_gbs = var.instance_shape_config_memory_in_gbs
69+
}
70+
8471
create_vnic_details {
8572
subnet_id = oci_core_subnet.example_subnet.id
8673
hostname_label = "instance"
8774
}
8875

8976
source_details {
9077
source_type = "image"
91-
source_id = var.instance_image_ocid[var.region]
78+
source_id = lookup(data.oci_core_images.test_images.images[0], "id")
9279
}
9380
}
9481

@@ -109,6 +96,7 @@ resource "oci_core_private_ip" "private_ip" {
10996
vnic_id = data.oci_core_vnic_attachments.instance_vnics.vnic_attachments[0]["vnic_id"]
11097
display_name = "someDisplayName"
11198
hostname_label = "somehostnamelabel"
99+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
112100
}
113101

114102
# List Private IPs
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "region" {
8+
}
9+
10+
variable "compartment_ocid" {
11+
}
12+
13+
provider "oci" {
14+
auth = "SecurityToken"
15+
config_file_profile = "terraform-federation-test"
16+
}
17+
18+
data "oci_identity_availability_domain" "ad" {
19+
compartment_id = var.tenancy_ocid
20+
ad_number = 1
21+
}
22+
23+
resource "oci_core_vcn" "example_vcn" {
24+
cidr_block = "10.1.0.0/16"
25+
compartment_id = var.compartment_ocid
26+
is_ipv6enabled = true
27+
ipv6private_cidr_blocks = ["fc00::/48"]
28+
display_name = "exampleVCN"
29+
dns_label = "tfexamplevcn"
30+
}
31+
32+
resource "oci_core_subnet" "example_subnet" {
33+
availability_domain = data.oci_identity_availability_domain.ad.name
34+
cidr_block = "10.1.20.0/24"
35+
ipv6cidr_blocks = ["fc00::/64"]
36+
display_name = "exampleSubnet"
37+
dns_label = "tfexamplesubnet"
38+
security_list_ids = [oci_core_vcn.example_vcn.default_security_list_id]
39+
compartment_id = var.compartment_ocid
40+
vcn_id = oci_core_vcn.example_vcn.id
41+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
42+
dhcp_options_id = oci_core_vcn.example_vcn.default_dhcp_options_id
43+
}
44+
45+
variable "instance_shape" {
46+
default = "VM.Standard.E4.Flex"
47+
}
48+
49+
variable "instance_ocpus" { default = 1 }
50+
51+
variable "instance_shape_config_memory_in_gbs" { default = 6 }
52+
53+
# See https://docs.oracle.com/iaas/images/
54+
data "oci_core_images" "test_images" {
55+
compartment_id = var.compartment_ocid
56+
operating_system = "Oracle Linux"
57+
operating_system_version = "8"
58+
sort_by = "TIMECREATED"
59+
sort_order = "DESC"
60+
}
61+
62+
# Create Instance
63+
resource "oci_core_instance" "test_instance1" {
64+
availability_domain = data.oci_identity_availability_domain.ad.name
65+
compartment_id = var.compartment_ocid
66+
display_name = "testInstance"
67+
shape = var.instance_shape
68+
69+
shape_config {
70+
ocpus = var.instance_ocpus
71+
memory_in_gbs = var.instance_shape_config_memory_in_gbs
72+
}
73+
74+
create_vnic_details {
75+
subnet_id = oci_core_subnet.example_subnet.id
76+
hostname_label = "instance"
77+
}
78+
79+
source_details {
80+
source_type = "image"
81+
source_id = lookup(data.oci_core_images.test_images.images[0], "id")
82+
}
83+
}
84+
85+
# Update only secondary VNIC with route table id
86+
resource "oci_core_vnic_attachment" "vnicatt" {
87+
instance_id = oci_core_instance.test_instance1.id
88+
create_vnic_details {
89+
subnet_id = oci_core_subnet.example_subnet.id
90+
# route_table_id = oci_core_vcn.example_vcn.default_route_table_id
91+
}
92+
}
93+
94+
# Gets a list of VNIC attachments on the instance
95+
data "oci_core_vnic_attachments" "instance_vnics" {
96+
compartment_id = var.compartment_ocid
97+
availability_domain = data.oci_identity_availability_domain.ad.name
98+
instance_id = oci_core_instance.test_instance1.id
99+
}
100+
101+
# Gets the OCID of the first (default) VNIC
102+
data "oci_core_vnic" "vnic1" {
103+
vnic_id = data.oci_core_vnic_attachments.instance_vnics.vnic_attachments[0]["vnic_id"]
104+
}
105+
106+
output "vnic_attachments" {
107+
value = [data.oci_core_vnic_attachments.instance_vnics.vnic_attachments]
108+
}

internal/integrationtest/core_ipv6_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ var (
4444
}
4545

4646
CoreIpv6Representation = map[string]interface{}{
47-
"vnic_id": acctest.Representation{RepType: acctest.Required, Create: `${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0], "vnic_id")}`},
48-
"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")}`},
49-
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
50-
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
51-
"ip_address": acctest.Representation{RepType: acctest.Optional, Create: `${substr(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 0, length(oci_core_vcn.test_vcn.ipv6cidr_blocks[0]) - 4)}5901:cede:a617:8bba`},
47+
"route_table_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_core_route_table.test_route_table.id}`},
48+
"vnic_id": acctest.Representation{RepType: acctest.Required, Create: `${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0], "vnic_id")}`},
49+
"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")}`},
50+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
51+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
52+
"ip_address": acctest.Representation{RepType: acctest.Optional, Create: `${substr(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 0, length(oci_core_vcn.test_vcn.ipv6cidr_blocks[0]) - 4)}5901:cede:a617:8bba`},
5253
}
5354

5455
CoreIpv6ResourceDependencies = utils.OciImageIdsVariable +
5556
acctest.GenerateResourceFromRepresentationMap("oci_core_instance", "test_instance", acctest.Required, acctest.Create, CoreInstanceRepresentation) +
57+
acctest.GenerateResourceFromRepresentationMap("oci_core_route_table", "test_route_table", acctest.Required, acctest.Create, CoreRouteTableRepresentation) +
5658
acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Optional, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreSubnetRepresentation, map[string]interface{}{
5759
"dns_label": acctest.Representation{RepType: acctest.Required, Create: `dnslabel`},
5860
"ipv6cidr_block": acctest.Representation{RepType: acctest.Optional, Create: `${substr(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 0, length(oci_core_vcn.test_vcn.ipv6cidr_blocks[0]) - 2)}${64}`},
@@ -119,6 +121,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
119121
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
120122
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
121123
resource.TestCheckResourceAttrSet(resourceName, "id"),
124+
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
122125
resource.TestCheckResourceAttrSet(resourceName, "ip_address"),
123126
resource.TestCheckResourceAttrSet(resourceName, "state"),
124127
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
@@ -146,6 +149,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
146149
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
147150
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
148151
resource.TestCheckResourceAttrSet(resourceName, "id"),
152+
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
149153
resource.TestCheckResourceAttrSet(resourceName, "ip_address"),
150154
resource.TestCheckResourceAttrSet(resourceName, "state"),
151155
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
@@ -174,6 +178,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
174178
resource.TestCheckResourceAttr(datasourceName, "ipv6s.0.display_name", "displayName2"),
175179
resource.TestCheckResourceAttr(datasourceName, "ipv6s.0.freeform_tags.%", "1"),
176180
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.id"),
181+
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.route_table_id"),
177182
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.ip_address"),
178183
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.subnet_id"),
179184
resource.TestCheckResourceAttrSet(datasourceName, "ipv6s.0.time_created"),
@@ -193,6 +198,7 @@ func TestCoreIpv6Resource_basic(t *testing.T) {
193198
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
194199
resource.TestCheckResourceAttrSet(singularDatasourceName, "ip_address"),
195200
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
201+
resource.TestCheckResourceAttrSet(singularDatasourceName, "route_table_id"),
196202
),
197203
},
198204
// verify resource import

0 commit comments

Comments
 (0)