Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/swarm-cluster: add advanced docker swarm cluster example #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
swarm updates
  • Loading branch information
lvnilesh committed Feb 16, 2018
commit 45a89f7d14c904a07513bc8121a7760ea1acac32
10 changes: 10 additions & 0 deletions examples/swarm-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Set an environment variable containing the Vultr API key:

export VULTR_API_KEY=<your-vultr-api-key>

or

Save vultr api key in a file `~/.creds/vultr_api_token`

Note: as an alternative, the API key can be specified in configuration as shown below.

// Configure the Vultr provider.
Expand All @@ -19,3 +23,9 @@ Note: as an alternative, the API key can be specified in configuration as shown
or

brew install jq



the same on digital ocean

https://knpw.rs/blog/docker-swarm-terraform
6 changes: 5 additions & 1 deletion examples/swarm-cluster/manager.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
provider "vultr" {
api_key = "${chomp(file("~/.creds/vultr_api_token"))}"
}

// Create swarm_manager

resource "vultr_instance" "swarm_manager" {
Expand All @@ -6,7 +10,7 @@ resource "vultr_instance" "swarm_manager" {
region_id = "${data.vultr_region.my_region.id}"
plan_id = "${data.vultr_plan.manager_plan.id}"
os_id = "${data.vultr_os.my_os.id}"
ssh_key_ids = ["${data.vultr_ssh_key.nilesh.id}"]
ssh_key_ids = ["${vultr_ssh_key.nilesh.id}"]
hostname = "${terraform.workspace}-manager-${count.index}"
tag = "manager"
private_networking= true
Expand Down
7 changes: 2 additions & 5 deletions examples/swarm-cluster/output.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
output "workspace" {
value = "${terraform.workspace}"
}
output "swarm_manager_token" {
value = "${data.external.swarm_tokens.result.manager}"
}
output "swarm_worker_token" {
value = "${data.external.swarm_tokens.result.worker}"
output "swarm_tokens" {
value = "${data.external.swarm_tokens.result}"
}
output "manager_count" {
value = ["${vultr_instance.swarm_manager.count}"]
Expand Down
5 changes: 5 additions & 0 deletions examples/swarm-cluster/ssh_key.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Create a new SSH key.
resource "vultr_ssh_key" "nilesh" {
name = "nilesh"
public_key = "${file("~/.ssh/id_rsa.pub")}"
}
2 changes: 1 addition & 1 deletion examples/swarm-cluster/worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "vultr_instance" "swarm_worker" {
region_id = "${data.vultr_region.my_region.id}"
plan_id = "${data.vultr_plan.worker_plan.id}"
os_id = "${data.vultr_os.my_os.id}"
ssh_key_ids = ["${data.vultr_ssh_key.nilesh.id}"]
ssh_key_ids = ["${vultr_ssh_key.nilesh.id}"]
hostname = "${terraform.workspace}-worker-${count.index}"
tag = "worker"
private_networking= true
Expand Down