This is an example terraform configuration folder, look at all the history to get iterations from ground to stars.
Last active
January 16, 2017 23:53
-
-
Save gionn/787a3fc379eeac0ce01f to your computer and use it in GitHub Desktop.
Infrastructure as Code with Terraform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.env | |
terraform.tfstate* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "cloudflare_domain" { | |
description = "CloudFlare domain" | |
} | |
# Add a record to the domain | |
resource "cloudflare_record" "frontend" { | |
domain = "${var.cloudflare_domain}" | |
name = "coderstug" | |
value = "${digitalocean_droplet.web.0.ipv4_address}" | |
type = "A" | |
ttl = 3600 | |
} | |
# Add a record to the domain | |
resource "cloudflare_record" "frontend2" { | |
domain = "${var.cloudflare_domain}" | |
name = "coderstug" | |
value = "${digitalocean_droplet.web.1.ipv4_address}" | |
type = "A" | |
ttl = 3600 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "digitalocean_droplet" "web" { | |
image = "${var.do_image}" | |
name = "web-${count.index+1}" | |
region = "${var.do_region}" | |
size = "512mb" | |
ssh_keys = ["${digitalocean_ssh_key.root.fingerprint}"] | |
private_networking = true | |
count = 2 | |
provisioner "remote-exec" { | |
inline = [ | |
"curl -s -L https://www.getchef.com/chef/install.sh | bash -s -- -v 12.0.3", | |
] | |
connection { | |
user = "root" | |
key_file = "/home/gionn/.ssh/id_rsa" | |
} | |
} | |
} | |
resource "digitalocean_droplet" "db" { | |
image = "${var.do_image}" | |
name = "db" | |
region = "${var.do_region}" | |
size = "1gb" | |
ssh_keys = ["${digitalocean_ssh_key.root.fingerprint}"] | |
private_networking = true | |
provisioner "remote-exec" { | |
inline = [ | |
"curl -s -L https://www.getchef.com/chef/install.sh | bash -s -- -v 12.0.3", | |
] | |
connection { | |
user = "root" | |
key_file = "/home/gionn/.ssh/id_rsa" | |
} | |
} | |
} | |
# Create a new SSH key | |
resource "digitalocean_ssh_key" "root" { | |
name = "Terraform key" | |
public_key = "${file("/home/gionn/.ssh/id_rsa.pub")}" | |
} | |
output "web_address" { | |
value = "${join(" ", digitalocean_droplet.web.*.ipv4_address)}" | |
} | |
output "db_address" { | |
value = "${digitalocean_droplet.db.ipv4_address}" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure the DigitalOcean Provider | |
provider "digitalocean" { | |
token = "${var.do_token}" | |
} | |
variable "do_token" { | |
description = "DigitalOcean API Token" | |
} | |
# Configure the CloudFlare provider | |
provider "cloudflare" { | |
email = "${var.cloudflare_email}" | |
token = "${var.cloudflare_token}" | |
} | |
variable "cloudflare_email" { | |
description = "CloudFlare email" | |
} | |
variable "cloudflare_token" { | |
description = "CloudFlare api token" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "do_region" { | |
description = "Main region where to deploy" | |
default = "lon1" | |
} | |
variable "do_image" { | |
description = "Image name to deploy" | |
default = "ubuntu-14-04-x64" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment