Skip to content

Commit

Permalink
Merge pull request #88 from vasubabu/vk_module_name
Browse files Browse the repository at this point in the history
Add provider meta module_name in Equinix Metal TF configs
  • Loading branch information
ctreatma authored May 8, 2023
2 parents 1fac092 + b1dec5d commit faae3cd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 59 deletions.
90 changes: 45 additions & 45 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "metal" {
auth_token = var.metal_auth_token
provider "equinix" {
auth_token = var.equinix_metal_auth_token
}

provider "google" {
Expand All @@ -12,10 +12,10 @@ resource "random_string" "cluster_suffix" {
upper = false
}

resource "metal_project" "new_project" {
count = var.metal_create_project ? 1 : 0
name = var.metal_project_name
organization_id = var.metal_organization_id
resource "equinix_metal_project" "new_project" {
count = var.equinix_metal_create_project ? 1 : 0
name = var.equinix_metal_project_name
organization_id = var.equinix_metal_organization_id
bgp_config {
deployment_type = "local"
asn = var.bgp_asn
Expand All @@ -28,7 +28,7 @@ locals {
timestamp = timestamp()
timestamp_sanitized = replace(local.timestamp, "/[- TZ:]/", "")
ssh_key_name = format("anthos-%s-%s", var.cluster_name, random_string.cluster_suffix.result)
metal_project_id = var.metal_create_project ? metal_project.new_project[0].id : var.metal_project_id
metal_project_id = var.equinix_metal_create_project ? equinix_metal_project.new_project[0].id : var.equinix_metal_project_id
gcr_sa_key = var.gcp_keys_path == "" ? base64decode(google_service_account_key.gcr_sa_key[0].private_key) : file("${var.gcp_keys_path}/gcr.json")
connect_sa_key = var.gcp_keys_path == "" ? base64decode(google_service_account_key.connect_sa_key[0].private_key) : file("${var.gcp_keys_path}/connect.json")
register_sa_key = var.gcp_keys_path == "" ? base64decode(google_service_account_key.register_sa_key[0].private_key) : file("${var.gcp_keys_path}/register.json")
Expand All @@ -42,7 +42,7 @@ resource "tls_private_key" "ssh_key_pair" {
rsa_bits = 4096
}

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

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

resource "metal_reserved_ip_block" "ingress_vip" {
resource "equinix_metal_reserved_ip_block" "ingress_vip" {
project_id = local.metal_project_id
metro = var.metro
quantity = 1
Expand Down Expand Up @@ -94,15 +94,15 @@ data "cloudinit_config" "cp_user_data" {

kube_vip_install = templatefile("${path.module}/templates/kube_vip_install.sh", {
cluster_name = local.cluster_name
eip = cidrhost(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
eip = cidrhost(equinix_metal_reserved_ip_block.cp_vip.cidr_notation, 0)
count = 0
kube_vip_ver = var.kube_vip_version
auth_token = var.metal_auth_token
auth_token = var.equinix_metal_auth_token
project_id = local.metal_project_id
})

ccm_secret = templatefile("${path.module}/templates/ccm_secret.yaml", {
auth_token = var.metal_auth_token
auth_token = var.equinix_metal_auth_token
project_id = local.metal_project_id
})
})
Expand All @@ -126,9 +126,9 @@ data "cloudinit_config" "worker_user_data" {
}


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

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

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

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

Expand All @@ -177,20 +177,20 @@ resource "null_resource" "prep_anthos_cluster" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
}


provisioner "file" {
content = templatefile("${path.module}/templates/pre_reqs.sh", {
cluster_name = local.cluster_name
operating_system = var.operating_system
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)
cp_ids = join(" ", metal_device.control_plane.*.id)
worker_ips = join(" ", metal_device.worker_nodes.*.access_private_ipv4)
worker_ids = join(" ", metal_device.worker_nodes.*.id)
cp_vip = cidrhost(equinix_metal_reserved_ip_block.cp_vip.cidr_notation, 0)
ingress_vip = cidrhost(equinix_metal_reserved_ip_block.ingress_vip.cidr_notation, 0)
cp_ips = join(" ", equinix_metal_device.control_plane.*.access_private_ipv4)
cp_ids = join(" ", equinix_metal_device.control_plane.*.id)
worker_ips = join(" ", equinix_metal_device.worker_nodes.*.access_private_ipv4)
worker_ids = join(" ", equinix_metal_device.worker_nodes.*.id)
anthos_ver = var.anthos_version
})
destination = "/root/bootstrap/pre_reqs.sh"
Expand All @@ -212,7 +212,7 @@ resource "null_resource" "deploy_anthos_cluster" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
}
provisioner "remote-exec" {
inline = [
Expand All @@ -225,21 +225,21 @@ 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@${metal_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@${equinix_metal_device.control_plane.0.access_public_ipv4}:/root/baremetal/bmctl-workspace/${local.cluster_name}/${local.cluster_name}-kubeconfig ."
}
}

resource "null_resource" "kube_vip_install_first_cp" {
depends_on = [
metal_bgp_session.enable_cp_bgp,
metal_bgp_session.enable_worker_bgp,
equinix_metal_bgp_session.enable_cp_bgp,
equinix_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 = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
}
provisioner "remote-exec" {
inline = [
Expand All @@ -258,16 +258,16 @@ resource "null_resource" "add_remaining_cps" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
}

provisioner "file" {
content = templatefile("${path.module}/templates/add_remaining_cps.sh", {
cluster_name = local.cluster_name
cp_ip_2 = metal_device.control_plane.1.access_private_ipv4
cp_id_2 = metal_device.control_plane.1.id
cp_ip_3 = metal_device.control_plane.2.access_private_ipv4
cp_id_3 = metal_device.control_plane.2.id
cp_ip_2 = equinix_metal_device.control_plane.1.access_private_ipv4
cp_id_2 = equinix_metal_device.control_plane.1.id
cp_ip_3 = equinix_metal_device.control_plane.2.access_private_ipv4
cp_id_3 = equinix_metal_device.control_plane.2.id
})
destination = "/root/bootstrap/add_remaining_cps.sh"
}
Expand All @@ -287,18 +287,18 @@ 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(metal_device.control_plane.*.access_public_ipv4, count.index + 1)
host = element(equinix_metal_device.control_plane.*.access_public_ipv4, count.index + 1)
}
provisioner "remote-exec" {
inline = ["mkdir -p /root/bootstrap"]
}
provisioner "file" {
content = templatefile("${path.module}/templates/kube_vip_install.sh", {
cluster_name = local.cluster_name
eip = cidrhost(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
eip = cidrhost(equinix_metal_reserved_ip_block.cp_vip.cidr_notation, 0)
count = 1
kube_vip_ver = var.kube_vip_version
auth_token = var.metal_auth_token
auth_token = var.equinix_metal_auth_token
project_id = local.metal_project_id
})

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

provisioner "remote-exec" {
Expand All @@ -340,7 +340,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 = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
}
provisioner "file" {
content = templatefile("${path.module}/templates/kube_vip_ds.yaml", {
Expand All @@ -363,11 +363,11 @@ module "storage" {
]

ssh = {
host = metal_device.control_plane.0.access_public_ipv4
host = equinix_metal_device.control_plane.0.access_public_ipv4
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
user = "root"
kubeconfig = "/root/baremetal/bmctl-workspace/${local.cluster_name}/${local.cluster_name}-kubeconfig"
worker_addresses = metal_device.worker_nodes.*.access_public_ipv4
worker_addresses = equinix_metal_device.worker_nodes.*.access_public_ipv4
}

cluster_name = local.cluster_name
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 = metal_device.control_plane.*.access_public_ipv4
value = equinix_metal_device.control_plane.*.access_public_ipv4
description = "Control Plane Public IPs"
}

output "Worker_Public_IPs" {
value = metal_device.worker_nodes.*.access_public_ipv4
value = equinix_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(metal_reserved_ip_block.cp_vip.cidr_notation, 0)
value = cidrhost(equinix_metal_reserved_ip_block.cp_vip.cidr_notation, 0)
description = "The Virtual IP for the Control Plane"
}

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

Expand Down
2 changes: 1 addition & 1 deletion util/test_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ "$1" = "apply" ]; then
for os in "${operating_systems[@]}"; do
mkdir -p $os
short_name=`echo $os |sed "s/_//g"`
nohup terraform apply --auto-approve -state="./$os/terraform.tfstate" -var "operating_system=$os" -var "facility=sv15" -var "plan=c3.small.x86" -var "hostname=$short_name-anothos-baermetal" > ./$os/terraform.log &
nohup terraform apply --auto-approve -state="./$os/terraform.tfstate" -var "operating_system=$os" -var "metro=da" -var "plan=c3.small.x86" -var "hostname=$short_name-anothos-baermetal" > ./$os/terraform.log &
done
elif [ "$1" = "destroy" ]; then
for os in "${operating_systems[@]}"; do
Expand Down
12 changes: 6 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
variable "metal_auth_token" {
variable "equinix_metal_auth_token" {
type = string
description = "Equinix Metal API Key"
}

variable "metal_project_id" {
variable "equinix_metal_project_id" {
type = string
default = "null"
description = "Equinix Metal Project ID"
}

variable "metal_organization_id" {
variable "equinix_metal_organization_id" {
type = string
default = "null"
description = "Equinix Metal Organization ID"
Expand Down Expand Up @@ -73,13 +73,13 @@ variable "cluster_name" {
}
}

variable "metal_create_project" {
variable "equinix_metal_create_project" {
type = bool
default = true
description = "Create a Metal Project if this is 'true'. Else use provided 'metal_project_id'"
description = "Create a Metal Project if this is 'true'. Else use provided 'equinix_metal_project_id'"
}

variable "metal_project_name" {
variable "equinix_metal_project_name" {
type = string
default = "baremetal-anthos"
description = "The name of the Metal project if 'create_project' is 'true'."
Expand Down
9 changes: 6 additions & 3 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ terraform {
null = {
source = "hashicorp/null"
}
metal = {
source = "equinix/metal"
equinix = {
source = "equinix/equinix"
version = "~> 1.14"
}
random = {
source = "hashicorp/random"
Expand All @@ -23,5 +24,7 @@ terraform {
version = "~>3.53.0"
}
}
required_version = ">= 0.13"
provider_meta "equinix" {
module_name = "equinix-metal-anthos-on-baremetal"
}
}

0 comments on commit faae3cd

Please sign in to comment.