Skip to content

Instantly share code, notes, and snippets.

@matt40k
Created September 29, 2017 13:21
Show Gist options
  • Save matt40k/9086a7e0de6d38a4b7e970b5fdadba81 to your computer and use it in GitHub Desktop.
Save matt40k/9086a7e0de6d38a4b7e970b5fdadba81 to your computer and use it in GitHub Desktop.
Terraform
variable "environment" {
description = "this environment"
default = "poc1"
}
resource "digitalocean_droplet" "web" {
name = "web-1-${var.environment}"
size = "512mb"
image = "ubuntu-14-04-x64"
region = "lon1"
tags = ["web", "${var.environment}"]
ipv6 = false
private_networking = false
}
variable "environment" {
description = "this environment"
default = "poc1"
}
# Get CloudFlare IPs
data "http" "cf_ip4" {
url = "https://www.cloudflare.com/ips-v4"
}
data "http" "cf_ip6" {
url = "https://www.cloudflare.com/ips-v6"
}
# Get my IP
data "http" "myip" {
url = "https://ident.me/"
}
resource "digitalocean_droplet" "web" {
name = "web-1-${var.environment}"
size = "512mb"
image = "ubuntu-14-04-x64"
region = "lon1"
tags = ["web", "${var.environment}"]
ipv6 = false
private_networking = false
}
resource "digitalocean_firewall" "web" {
name = "onlyMeAndCf"
tags = ["web"]
inbound_rule = [
{
protocol = "tcp"
port_range = "443"
source_addresses = ["${split("\n", data.http.cf_ip4.body)}", "${split("\n", data.http.cf_ip4.body)}"]
}
,{
protocol = "tcp"
port_range = "22"
source_addresses = ["${data.http.myip.body}"]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment