Skip to content

Commit

Permalink
Use the Equinix Metal provider (#26)
Browse files Browse the repository at this point in the history
* replace packet provider with equinix/metal

To migrate an existing install:

```sh
git pull
terraform init
sed -i "" s/packet_/metal_/g terraform.tfstate # omit "" on Linux
terraform plan
```

Signed-off-by: Marques Johansson <[email protected]>

* avoid jitter on ssh_key_name

The key contents do not change, so this change is not breaking.
when applying this change, the plan will call for a renamed key file.
The old key file (~/.ssh/bm-something) will be renamed in the apply.

Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague authored Dec 16, 2020
1 parent 64bd909 commit c5479ef
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Users are responsible for providing their Equinix Metal account, and Anthos subs

The build (with default settings) typically takes 25-30 minutes.

**The automation in the repo is COMMUNITY SUPPORTED ONLY**, if the installation succeeds, and you run the Anthos Platform Validation this cluster is production grade and supportable by Google for Anthos and packet for Infrastructure. If you have any questions please consult with Equinix Metal Support via a support ticket.
**The automation in the repo is COMMUNITY SUPPORTED ONLY**, if the installation succeeds, and you run the Anthos Platform Validation this cluster is production grade and supportable by Google for Anthos and Equinix Metal for Infrastructure. If you have any questions please consult with Equinix Metal Support via a support ticket.

## Join us on Slack
We use [Slack](https://slack.com/) as our primary communication tool for collaboration. You can join the Equinix Metal Community Slack group by going to [slack.equinixmetal.com](https://slack.equinixmetal.com/) and submitting your email address. You will receive a message with an invite link. Once you enter the Slack group, join the **#google-anthos** channel! Feel free to introduce yourself there, but know it's not mandatory.
Expand All @@ -24,7 +24,7 @@ This is the initial release of this project. We support Ubuntu 20.04, Ubuntu 18.
To use these Terraform files, you need to have the following Prerequisites:
* An [Anthos subscription](https://cloud.google.com/anthos/docs/getting-started)
* Google Cloud service-account keys, check this [section](#-service-account-generation)
* A Equinix Metal org-id and [API key](https://www.packet.com/developers/api/)
* A Equinix Metal org-id and [API key](https://metal.equinix.com/developers/api/)


## Associated Equinix Metal Costs
Expand Down Expand Up @@ -120,7 +120,7 @@ Here is a quick command plus sample values to start file for you (make sure you
cat <<EOF >terraform.tfvars
auth_token = "cefa5c94-e8ee-4577-bff8-1d1edca93ed8"
organization_id = "42259e34-d300-48b3-b3e1-d5165cd14169"
project_name = "anthos-packet-project-1"
project_name = "anthos-metal-project-1"
cluster_name = "my-first-anthos-cluster"
EOF
```
Expand Down
68 changes: 34 additions & 34 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider "packet" {
provider "metal" {
auth_token = var.auth_token
}

Expand All @@ -8,7 +8,7 @@ resource "random_string" "cluster_suffix" {
upper = false
}

resource "packet_project" "new_project" {
resource "metal_project" "new_project" {
count = var.create_project ? 1 : 0
name = var.project_name
organization_id = var.organization_id
Expand All @@ -23,16 +23,16 @@ locals {
cluster_name = format("%s-%s", var.cluster_name, random_string.cluster_suffix.result)
timestamp = timestamp()
timestamp_sanitized = replace(local.timestamp, "/[- TZ:]/", "")
ssh_key_name = format("bm-cluster-%s", local.timestamp_sanitized)
project_id = var.create_project ? packet_project.new_project[0].id : var.project_id
ssh_key_name = format("anthos-%s-%s", var.cluster_name, random_string.cluster_suffix.result)
project_id = var.create_project ? metal_project.new_project[0].id : var.project_id
}

resource "tls_private_key" "ssh_key_pair" {
algorithm = "RSA"
rsa_bits = 4096
}

resource "packet_ssh_key" "ssh_pub_key" {
resource "metal_ssh_key" "ssh_pub_key" {
name = local.cluster_name
public_key = chomp(tls_private_key.ssh_key_pair.public_key_openssh)
}
Expand All @@ -43,14 +43,14 @@ resource "local_file" "cluster_private_key_pem" {
file_permission = "0600"
}

resource "packet_reserved_ip_block" "cp_vip" {
resource "metal_reserved_ip_block" "cp_vip" {
project_id = local.project_id
facility = var.facility
quantity = 1
description = format("Cluster: '%s' Contol Plane VIP", local.cluster_name)
}

resource "packet_reserved_ip_block" "ingress_vip" {
resource "metal_reserved_ip_block" "ingress_vip" {
project_id = local.project_id
facility = var.facility
quantity = 1
Expand All @@ -64,9 +64,9 @@ data "template_file" "user_data" {
}
}

resource "packet_device" "control_plane" {
resource "metal_device" "control_plane" {
depends_on = [
packet_ssh_key.ssh_pub_key
metal_ssh_key.ssh_pub_key
]
count = local.cp_count
hostname = format("%s-cp-%02d", local.cluster_name, count.index + 1)
Expand All @@ -79,9 +79,9 @@ resource "packet_device" "control_plane" {
tags = ["anthos", "baremetal", "control-plane"]
}

resource "packet_device" "worker_nodes" {
resource "metal_device" "worker_nodes" {
depends_on = [
packet_ssh_key.ssh_pub_key
metal_ssh_key.ssh_pub_key
]
count = var.worker_count
hostname = format("%s-worker-%02d", local.cluster_name, count.index + 1)
Expand All @@ -94,15 +94,15 @@ resource "packet_device" "worker_nodes" {
tags = ["anthos", "baremetal", "worker"]
}

resource "packet_bgp_session" "enable_cp_bgp" {
resource "metal_bgp_session" "enable_cp_bgp" {
count = local.cp_count
device_id = element(packet_device.control_plane.*.id, count.index)
device_id = element(metal_device.control_plane.*.id, count.index)
address_family = "ipv4"
}

resource "packet_bgp_session" "enable_worker_bgp" {
resource "metal_bgp_session" "enable_worker_bgp" {
count = var.worker_count
device_id = element(packet_device.worker_nodes.*.id, count.index)
device_id = element(metal_device.worker_nodes.*.id, count.index)
address_family = "ipv4"
}

Expand All @@ -111,7 +111,7 @@ resource "null_resource" "write_ssh_private_key" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}

provisioner "file" {
Expand All @@ -128,10 +128,10 @@ data "template_file" "deploy_anthos_cluster" {
vars = {
cluster_name = local.cluster_name
operating_system = var.operating_system
cp_vip = cidrhost(packet_reserved_ip_block.cp_vip.cidr_notation, 0)
ingress_vip = cidrhost(packet_reserved_ip_block.ingress_vip.cidr_notation, 0)
cp_ips = join(" ", packet_device.control_plane.*.access_private_ipv4)
worker_ips = join(" ", packet_device.worker_nodes.*.access_private_ipv4)
cp_vip = cidrhost(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
ingress_vip = cidrhost(metal_reserved_ip_block.ingress_vip.cidr_notation, 0)
cp_ips = join(" ", metal_device.control_plane.*.access_private_ipv4)
worker_ips = join(" ", metal_device.worker_nodes.*.access_private_ipv4)
anthos_ver = var.anthos_version
}
}
Expand All @@ -141,7 +141,7 @@ resource "null_resource" "prep_anthos_cluster" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}

provisioner "remote-exec" {
Expand Down Expand Up @@ -182,7 +182,7 @@ resource "null_resource" "deploy_anthos_cluster" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}

provisioner "file" {
Expand All @@ -201,7 +201,7 @@ resource "null_resource" "download_kube_config" {
depends_on = [null_resource.deploy_anthos_cluster]

provisioner "local-exec" {
command = "scp -i ~/.ssh/${local.ssh_key_name} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@${packet_device.control_plane.0.access_public_ipv4}:/root/baremetal/bmctl-workspace/${local.cluster_name}/${local.cluster_name}-kubeconfig ."
command = "scp -i ~/.ssh/${local.ssh_key_name} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@${metal_device.control_plane.0.access_public_ipv4}:/root/baremetal/bmctl-workspace/${local.cluster_name}/${local.cluster_name}-kubeconfig ."
}
}

Expand All @@ -210,7 +210,7 @@ data "template_file" "template_kube_vip_install" {
template = file("templates/kube_vip_install.sh")
vars = {
cluster_name = local.cluster_name
eip = cidrhost(packet_reserved_ip_block.cp_vip.cidr_notation, 0)
eip = cidrhost(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
count = count.index
kube_vip_ver = var.kube_vip_version
auth_token = var.auth_token
Expand All @@ -220,15 +220,15 @@ data "template_file" "template_kube_vip_install" {

resource "null_resource" "kube_vip_install_first_cp" {
depends_on = [
packet_bgp_session.enable_cp_bgp,
packet_bgp_session.enable_worker_bgp,
metal_bgp_session.enable_cp_bgp,
metal_bgp_session.enable_worker_bgp,
null_resource.prep_anthos_cluster,
]
connection {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}
provisioner "file" {
content = data.template_file.template_kube_vip_install.0.rendered
Expand All @@ -247,8 +247,8 @@ data "template_file" "add_remaining_cps" {
template = file("templates/add_remaining_cps.sh")
vars = {
cluster_name = local.cluster_name
cp_2 = packet_device.control_plane.1.access_private_ipv4
cp_3 = packet_device.control_plane.2.access_private_ipv4
cp_2 = metal_device.control_plane.1.access_private_ipv4
cp_3 = metal_device.control_plane.2.access_private_ipv4
}
}

Expand All @@ -262,7 +262,7 @@ resource "null_resource" "add_remaining_cps" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}
provisioner "file" {
content = data.template_file.add_remaining_cps.0.rendered
Expand All @@ -284,7 +284,7 @@ resource "null_resource" "kube_vip_install_remaining_cp" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = element(packet_device.control_plane.*.access_public_ipv4, count.index + 1)
host = element(metal_device.control_plane.*.access_public_ipv4, count.index + 1)
}
provisioner "remote-exec" {
inline = ["mkdir -p /root/bootstrap"]
Expand Down Expand Up @@ -315,7 +315,7 @@ resource "null_resource" "add_kubelet_flags_to_workers" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = element(packet_device.worker_nodes.*.access_public_ipv4, count.index)
host = element(metal_device.worker_nodes.*.access_public_ipv4, count.index)
}
provisioner "remote-exec" {
inline = [
Expand Down Expand Up @@ -349,7 +349,7 @@ resource "null_resource" "install_ccm" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}
provisioner "file" {
content = data.template_file.ccm_secret.rendered
Expand All @@ -375,7 +375,7 @@ resource "null_resource" "install_kube_vip_daemonset" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = packet_device.control_plane.0.access_public_ipv4
host = metal_device.control_plane.0.access_public_ipv4
}
provisioner "file" {
content = data.template_file.kube_vip_ds.rendered
Expand Down
8 changes: 4 additions & 4 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
output "Control_Plane_Public_IPs" {
value = packet_device.control_plane.*.access_public_ipv4
value = metal_device.control_plane.*.access_public_ipv4
description = "Control Plane Public IPs"
}

output "Worker_Public_IPs" {
value = packet_device.worker_nodes.*.access_public_ipv4
value = metal_device.worker_nodes.*.access_public_ipv4
description = "Worker Node Public IPs"
}

Expand All @@ -14,12 +14,12 @@ output "ssh_key_location" {
}

output "Control_Plane_VIP" {
value = cidrhost(packet_reserved_ip_block.cp_vip.cidr_notation, 0)
value = cidrhost(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
description = "The Virtual IP for the Control Plane"
}

output "Ingress_VIP" {
value = cidrhost(packet_reserved_ip_block.ingress_vip.cidr_notation, 0)
value = cidrhost(metal_reserved_ip_block.ingress_vip.cidr_notation, 0)
description = "The Virtual IP for Ingress"
}

Expand Down
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ terraform {
null = {
source = "hashicorp/null"
}
packet = {
source = "packethost/packet"
metal = {
source = "equinix/metal"
}
random = {
source = "hashicorp/random"
Expand Down

0 comments on commit c5479ef

Please sign in to comment.