initial commit

This commit is contained in:
Gianluca Arbezzano
2020-08-20 13:53:27 +02:00
commit 6ede8cb2e3
25 changed files with 1317 additions and 0 deletions

View File

@ -0,0 +1 @@
https://tinkerbell.org/docs/setup/packet-with-terraform/

17
deploy/terraform/input.tf Normal file
View File

@ -0,0 +1,17 @@
variable "packet_api_token" {
description = "Packet user api token"
}
variable "project_id" {
description = "Project ID"
}
variable "facility" {
description = "Packet facility to provision in"
default = "sjc1"
}
variable "device_type" {
description = "Type of device to provision"
default = "c3.small.x86"
}

View File

@ -0,0 +1,66 @@
#!/usr/bin/env bash
YUM="yum"
APT="apt"
PIP3="pip3"
YUM_CONFIG_MGR="yum-config-manager"
WHICH_YUM=$(command -v $YUM)
WHICH_APT=$(command -v $APT)
YUM_INSTALL="$YUM install"
APT_INSTALL="$APT install"
PIP3_INSTALL="$PIP3 install"
declare -a YUM_LIST=("https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm"
"docker-ce"
"docker-ce-cli"
"epel-release"
"python3")
declare -a APT_LIST=("docker"
"docker-compose")
add_yum_repo() (
$YUM_CONFIG_MGR --add-repo https://download.docker.com/linux/centos/docker-ce.repo
)
update_yum() (
$YUM_INSTALL -y yum-utils
add_yum_repo
)
update_apt() (
$APT update
DEBIAN_FRONTEND=noninteractive $APT --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
)
restart_docker_service() (
service docker restart
)
install_yum_packages() (
$YUM_INSTALL "${YUM_LIST[@]}" -y
)
install_pip3_packages() (
$PIP3_INSTALL docker-compose
)
install_apt_packages() (
$APT_INSTALL "${APT_LIST[@]}" -y
)
main() (
if [[ -n $WHICH_YUM ]]; then
update_yum
install_yum_packages
install_pip3_packages
restart_docker_service
elif [[ -n $WHICH_APT ]]; then
update_apt
install_apt_packages
restart_docker_service
else
echo "Unknown platform. Error while installing the required packages"
exit 1
fi
)
main

65
deploy/terraform/main.tf Normal file
View File

@ -0,0 +1,65 @@
# Configure the Packet Provider.
provider "packet" {
auth_token = var.packet_api_token
version = "~> 2.9"
}
# Create a new VLAN in datacenter "ewr1"
resource "packet_vlan" "provisioning-vlan" {
description = "provisioning-vlan"
facility = var.facility
project_id = var.project_id
}
# Create a device and add it to tf_project_1
resource "packet_device" "tink-provisioner" {
hostname = "tink-provisioner"
plan = var.device_type
facilities = [var.facility]
operating_system = "ubuntu_18_04"
billing_cycle = "hourly"
project_id = var.project_id
network_type = "hybrid"
user_data = "${file("install_package.sh")}"
}
}
# Create a device and add it to tf_project_1
resource "packet_device" "tink-worker" {
hostname = "tink-worker"
plan = var.device_type
facilities = [var.facility]
operating_system = "custom_ipxe"
ipxe_script_url = "https://boot.netboot.xyz"
always_pxe = "true"
billing_cycle = "hourly"
project_id = var.project_id
network_type = "layer2-individual"
}
# Attach VLAN to provisioner
resource "packet_port_vlan_attachment" "provisioner" {
device_id = packet_device.tink-provisioner.id
port_name = "eth1"
vlan_vnid = packet_vlan.provisioning-vlan.vxlan
}
# Attach VLAN to worker
resource "packet_port_vlan_attachment" "worker" {
device_id = packet_device.tink-worker.id
port_name = "eth0"
vlan_vnid = packet_vlan.provisioning-vlan.vxlan
}
output "provisioner_dns_name" {
value = "${split("-", packet_device.tink-provisioner.id)[0]}.packethost.net"
}
output "provisioner_ip" {
value = "${packet_device.tink-provisioner.network[0].address}"
}
output "worker_mac_addr" {
value = "${packet_device.tink-worker.ports[1].mac}"
}