Skip to content

Instantly share code, notes, and snippets.

View mlabouardy's full-sized avatar
☁️
Subscribe to my newsletter ➡️ https://devopsbulletin.com

LABOUARDY Mohamed mlabouardy

☁️
Subscribe to my newsletter ➡️ https://devopsbulletin.com
View GitHub Profile
@mlabouardy
mlabouardy / main.tf
Created January 5, 2019 13:33
Deploy Nexus repository on GCP with Terraform
provider "google" {
credentials = "${file("${var.credentials}")}"
project = "${var.project}"
region = "${var.region}"
}
resource "google_compute_firewall" "nexus" {
name = "nexus-firewall"
network = "${google_compute_network.nexus.name}"
@mlabouardy
mlabouardy / network.tf
Created January 5, 2019 13:26
Expose Nexus docker repository on GCP
resource "google_compute_firewall" "nexus" {
name = "nexus-firewall"
network = "${google_compute_network.nexus.name}"
allow {
protocol = "tcp"
ports = ["22", "8081", "5000"]
}
source_ranges = ["0.0.0.0/0"]
@mlabouardy
mlabouardy / network.tf
Created January 5, 2019 11:32
Allow inbound traffic on port 8080
resource "google_compute_firewall" "swarm" {
name = "swarm-firewall"
network = "${google_compute_network.swarm.name}"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
@mlabouardy
mlabouardy / deploy.sh
Created January 5, 2019 11:30
Deploy visualizer in swarm
docker service create --name=visualizer --publish=8080:8080/tcp \
--constraint=node.role==manager --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
dockersamples/visualizer
@mlabouardy
mlabouardy / main.yml
Created January 5, 2019 11:14
Provision GCP instances to Swarm cluster
---
- name: Install Python
hosts: managers:workers
gather_facts: False
roles:
- python
- name: Init Swarm cluster
hosts: managers
gather_facts: False
@mlabouardy
mlabouardy / inventory.tpl
Created January 5, 2019 11:12
Inventory template file
[managers]
${managers}
[workers]
${workers}
@mlabouardy
mlabouardy / inventory.tf
Created January 5, 2019 11:11
Generate host inventory for Ansible with Terraform
data "template_file" "inventory" {
template = "${file("templates/inventory.tpl")}"
depends_on = [
"google_compute_instance.managers",
"google_compute_instance.workers",
]
vars {
managers = "${join("\n", google_compute_instance.managers.*.network_interface.0.access_config.0.nat_ip)}"
@mlabouardy
mlabouardy / network.tf
Created January 5, 2019 11:10
Docker swarm port requirements in GCP
resource "google_compute_firewall" "swarm" {
name = "swarm-firewall"
network = "${google_compute_network.swarm.name}"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
@mlabouardy
mlabouardy / swarm-workers.tf
Created January 5, 2019 11:07
Swarm workers on GCP
resource "google_compute_instance" "workers" {
count = "${var.swarm_workers}"
name = "worker${count.index + 1}"
machine_type = "${var.swarm_workers_instance_type}"
zone = "${var.zone}"
depends_on = ["google_compute_instance.managers"]
boot_disk {
initialize_params {
@mlabouardy
mlabouardy / swarm-managers.tf
Created January 5, 2019 11:06
Swarm managers on GCP
resource "google_compute_instance" "managers" {
count = "${var.swarm_managers}"
name = "manager"
machine_type = "${var.swarm_managers_instance_type}"
zone = "${var.zone}"
boot_disk {
initialize_params {
image = "${var.image_name}"
size = 100