Skip to content

Commit d75dce7

Browse files
craigcarl-oraclemikejihbe
authored andcommitted
Reworked compute, MongoDB, DBSystems examples
1 parent 7c4cc45 commit d75dce7

38 files changed

+655
-438
lines changed

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ Oracle customers now have access to an enterprise class, developer friendly orch
99

1010
This Terraform provider is OSS, available to all OBMCS customers at no charge.
1111

12+
## Compatibility
13+
The provider is compatible with Terraform .8.\*, .8.8 is recommended. .9.\* compatibility is in the works.
14+
1215
### Coverage
13-
The Terraform provider provides coverage for the entire BMC API excluding the Load Balancer Service, expected March 1 2017.
16+
The Terraform provider provides coverage for the entire BMC API excluding the Load Balancer Service, expected first half of April 2017.
1417

1518
## Getting started
1619
Be sure to read the FAQ and Writing Terraform configurations for OBMCS in [/docs](https://github.com/oracle/terraform-provider-baremetal/tree/master/docs).
@@ -42,26 +45,28 @@ Required Keys and OCIDs - https://docs.us-phoenix-1.oraclecloud.com/Content/API/
4245
If you primarily work in a single compartment consider exporting that compartment's OCID as well. Remember that the tenancy OCID is also the OCID of the root compartment.
4346

4447
#### \*nix
45-
In your ~/.bash_profile set these variables
46-
`export TF_VAR_tenancy_ocid=`
47-
`export TF_VAR_user_ocid=`
48-
`export TF_VAR_fingerprint=`
49-
`export TF_VAR_private_key_path=<fully qualified path>`
50-
`export TF_VAR_private_key_password=`
48+
If your TF configurations are limited to a single compartment/user then using this `bash_profile` option will work well. For more complex environments you may want to maintain multiple sets of environment variables. [See the single-compute example for an example.](https://github.com/oracle/terraform-provider-baremetal/tree/master/docs/examples/compute/single-instance)
5149

50+
In your ~/.bash_profile set these variables
51+
```
52+
export TF_VAR_tenancy_ocid=
53+
export TF_VAR_user_ocid=
54+
export TF_VAR_fingerprint=
55+
export TF_VAR_private_key_path=<fully qualified path>`
56+
```
5257
Don't forget to `source ~/.bash_profile` once you've set these.
5358

5459
#### Windows
55-
`setx TF_VAR_tenancy_ocid <value>`
56-
`setx TF_VAR_user_ocid <value>`
57-
`setx TF_VAR_fingerprint <value>`
58-
`setx TF_VAR_private_key_path <value>`
59-
`setx TF_VAR_private_key_password <value>`
60-
60+
```
61+
setx TF_VAR_tenancy_ocid <value>
62+
setx TF_VAR_user_ocid <value>
63+
setx TF_VAR_fingerprint <value>
64+
setx TF_VAR_private_key_path <value>
65+
```
6166
The variables won't be set for the current session, exit the terminal and reopen.
6267

6368
## Deploy an example configuration
64-
Download the [VCN example configuration.](https://github.com/oracle/terraform-provider-baremetal/tree/master/docs/examples/network/simple_vcn)
69+
Download the [Single instance example.](https://github.com/oracle/terraform-provider-baremetal/tree/master/docs/examples/compute/single-instance)
6570

6671
Edit it to include the OCID of the compartment you want to create the VCN. Remember that the tenancy OCID is the compartment OCID of your root compartment.
6772

@@ -82,7 +87,7 @@ or meet us in the OBMCS forums
8287
https://community.oracle.com/community/cloud_computing/bare-metal
8388

8489
## Known serious bugs
85-
None
90+
See [Issues.](https://github.com/oracle/terraform-provider-baremetal/issues)
8691

87-
#### About the provider
92+
## About the provider
8893
This provider was written on behalf of Oracle by [MustWin.](http://mustwin.com/)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "baremetal_database_db_system" "TFDBNode" {
2+
availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[0],"name")}"
3+
compartment_id = "${var.compartment_ocid}"
4+
cpu_core_count = "${var.CPUCoreCount}"
5+
database_edition = "${var.DBEdition}"
6+
db_home {
7+
database {
8+
"admin_password" = "${var.DBAdminPassword}"
9+
"db_name" = "${var.DBName}"
10+
}
11+
db_version = "${var.DBVersion}"
12+
display_name = "${var.DBDisplayName}"
13+
}
14+
disk_redundancy = "${var.DBDiskRedundancy}"
15+
shape = "${var.DBNodeShape}"
16+
subnet_id = "${var.SubnetOCID}"
17+
ssh_public_keys = ["${var.ssh_private_key}"]
18+
display_name = "${var.DBNodeDisplayName}"
19+
domain = "${var.DBNodeDomainName}"
20+
hostname = "${var.DBNodeHostName}"
21+
}

docs/examples/DBsystems/DBsystems.tf

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

docs/examples/DBsystems/README.md

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+
## Manage an instance
8+
This example launches a Database System into an existing subnet and because it's an anti-pattern to launch an DBSystem in a subnet with Internet access, behind an existing bastion host. Database Systems don't support user-data scripts but there are still use cases where you might want to execute a script once the DBNode starts so we use the `file` and `remote-exec` provisoners to get through the bastion host and onto the instance. The configuration outputs the 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 launch options and bastion host IP.
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+
#### `DBSystem.tf`
25+
Defines the Database System
26+
27+
#### `remote-exec.tf`
28+
Uses a `null_resource`, `file`, `remote-exec` and `depends_on` to execute a script on the instance. [More information on the remote-exec provisioner.](https://www.terraform.io/docs/provisioners/remote-exec.html)
29+
30+
#### `./scripts/bootstrap.sh`
31+
A script that gets scp'ed onto the instance then executed.
32+
33+
#### `variables.tf`
34+
Defines the variables used in the configuration
35+
36+
#### `datasources.tf`
37+
Defines the datasources used in the configuration
38+
39+
#### `outputs.tf`
40+
Defines the outputs of the configuration
41+
42+
#### `provider.tf`
43+
Specifies and passes authentication details to the OBMCS TF provider
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Gets a list of Availability Domains
2+
data "baremetal_identity_availability_domains" "ADs" {
3+
compartment_id = "${var.tenancy_ocid}"
4+
}
5+
6+
# Get DB node details
7+
data "baremetal_database_db_node" "DBNodeDetails" {
8+
db_node_id = "${baremetal_database_db_system.TFDBNode.id}"
9+
}
10+
11+
# Gets the OCID of the first (default) vNIC
12+
data "baremetal_core_vnic" "DBNodeVnic" {
13+
vnic_id = "${lookup(data.baremetal_database_db_node.DBNodeDetails.vnic_id,"vnic_id")}"
14+
}
15+

docs/examples/DBsystems/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+

docs/examples/DBsystems/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Output the private IP of the instance
2+
3+
output "DBNodePrivateIP" {
4+
value = ["${data.baremetal_core_vnic.DBNodeVnic.private_ip_address}"]
5+
}
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "null_resource" "remote-exec" {
2+
depends_on = ["baremetal_database_db_system.TFDBNode"]
3+
provisioner "file" {
4+
connection {
5+
agent = false
6+
timeout = "10m"
7+
host = "${data.baremetal_core_vnic.DBNodeVnic.private_ip_address}"
8+
user = "${var.HostUserName}"
9+
private_key = "${var.ssh_private_key}"
10+
# Bastion details
11+
bastion_host = "${var.BastionHost}"
12+
bastion_user = "${var.HostUserName}"
13+
bastion_key = "${var.ssh_private_key}"
14+
}
15+
source = "./scripts/bootstrap"
16+
destination = "~/bootstrap.sh"
17+
18+
}
19+
20+
provisioner "remote-exec" {
21+
connection {
22+
agent = false
23+
timeout = "10m"
24+
host = "${data.baremetal_core_vnic.DBNodeVnic.private_ip_address}"
25+
user = "${var.HostUserName}"
26+
private_key = "${var.ssh_private_key}"
27+
# Bastion details
28+
bastion_host = "${var.BastionHost}"
29+
bastion_user = "${var.HostUserName}"
30+
bastion_key = "${var.ssh_private_key}"
31+
}
32+
inline = [
33+
"chmod +x ~/bootstrap.sh",
34+
"~/bootstrap.sh",
35+
]
36+
}
37+
}

0 commit comments

Comments
 (0)