Skip to content

Commit

Permalink
Merge pull request #19 from stavxyz/mongo-example
Browse files Browse the repository at this point in the history
Mongo example
  • Loading branch information
stavxyz authored Mar 13, 2021
2 parents dfee671 + 1f79e27 commit 7ecc20a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ That's it!

## Example

Let's say you have a relatively simple [Policyfile](https://docs.chef.io/policyfile) which bootstraps your machine with docker:
Let's say you have a relatively simple [Policyfile](https://docs.chef.io/policyfile) which provisions your machine with mongodb:


```ruby
name 'docker'
name 'mongodb'
default_source :supermarket
cookbook 'docker', '~> 7.7.0', :supermarket
run_list 'docker::default'
cookbook 'sc-mongodb', '~> 4.1.0', :supermarket
run_list 'sc-mongodb::default'
```

and you would like to apply this policy to a VM. For this example let's assume use a [DigitalOcean Droplet](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/droplet).
Expand All @@ -37,7 +37,7 @@ Also, for the sake of this example, let's assume your local private key, `~/.ssh
```terraform
resource "digitalocean_droplet" "chef-node" {
image = "ubuntu-18-04-x64"
name = "chef_docker_policy_droplet"
name = "chef_mongodb_policy_droplet"
region = "nyc2"
size = "s-1vcpu-1gb"
ssh_keys = ["my-ssh-key"]
Expand Down
3 changes: 3 additions & 0 deletions examples/do-sc-mongodb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Policyfile.lock.json

.ssh
4 changes: 4 additions & 0 deletions examples/do-sc-mongodb/Policyfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name 'mongodb'
default_source :supermarket
cookbook 'sc-mongodb', '~> 4.1.0', :supermarket
run_list 'sc-mongodb::default'
6 changes: 6 additions & 0 deletions examples/do-sc-mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## sc-mongodb example

In this example, we will provision a digitalocean
droplet as a chef managed node by installing and configuring mongodb

https://supermarket.chef.io/cookbooks/sc-mongodb
36 changes: 36 additions & 0 deletions examples/do-sc-mongodb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "tls_private_key" "default" {
algorithm = "RSA"
}

resource "local_file" "private_key" {
filename = "${path.cwd}/.ssh/${format("%s.pem", tls_private_key.default.public_key_fingerprint_md5)}"
sensitive_content = tls_private_key.default.private_key_pem
file_permission = "0600"
directory_permission = "0700"
}


resource "digitalocean_ssh_key" "default" {
name = "default"
public_key = tls_private_key.default.public_key_openssh
}

resource "digitalocean_droplet" "mongo" {
image = "ubuntu-18-04-x64"
name = "chef-mongo"
region = "nyc2"
size = "s-1vcpu-1gb"
ssh_keys = [digitalocean_ssh_key.default.fingerprint]
}

module "provision" {
source = "../.."
connection = {
host = digitalocean_droplet.mongo.ipv4_address
private_key = tls_private_key.default.private_key_pem
}
}

output "droplet_ip" {
value = digitalocean_droplet.mongo.ipv4_address
}
15 changes: 15 additions & 0 deletions examples/do-sc-mongodb/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

terraform {
required_version = ">= 0.13"
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
}
local = {
source = "hashicorp/local"
}
tls = {
source = "hashicorp/tls"
}
}
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ locals {


resource "null_resource" "deliver_ensure_chef_script" {
depends_on = [null_resource.create_target_dirs]
depends_on = [null_resource.create_target_dirs, null_resource.deliver_chef_installer_script]
# only deliver the ensure/installer script if the file has been changed
count = var.skip == true ? 0 : 1

Expand Down

0 comments on commit 7ecc20a

Please sign in to comment.