Skip to content

Commit 8b4bc85

Browse files
committed
Merge branch 'master' of github.com:oracle/terraform-provider-baremetal
2 parents a429493 + 372eac3 commit 8b4bc85

13 files changed

+441
-2
lines changed

data_source_obmcs_identity_user_group_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (s *ResourceIdentityUserGroupMembershipsTestSuite) SetupTest() {
4747
description = "group desc"
4848
}
4949
resource "baremetal_identity_user_group_membership" "ug_membership" {
50-
compartment_id = "cid"
50+
compartment_id = "cid"
5151
user_id = "${baremetal_identity_user.u.id}"
5252
group_id = "${baremetal_identity_group.g.id}"
5353
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ___ ____ _ ____ _ _____
2+
# / _ \| _ \ / \ / ___| | | ____|
3+
# | | | | |_) | / _ \| | | | | _|
4+
# | |_| | _ < / ___ | |___| |___| |___
5+
# \___/|_| \_/_/ \_\____|_____|_____|
6+
***
7+
## Start a NFS server
8+
This example launches an instance into an existing subnet, creates and attaches a 2TB LUN, installs and starts a NFS server, and outputs the public and private IP address of the instance.
9+
10+
### Using this example
11+
* Update env-var with the required information. Most examples use the same set of environment variables so you only need to do this once.
12+
* Source env-var
13+
* `$ . env-var`
14+
* Update `variables.tf` with your instance options.
15+
16+
### Files in the configuration
17+
18+
#### `env-vars`
19+
Is used to export the environmental variables used in the configuration. These are usually authentication related, be sure to exclude this file from your version control system. It's typical to keep this file outside of the configuration.
20+
21+
Before you plan, apply, or destroy the configuration source the file -
22+
`$ . env-vars`
23+
24+
#### `compute.tf`
25+
Defines the compute resource
26+
27+
#### `./userdata/nfs-bootstrap`
28+
The user-data script that gets injected into the instance on launch to install and configure NFS. More information on user-data scripts can be [found at the cloud-init project.](https://cloudinit.readthedocs.io/en/latest/topics/format.html)
29+
30+
#### `variables.tf`
31+
Defines the variables used in the configuration
32+
33+
#### `datasources.tf`
34+
Defines the datasources used in the configuration
35+
36+
#### `outputs.tf`
37+
Defines the outputs of the configuration
38+
39+
#### `provider.tf`
40+
Specifies and passes authentication details to the OBMCS TF provider
41+
42+
#### `iscsiattach.sh`
43+
Scans the iscsi bus for new LUNs

docs/examples/storage/nfs/block.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resource "baremetal_core_volume" "TFBlock0" {
2+
availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "2TB NFS"
5+
size_in_mbs = "${var.2TB}"
6+
}
7+
8+
resource "baremetal_core_volume_attachment" "TFBlock0Attach" {
9+
attachment_type = "iscsi"
10+
compartment_id = "${var.compartment_ocid}"
11+
instance_id = "${baremetal_core_instance.TFInstance.id}"
12+
volume_id = "${baremetal_core_volume.TFBlock0.id}"
13+
}
14+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "baremetal_core_instance" "TFInstance" {
2+
availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "NFS server"
5+
hostname_label = "NFSserver"
6+
image = "${lookup(data.baremetal_core_images.OLImageOCID.images[0], "id")}"
7+
shape = "${var.InstanceShape}"
8+
subnet_id = "${var.SubnetOCID}"
9+
metadata {
10+
ssh_authorized_keys = "${var.ssh_public_key}"
11+
user_data = "${base64encode(file(var.BootStrapFile))}"
12+
}
13+
14+
timeouts {
15+
create = "60m"
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Gets a list of Availability Domains
2+
data "baremetal_identity_availability_domains" "ADs" {
3+
compartment_id = "${var.tenancy_ocid}"
4+
}
5+
6+
# Gets the OCID of the OS image to use
7+
data "baremetal_core_images" "OLImageOCID" {
8+
compartment_id = "${var.compartment_ocid}"
9+
operating_system = "${var.InstanceOS}"
10+
operating_system_version = "${var.InstanceOSVersion}"
11+
}
12+
13+
# Gets a list of vNIC attachments on the instance
14+
data "baremetal_core_vnic_attachments" "InstanceVnics" {
15+
compartment_id = "${var.compartment_ocid}"
16+
availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
17+
instance_id = "${baremetal_core_instance.TFInstance.id}"
18+
}
19+
20+
# Gets the OCID of the first (default) vNIC
21+
data "baremetal_core_vnic" "InstanceVnic" {
22+
vnic_id = "${lookup(data.baremetal_core_vnic_attachments.InstanceVnics.vnic_attachments[0],"vnic_id")}"
23+
}

docs/examples/storage/nfs/env-vars

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### Authentication details
2+
export TF_VAR_tenancy_ocid="<tenancy OCID"
3+
export TF_VAR_user_ocid="<user OCID>"
4+
export TF_VAR_fingerprint="<PEM key fingerprint>"
5+
export TF_VAR_private_key_path="<path to the private key that matches the fingerprint above>"
6+
7+
### Compartment
8+
export TF_VAR_compartment_ocid="<compartment OCID>"
9+
10+
### Public/private keys used on the instance
11+
export TF_VAR_ssh_public_key=$(cat <path to public key>)
12+
export TF_VAR_ssh_private_key=$(cat <path to private key>)
13+
14+
## Specific to this example
15+
### Choose a subnet that exists in the AD and compartment you are launching the instance in
16+
export TF_VAR_SubnetOCID="<subnet>"
17+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Output the private and public IPs of the instance
2+
3+
output "InstancePrivateIP" {
4+
value = ["${data.baremetal_core_vnic.InstanceVnic.private_ip_address}"]
5+
}
6+
7+
output "InstancePublicIP" {
8+
value = ["${data.baremetal_core_vnic.InstanceVnic.public_ip_address}"]
9+
}
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "baremetal" {
2+
tenancy_ocid = "${var.tenancy_ocid}"
3+
user_ocid = "${var.user_ocid}"
4+
fingerprint = "${var.fingerprint}"
5+
private_key_path = "${var.private_key_path}"
6+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# iscsiattach.sh - Scan and automatically attach new iSCSI targets
3+
#
4+
# Author: Steven B. Nelson, Sr. Solutions Architect
5+
# Oracle Bare Metal Cloud Services
6+
#
7+
# 20 April 2017
8+
# Copyright Oracle, Inc. All rights reserved.
9+
10+
# Make FIFO pipes for the two loops below
11+
mkfifo discpipe
12+
mkfifo sesspipe
13+
14+
# Set the address ranges based on the Block Storage version
15+
V1ADDR="169.254.0.2"
16+
V2ADDR="169.254.2.0"
17+
18+
# Set the block storage version
19+
BSV="v1"
20+
21+
# If the BSV is v2, we need to scan all 254 addresses, otherwise,
22+
# we scan 1. :-(
23+
24+
if [ ${BSV} = "v2" ]
25+
then
26+
numAddrs=254
27+
BASEADDR=${V2ADDR}
28+
else
29+
numAddrs=3
30+
BASEADDR=${V1ADDR}
31+
fi
32+
33+
# Set a base address incrementor so we can loop through all the
34+
# addresses.
35+
addrCount=0
36+
37+
echo "Scanning "${numAddrs}" for new targets. Stand by."
38+
while [ ${addrCount} -le ${numAddrs} ]
39+
do
40+
# Set the current address to attempt to attach.
41+
if [ ${BSV} = "v2" ]
42+
then
43+
CURRADDR=`echo ${BASEADDR} | awk -F\. '{
44+
last=$4+'${addrCount}'
45+
print $1"."$2"."$3"."last
46+
}'`
47+
else
48+
CURRADDR=`echo ${BASEADDR} | awk -F\. '{
49+
last=$3+'${addrCount}'
50+
print $1"."$2"."last"."$4
51+
}'`
52+
fi
53+
54+
# We use ping to see if the target is even there.
55+
# Skip to the next address if we cant ping it.
56+
ping -q -c 1 -W 1 ${CURRADDR} > /dev/null 2>&1
57+
result=$?
58+
if [ ${result} -ne 0 ]
59+
then
60+
(( addrCount = addrCount + 1 ))
61+
continue
62+
fi
63+
64+
echo "Connecting to "${CURRADDR}
65+
# Find all the iSCSI Block Storage volumes attached to the instance but
66+
# not configured for use on the instance. Basically, get a list of the
67+
# volumes that the instance can see, the loop through the ones it has,
68+
# and add volumes not already configured on the instance.
69+
#
70+
# First get the list of volumes visible (attached) to the instance
71+
72+
iscsiadm -m discovery -t st -p ${CURRADDR}:3260 | grep -v uefi | awk '{print $2}' > discpipe 2> /dev/null &
73+
74+
# If the result is non-zero, that generally means that there are no targets available or
75+
# that the portal is reachable but not active. We make no distinction between the two
76+
# and simply skip ahead.
77+
result=$?
78+
if [ ${result} -ne 0 ]
79+
then
80+
(( addrCount = addrCount + 1 ))
81+
continue
82+
fi
83+
84+
# Loop through the list (via the named FIFO pipe below)
85+
while read target
86+
do
87+
# Get the list of the currently attached Block Storage volumes
88+
iscsiadm -m session -P 0 | grep -v uefi | awk '{print $4}' > sesspipe 2> /dev/null &
89+
90+
# Set a flag, and loop through the sessions (attached, but not configured)
91+
# and see if the volumes match. If so, skip to the next until we get
92+
# through the list. Session list is via the pipe.
93+
found="false"
94+
while read session
95+
do
96+
if [ ${target} = ${session} ]
97+
then
98+
found="true"
99+
break
100+
fi
101+
done < sesspipe
102+
103+
# If the volume is not found, configure it. Get the resulting device file.
104+
if [ ${found} = "false" ]
105+
then
106+
iscsiadm -m node -o new -T ${target} -p ${CURRADDR}:3260
107+
iscsiadm -m node -o update -T ${target} -n node.startup -v automatic
108+
iscsiadm -m node -T ${target} -p ${CURRADDR}:3260 -l
109+
sleep 10
110+
fi
111+
done < discpipe
112+
(( addrCount = addrCount + 1 ))
113+
done
114+
echo "Scan Complete."
115+
116+
# Remove the FIFOs
117+
find . -maxdepth 1 -type p -exec rm {} \;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e
3+
4+
## Install and configure a NFS server to export a 2TB remote attached LUN.
5+
6+
### Send stdout, stderr to /var/log/messages/
7+
exec 1> >(logger -s -t $(basename $0)) 2>&1
8+
9+
### Storage setup
10+
wget -O /usr/local/bin/iscsiattach.sh https://raw.githubusercontent.com/oracle/terraform-provider-baremetal/master/docs/examples/storage/nfs/userdata/iscsiattach.sh
11+
chmod +x /usr/local/bin/iscsiattach.sh
12+
/usr/local/bin/iscsiattach.sh
13+
mkfs.xfs /dev/sdb
14+
mkdir /mnt/2tb-nfs
15+
mount -t xfs /dev/sdb /mnt/2tb-nfs/
16+
sdb_uuid=`blkid /dev/sdb -s UUID -o value`
17+
echo "UUID=$sdb_uuid /mnt/2tb-nfs xfs defaults,noatime,_netdev,nofail" >> /etc/fstab
18+
19+
20+
### NFS setup
21+
firewall-offline-cmd --zone=public --add-service=nfs
22+
yum -y install nfs-utils
23+
systemctl enable nfs-server.service
24+
systemctl start nfs-server.service
25+
chown nfsnobody:nfsnobody /mnt/2tb-nfs/
26+
chmod 777 /mnt/2tb-nfs/
27+
cidr=`ip addr show dev ens3 | grep "inet " | awk -F' ' '{print $2}'`
28+
echo "/mnt/2tb-nfs $cidr(rw,sync,no_subtree_check)" > /etc/exports
29+
exportfs -a
30+
31+
### YUM update
32+
yum update -y
33+
34+
### Firewall
35+
systemctl restart firewalld.service

0 commit comments

Comments
 (0)