Skip to content

Commit

Permalink
Add provider equinix, module_name for TF configs
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed May 10, 2023
1 parent 042ed52 commit 7f9ba65
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 35 deletions.
11 changes: 5 additions & 6 deletions 02-master-nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ data "template_file" "master_bootstrap" {
}
}

resource "metal_device" "k8s_masters" {
resource "equinix_metal_device" "k8s_masters" {
depends_on = [
metal_ssh_key.ssh_pub_key
equinix_metal_ssh_key.ssh_pub_key
]
count = var.master_count
hostname = format("%s-master%02d", var.cluster_name, count.index + 1)
plan = var.master_size
facilities = [var.facility]
operating_system = var.operating_system
billing_cycle = var.billing_cycle
project_id = metal_project.new_project.id
project_id = equinix_metal_project.new_project.id
user_data = data.template_file.master_bootstrap.rendered
}

resource "metal_bgp_session" "master_bgp_session" {
resource "equinix_metal_bgp_session" "master_bgp_session" {
count = var.master_count
device_id = element(metal_device.k8s_masters.*.id, count.index)
device_id = element(equinix_metal_device.k8s_masters.*.id, count.index)
address_family = "ipv4"
}

11 changes: 5 additions & 6 deletions 03-worker-nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ data "template_file" "worker_bootstrap" {
}
}

resource "metal_device" "k8s_workers" {
resource "equinix_metal_device" "k8s_workers" {
depends_on = [
metal_ssh_key.ssh_pub_key
equinix_metal_ssh_key.ssh_pub_key
]
count = var.worker_count
hostname = format("%s-worker%02d", var.cluster_name, count.index + 1)
plan = var.worker_size
facilities = [var.facility]
operating_system = var.operating_system
billing_cycle = var.billing_cycle
project_id = metal_project.new_project.id
project_id = equinix_metal_project.new_project.id
user_data = data.template_file.worker_bootstrap.rendered
}

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

8 changes: 4 additions & 4 deletions 04-configure-bgp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ data "template_file" "bird_conf" {
template = file("templates/bird_conf.sh")

vars = {
floating_ip = metal_reserved_ip_block.cluster_ip.address
floating_cidr = metal_reserved_ip_block.cluster_ip.cidr
floating_netmask = metal_reserved_ip_block.cluster_ip.netmask
floating_ip = equinix_metal_reserved_ip_block.cluster_ip.address
floating_cidr = equinix_metal_reserved_ip_block.cluster_ip.cidr
floating_netmask = equinix_metal_reserved_ip_block.cluster_ip.netmask
}
}

Expand All @@ -14,7 +14,7 @@ resource "null_resource" "configure_bird" {
type = "ssh"
user = "root"
private_key = chomp(tls_private_key.ssh_key_pair.private_key_pem)
host = element(metal_device.k8s_masters.*.access_public_ipv4, count.index)
host = element(equinix_metal_device.k8s_masters.*.access_public_ipv4, count.index)
}

provisioner "file" {
Expand Down
10 changes: 5 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "metal" {
auth_token = var.metal_api_key
provider "equinix" {
auth_token = var.equinix_metal_api_key
}

resource "random_string" "bgp_password" {
Expand All @@ -13,9 +13,9 @@ resource "random_string" "bgp_password" {
special = false
}

resource "metal_project" "new_project" {
resource "equinix_metal_project" "new_project" {
name = var.project_name
organization_id = var.metal_org_id
organization_id = var.equinix_metal_org_id
bgp_config {
deployment_type = "local"
md5 = random_string.bgp_password.result
Expand All @@ -28,7 +28,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 = var.project_name
public_key = chomp(tls_private_key.ssh_key_pair.public_key_openssh)
}
Expand Down
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "Master_IPs" {
value = metal_device.k8s_masters.*.access_public_ipv4
value = equinix_metal_device.k8s_masters.*.access_public_ipv4
}

output "Worker_IPs" {
value = metal_device.k8s_workers.*.access_public_ipv4
value = equinix_metal_device.k8s_workers.*.access_public_ipv4
}

output "Master_LB_IP" {
value = metal_reserved_ip_block.cluster_ip.address
}
value = equinix_metal_reserved_ip_block.cluster_ip.address
}
9 changes: 2 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###############################


variable "metal_api_key" {
variable "equinix_metal_api_key" {
description = "Equinix Metal API Key"
}

Expand All @@ -17,7 +17,7 @@ variable "project_name" {
default = "platform9-on-equinix-metal"
}

variable "metal_org_id" {
variable "equinix_metal_org_id" {
description = "Equinix Metal Organization ID (found on the General tab of the Organizations Settings page)"
}

Expand All @@ -36,11 +36,6 @@ variable "worker_size" {
default = "c3.small.x86"
}

variable "facility" {
description = "Equinix Metal facility for all device nodes"
default = "sv15"
}

variable "operating_system" {
description = "Operating System to be deployed on Equinix Metal device nodes"
default = "ubuntu_18_04"
Expand Down
11 changes: 8 additions & 3 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
terraform {
required_providers {
metal = {
source = "equinix/metal"
version = "<= 4.0.0"
equinix = {
source = "equinix/equinix"
version = "~> 1.14"
}
}
required_version = ">= 0.13"

provider_meta "equinix" {
module_name = "equinix-metal-platform9-k8s"
}
}

0 comments on commit 7f9ba65

Please sign in to comment.