Skip to content

Commit eb0a4dd

Browse files
rohanbhattacharjeeJason Bolla
authored andcommitted
Adding example of an instance mounting the NFS
1 parent 361960d commit eb0a4dd

File tree

8 files changed

+148
-25
lines changed

8 files changed

+148
-25
lines changed

docs/examples/storage/fss/README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ We see that a single mount target can export paths from two (or more) file syste
1313

1414
We also see how we need to specify certain stateful ingress rules in a security list for the file system to be operational.
1515

16+
Finally, we set up a compute instance that mounts the NFS storage.
17+
1618
### Using this example
1719
* Update env-vars with the required information. Most examples use the same set of environment variables so you only need to do this once.
1820
* Source env-vars
@@ -39,14 +41,24 @@ Defines the exports - used to make the file systems accessible via the mount tar
3941
#### `snapshot.tf`
4042
Defines a snapshot for a file system
4143

42-
#### `vcn.tf`
43-
Defines a virtual cloud network
44+
#### `network.tf`
45+
Defines a virtual cloud network, internet gateway, route table and a subnet.
4446

45-
#### `subnet.tf`
46-
Defines a subnet in the vcn
47+
This basic setup is needed to enable SSH to our instance.
4748

4849
#### `security_list.tf`
49-
Defines a security list setup to make our file system operational
50+
Defines a security list setup to make our file system operational.
51+
52+
We keep this separate from our `network.tf` file since there are some interesting things to note here.
53+
54+
In particular, some specific ports are being opened to allow the NFS communication to happen.
55+
56+
### `instance.tf`
57+
Defines our compute instance.
58+
59+
Note the remote action that we execute on our compute instance once it is launched.
60+
61+
We install the nfs-utils and then mount the NFS storage on to our compute instance.
5062

5163
#### `variables.tf`
5264
Defines the variables used in the configuration

docs/examples/storage/fss/data_sources.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ data "oci_file_storage_export_sets" "export_sets" {
6060
#display_name = "${var.export_set_display_name}"
6161
#id = "${var.export_set_id}"
6262
#state = "${var.export_set_state}"
63-
}
63+
}
64+
65+
data "oci_core_private_ips" ip_mount_target1 {
66+
subnet_id = "${oci_file_storage_mount_target.my_mount_target_1.subnet_id}"
67+
68+
filter {
69+
name = "id"
70+
values = ["${oci_file_storage_mount_target.my_mount_target_1.private_ip_ids.0}"]
71+
}
72+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "oci_core_instance" "my_instance" {
2+
availability_domain = "${var.availability_domain}"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "my instance with FSS access"
5+
hostname_label = "myinstance"
6+
image = "${var.instance_image_ocid[var.region]}"
7+
shape = "${var.instance_shape}"
8+
subnet_id = "${oci_core_subnet.my_subnet.id}"
9+
metadata {
10+
ssh_authorized_keys = "${file(var.ssh_public_key)}"
11+
}
12+
timeouts {
13+
create = "60m"
14+
}
15+
}
16+
17+
resource "null_resource" "mount_fss_on_instance" {
18+
depends_on = ["oci_core_instance.my_instance",
19+
"oci_file_storage_export.my_export_fs1_mt1"]
20+
provisioner "remote-exec" {
21+
connection {
22+
agent = false
23+
timeout = "30m"
24+
host = "${oci_core_instance.my_instance.public_ip}"
25+
user = "opc"
26+
private_key = "${file(var.ssh_private_key)}"
27+
}
28+
inline = [
29+
"sudo yum -y install nfs-utils > nfs-utils-install.log",
30+
"sudo mkdir -p /mnt/myfsspaths/fs1/path1",
31+
"sudo mount ${local.mount_target_1_ip_address}:${var.export_path_fs1_mt1} /mnt${var.export_path_fs1_mt1}",
32+
]
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
resource "oci_core_virtual_network" "my_vcn" {
2+
cidr_block = "${var.my_vcn-cidr}"
3+
dns_label = "myvcn"
4+
compartment_id = "${var.compartment_ocid}"
5+
display_name = "myvcn"
6+
dns_label = "myvcn"
7+
}
8+
9+
resource "oci_core_internet_gateway" "my_internet_gateway" {
10+
compartment_id = "${var.compartment_ocid}"
11+
display_name = "my internet gateway"
12+
vcn_id = "${oci_core_virtual_network.my_vcn.id}"
13+
}
14+
15+
resource "oci_core_route_table" "my_route_table" {
16+
compartment_id = "${var.compartment_ocid}"
17+
vcn_id = "${oci_core_virtual_network.my_vcn.id}"
18+
display_name = "my route table"
19+
route_rules {
20+
cidr_block = "0.0.0.0/0"
21+
network_entity_id = "${oci_core_internet_gateway.my_internet_gateway.id}"
22+
}
23+
}
24+
25+
resource "oci_core_subnet" "my_subnet" {
26+
availability_domain = "${var.availability_domain}"
27+
cidr_block = "${var.my_subnet_cidr}"
28+
display_name = "mysubnet"
29+
dns_label = "mysubnet"
30+
compartment_id = "${var.compartment_ocid}"
31+
vcn_id = "${oci_core_virtual_network.my_vcn.id}"
32+
security_list_ids = ["${oci_core_security_list.my_security_list.id}"]
33+
route_table_id = "${oci_core_route_table.my_route_table.id}"
34+
}
35+

docs/examples/storage/fss/security_list.tf

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "oci_core_security_list" "my_security_list" {
1010
egress_security_rules = [
1111
{
1212
destination = "0.0.0.0/0"
13-
protocol = "6"
13+
protocol = "all"
1414
}]
1515

1616
// See https://docs.us-phoenix-1.oraclecloud.com/Content/File/Tasks/creatingfilesystems.htm.
@@ -41,8 +41,38 @@ resource "oci_core_security_list" "my_security_list" {
4141
source = "${var.my_vcn-cidr}"
4242

4343
tcp_options {
44-
"max" = 111
4544
"min" = 111
45+
"max" = 111
4646
}
47-
}]
47+
},
48+
// Allowing inbound SSH traffic to instances in the subnet from any source
49+
{
50+
protocol = "6"
51+
source = "0.0.0.0/0"
52+
53+
tcp_options {
54+
"min" = 22
55+
"max" = 22
56+
}
57+
},
58+
// Allowing inbound ICMP traffic of a specific type and code from any source
59+
{
60+
protocol = 1
61+
source = "0.0.0.0/0"
62+
63+
icmp_options {
64+
"type" = 3
65+
"code" = 4
66+
}
67+
},
68+
// Allowing inbound ICMP traffic of a specific type from within our VCN
69+
{
70+
protocol = 1
71+
source = "${var.my_vcn-cidr}"
72+
73+
icmp_options {
74+
"type" = 3
75+
}
76+
}
77+
]
4878
}

docs/examples/storage/fss/subnet.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/examples/storage/fss/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,23 @@ variable "max_byte" {
7070

7171
variable "max_files" {
7272
default = 223442
73+
}
74+
75+
variable "instance_image_ocid" {
76+
type = "map"
77+
default = {
78+
// Oracle-provided image "Oracle-Linux-7.4-2017.12.18-0"
79+
// See https://docs.us-phoenix-1.oraclecloud.com/Content/Resources/Assets/OracleProvidedImageOCIDs.pdf
80+
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaasc56hnpnx7swoyd2fw5gyvbn3kcdmqc2guiiuvnztl2erth62xnq"
81+
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaaxrqeombwty6jyqgk3fraczdd63bv66xgfsqka4ktr7c57awr3p5a"
82+
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaayxmzu6n5hsntq4wlffpb4h6qh6z3uskpbm5v3v4egqlqvwicfbyq"
83+
}
84+
}
85+
86+
variable "instance_shape" {
87+
default = "VM.Standard1.2"
88+
}
89+
90+
locals {
91+
mount_target_1_ip_address = "${lookup(data.oci_core_private_ips.ip_mount_target1.private_ips[0], "ip_address")}"
7392
}

docs/examples/storage/fss/vcn.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)