Skip to content

Instantly share code, notes, and snippets.

@johananl
Created January 4, 2019 21:59
Show Gist options
  • Save johananl/1add0cec95f52087b31ac2393a9fca93 to your computer and use it in GitHub Desktop.
Save johananl/1add0cec95f52087b31ac2393a9fca93 to your computer and use it in GitHub Desktop.
Spot servers on Packet
provider "packet" {
auth_token = "${var.auth_token}"
}
# Packet auth token. Generate it on your Packet account. More info:
# https://support.packet.com/kb/articles/api-integrations
variable "auth_token" {}
# The Packet project ID. More info: https://support.packet.com/kb/articles/api-integrations
variable "project_id" {}
# Name for the server.
variable "hostname" {}
# Preferred Packet data center(s) to use. Query the Packet API for a list of facility codes:
# https://www.packet.com/developers/api/#facilities
# WARNING - if capacity is unavilable at the preferred facilities, servers may be launched in other
# facilities. More info here: https://www.packet.com/developers/api/#create-a-device
variable "facilities" {
type = "list"
}
# A list of *USER* IDs whose SSH keys should be authorized on the server. Again - the IDs of the
# USERS should be specified, not the IDs of the keys. Ask Packet why :-/
# https://support.packet.com/kb/articles/deploy-via-the-api
variable "user_ssh_keys" {
type = "list"
}
resource "packet_spot_market_request" "my-server" {
project_id = "${var.project_id}"
# A safe bet is to set this to the on-demand price of the server.
max_bid_price = "0.7"
facilities = "${var.facilities}"
# Create one server.
devices_min = 1
devices_max = 1
instance_parameters = {
hostname = "${var.hostname}"
billing_cycle = "hourly"
# The operating system to install on the server. More info:
# https://www.terraform.io/docs/providers/packet/r/device.html#operating_system
operating_system = "ubuntu_18_04"
# Determines the server type. 'baremetal_0' is t1.small.x86 More info:
# https://www.terraform.io/docs/providers/packet/r/device.html#plan
plan = "baremetal_0"
# Authorize SSH key on server.
user_ssh_keys = "${var.user_ssh_keys}"
}
# Without this, Terraform will exit as soon as the API request to Packet completed, which can
# create problems. For example, a server might be left behind when running 'terraform destroy'
# while the server is installing.
wait_for_devices = true
}
# This is a sample file with fake values.
auth_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
project_id = "3e27e97c-26b5-443d-aa65-e89e542892d0"
hostname = "my-server"
facilities = [
"ams1" # Amsterdam
]
user_ssh_keys = ["f3e8c6f8-cec5-4b20-a2b5-00f476aa0e0b"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment