|
| 1 | + # ___ ____ _ ____ _ _____ |
| 2 | + # / _ \| _ \ / \ / ___| | | ____| |
| 3 | + # | | | | |_) | / _ \| | | | | _| |
| 4 | + # | |_| | _ < / ___ | |___| |___| |___ |
| 5 | + # \___/|_| \_/_/ \_\____|_____|_____| |
| 6 | +*** |
| 7 | +## Bootstrap an instance as a Chef node |
| 8 | +This example shows how to use Terraform to bootstrap an OCI instance as a Chef node, register it with an existing Chef server, and run a recipe. When the plan completes, you will have a running web server with content and the correct firewall configuration. |
| 9 | + |
| 10 | +### Prerequisites |
| 11 | + |
| 12 | +* `knife` must be installed and configured in your PATH. This allows the Chef node deletion to work properly when `terraform destroy` is called. |
| 13 | +* Access to a Chef server to upload the example_webserver recipe to. |
| 14 | + |
| 15 | +### Using this example |
| 16 | +* Update env-vars with the required information. Most examples use the same set of environment variables so you only need to do this once. |
| 17 | +* Source env-vars |
| 18 | + * `$ . env-vars` |
| 19 | +* Update `variables.tf` with your instance options. |
| 20 | +* Upload the example Chef recipe and its dependencies to your Chef server. |
| 21 | + * `$ cd cookbooks/example_webserver` |
| 22 | + * `$ berks install` |
| 23 | + * `$ berks upload` |
| 24 | +* Run `terraform apply`. |
| 25 | +* Navigate to the public IP address (reported by Terraform, above) in your browser. |
| 26 | + |
| 27 | +### Files in the configuration |
| 28 | + |
| 29 | +#### `env-vars` |
| 30 | +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. |
| 31 | + |
| 32 | +Before you plan, apply, or destroy the configuration source the file - |
| 33 | +`$ . env-vars` |
| 34 | + |
| 35 | +#### `compute.tf` |
| 36 | +Defines the compute resource. This demo connects to the running instance |
| 37 | +so you will need to supply public/private keys to create an ssh connection. |
| 38 | +**NOTE**: do not try to use your api keys, see [this doc](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingkeypairs.htm) |
| 39 | +for more info on configuring keys. |
| 40 | + |
| 41 | +#### `./userdata/bootstrap` |
| 42 | +The user-data script that gets injected into the instance on launch. More information on user-data scripts can be [found at the cloud-init project.](https://cloudinit.readthedocs.io/en/latest/topics/format.html) |
| 43 | + |
| 44 | +#### `variables.tf` |
| 45 | +Defines the variables used in the configuration |
| 46 | + |
| 47 | +#### `datasources.tf` |
| 48 | +Defines the datasources used in the configuration |
| 49 | + |
| 50 | +#### `outputs.tf` |
| 51 | +Defines the outputs of the configuration |
| 52 | + |
| 53 | +#### `provider.tf` |
| 54 | +Specifies and passes authentication details to the OCI TF provider |
| 55 | + |
| 56 | +#### `./cookbooks/example_webserver/recipes/default.rb` |
| 57 | +Installs a web server and configures the firewall to allow inbound http and ssh connections. |
0 commit comments