Skip to content
This repository was archived by the owner on Mar 3, 2022. It is now read-only.

Commit 267a4da

Browse files
alexng-canuckscross01
authored andcommitted
Copy solutions to this repo from github.com/oracle/terraform-provider-oci
These solutions were copied from https://github.com/oracle/terraform-provider-oci/tree/master/docs/solutions
1 parent 49a5bc2 commit 267a4da

File tree

121 files changed

+4963
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4963
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ id_rsa
66
id_rsa.pub
77
.DS_Store
88
*.zip
9+
*.iml
10+
.idea

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ This repository provides sample/example terraform configurations and modules for
1010
Examples
1111
--------
1212

13-
- [Oracle Cloud Infrastructure](https://github.com/oracle/terraform-provider-oci/tree/master/docs/examples)
13+
- [Oracle Cloud Infrastructure](examples/oci)
1414
- [Oracle Cloud Infrastructure Classic](examples/opc)
1515
- [Oracle Cloud Platform](examples/oraclepaas)

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Examples
55
- [`oraclepaas`](./oraclepaas) examples for the Oracle Cloud Platform `oraclepaas` provider
66

77

8-
- [`oci`](https://github.com/oracle/terraform-provider-oci/tree/master/docs/examples) examples for the Oracle Cloud Infrastructure `oci` provider (separate repo)
8+
- [`oci`](./oci) examples for the Oracle Cloud Infrastructure `oci` provider

examples/oci/chef/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.

examples/oci/chef/compute.tf

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
resource "oci_core_instance" "TFInstance" {
2+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "ChefNodeExample"
5+
hostname_label = "instance1"
6+
image = "${var.InstanceImageOCID[var.region]}"
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+
18+
provisioner "chef" {
19+
server_url = "${var.chef_server}"
20+
node_name = "${var.chef_node_name}"
21+
run_list = "${var.chef_recipes}"
22+
user_name = "${var.chef_user}"
23+
user_key = "${file(var.chef_key)}"
24+
recreate_client = true
25+
fetch_chef_certificates = true
26+
connection {
27+
host = "${self.public_ip}"
28+
type = "ssh"
29+
user = "opc"
30+
private_key = "${var.ssh_private_key}"
31+
timeout = "3m"
32+
}
33+
}
34+
35+
#You will need knife.rb in your current path in order for this command to complete successfully.
36+
provisioner "local-exec" {
37+
when = "destroy"
38+
on_failure = "continue"
39+
command = "knife node delete ${var.chef_node_name} -y",
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.vagrant
2+
*~
3+
*#
4+
.#*
5+
\#*#
6+
.*.sw[a-z]
7+
*.un~
8+
9+
# Bundler
10+
Gemfile.lock
11+
bin/*
12+
.bundle/*
13+
14+
# test kitchen
15+
.kitchen/
16+
.kitchen.local.yml
17+
18+
# Chef
19+
Berksfile.lock
20+
.zero-knife.rb
21+
Policyfile.lock.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
source 'https://supermarket.chef.io'
3+
4+
metadata
5+
6+
cookbook 'firewall', '~> 2.6.2'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# example_webserver
2+
3+
This recipe installs a web server and configure the firewall to allow inbound http and ssh connections.
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Put files/directories that should be ignored in this file when uploading
2+
# to a chef-server or supermarket.
3+
# Lines that start with '# ' are comments.
4+
5+
# OS generated files #
6+
######################
7+
.DS_Store
8+
Icon?
9+
nohup.out
10+
ehthumbs.db
11+
Thumbs.db
12+
13+
# SASS #
14+
########
15+
.sass-cache
16+
17+
# EDITORS #
18+
###########
19+
\#*
20+
.#*
21+
*~
22+
*.sw[a-z]
23+
*.bak
24+
REVISION
25+
TAGS*
26+
tmtags
27+
*_flymake.*
28+
*_flymake
29+
*.tmproj
30+
.project
31+
.settings
32+
mkmf.log
33+
34+
## COMPILED ##
35+
##############
36+
a.out
37+
*.o
38+
*.pyc
39+
*.so
40+
*.com
41+
*.class
42+
*.dll
43+
*.exe
44+
*/rdoc/
45+
46+
# Testing #
47+
###########
48+
.watchr
49+
.rspec
50+
spec/*
51+
spec/fixtures/*
52+
test/*
53+
features/*
54+
examples/*
55+
Guardfile
56+
Procfile
57+
.kitchen*
58+
.rubocop.yml
59+
spec/*
60+
Rakefile
61+
.travis.yml
62+
.foodcritic
63+
.codeclimate.yml
64+
65+
# SCM #
66+
#######
67+
.git
68+
*/.git
69+
.gitignore
70+
.gitmodules
71+
.gitconfig
72+
.gitattributes
73+
.svn
74+
*/.bzr/*
75+
*/.hg/*
76+
*/.svn/*
77+
78+
# Berkshelf #
79+
#############
80+
Berksfile
81+
Berksfile.lock
82+
cookbooks/*
83+
tmp
84+
85+
# Policyfile #
86+
##############
87+
Policyfile.rb
88+
Policyfile.lock.json
89+
90+
# Cookbooks #
91+
#############
92+
CONTRIBUTING*
93+
CHANGELOG*
94+
TESTING*
95+
MAINTAINERS.toml
96+
97+
# Strainer #
98+
############
99+
Colanderfile
100+
Strainerfile
101+
.colander
102+
.strainer
103+
104+
# Vagrant #
105+
###########
106+
.vagrant
107+
Vagrantfile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name 'example_webserver'
2+
maintainer 'The Authors'
3+
maintainer_email 'you@example.com'
4+
license 'All Rights Reserved'
5+
description 'Installs/Configures example_webserver'
6+
long_description 'Installs/Configures example_webserver'
7+
version '0.1.0'
8+
chef_version '>= 12.1' if respond_to?(:chef_version)
9+
10+
depends 'firewall'
11+
12+
# The `issues_url` points to the location where issues for this cookbook are
13+
# tracked. A `View Issues` link will be displayed on this cookbook's page when
14+
# uploaded to a Supermarket.
15+
#
16+
# issues_url 'https://github.com/<insert_org_here>/example_webserver/issues'
17+
18+
# The `source_url` points to the development repository for this cookbook. A
19+
# `View Source` link will be displayed on this cookbook's page when uploaded to
20+
# a Supermarket.
21+
#
22+
# source_url 'https://github.com/<insert_org_here>/example_webserver'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Cookbook:: example_webserver
3+
# Recipe:: default
4+
#
5+
# Copyright:: 2017, The Authors, All Rights Reserved.
6+
7+
package "httpd" do
8+
action :install
9+
end
10+
11+
service "httpd" do
12+
action [:enable, :start]
13+
end
14+
15+
firewall 'default'
16+
17+
# enable platform default firewall
18+
firewall 'default' do
19+
action :install
20+
end
21+
22+
firewall_rule 'http' do
23+
port 80
24+
command :allow
25+
end
26+
27+
firewall_rule 'ssh' do
28+
port 22
29+
command :allow
30+
end
31+
32+
# create an example index page on the web server
33+
file '/var/www/html/index.html' do
34+
content 'Hello World!'
35+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
require 'chefspec'
3+
require 'chefspec/berkshelf'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Cookbook:: example_webserver
3+
# Spec:: default
4+
#
5+
# Copyright:: 2017, The Authors, All Rights Reserved.
6+
7+
require 'spec_helper'
8+
9+
describe 'example_webserver::default' do
10+
context 'When all attributes are default, on an Ubuntu 16.04' do
11+
let(:chef_run) do
12+
# for a complete list of available platforms and versions see:
13+
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
14+
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
15+
runner.converge(described_recipe)
16+
end
17+
18+
it 'converges successfully' do
19+
expect { chef_run }.to_not raise_error
20+
end
21+
end
22+
end

examples/oci/chef/datasources.tf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Gets a list of Availability Domains
2+
data "oci_identity_availability_domains" "ADs" {
3+
compartment_id = "${var.tenancy_ocid}"
4+
}
5+
6+
# Gets a list of vNIC attachments on the instance
7+
data "oci_core_vnic_attachments" "InstanceVnics" {
8+
compartment_id = "${var.compartment_ocid}"
9+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
10+
instance_id = "${oci_core_instance.TFInstance.id}"
11+
}
12+
13+
# Gets the OCID of the first (default) vNIC
14+
data "oci_core_vnic" "InstanceVnic" {
15+
vnic_id = "${lookup(data.oci_core_vnic_attachments.InstanceVnics.vnic_attachments[0],"vnic_id")}"
16+
}

examples/oci/chef/env-vars

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
### Region
8+
export TF_VAR_region="<region in which to operate, example: us-ashburn-1, us-phoenix-1>"
9+
10+
### Compartment
11+
export TF_VAR_compartment_ocid="<compartment OCID>"
12+
13+
### Public/private keys used on the instance
14+
export TF_VAR_ssh_public_key=$(cat <path to public key>)
15+
export TF_VAR_ssh_private_key=$(cat <path to private key>)
16+
## NOTE: These are not your api keys. More info on the right keys see
17+
## https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingkeypairs.htm
18+
19+
## Specific to this example
20+
### Choose a subnet that exists in the AD and compartment you are launching the instance in
21+
export TF_VAR_SubnetOCID="<subnet>"
22+
export TF_VAR_AD="<availability domain>"
23+
24+
# Path to Chef SSL certificate
25+
export TF_VAR_chef_key="<SSL certificate path>"
26+
export TF_VAR_chef_user="<Chef user>"
27+
export TF_VAR_chef_node_name="<Chef node name>"
28+
export TF_VAR_chef_recipes='["recipe[example_webserver::default]"]'
29+
export TF_VAR_chef_server="https://<Chef server IP>/organizations/<Organization>"

0 commit comments

Comments
 (0)