Skip to content

Commit

Permalink
provide type definition for variables, give project_name a default value
Browse files Browse the repository at this point in the history
  • Loading branch information
glovecchi0 authored and displague committed Sep 12, 2024
1 parent c55c4f8 commit ec5b209
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data "equinix_metal_project" "project" {

data "equinix_metal_ip_block_ranges" "address_block" {
project_id = local.project_id
metro = (var.spot_instance && var.use_cheapest_metro) ? local.cheapest_metro_price.metro : var.metro
metro = (var.spot_instance && var.use_cheapest_metro && local.cheapest_metro_price != null) ? local.cheapest_metro_price.metro : var.metro
}


Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project[0].project_id
metro = (var.spot_instance && var.use_cheapest_metro) ? local.cheapest_metro_price.metro : lower(var.metro)
metro = (var.spot_instance && var.use_cheapest_metro && local.cheapest_metro_price != null) ? local.cheapest_metro_price.metro : lower(var.metro)
}

// IP attachment to be added to seed node, and this is subsequently assigned as Harvester vip
Expand Down Expand Up @@ -65,7 +65,7 @@ resource "equinix_metal_device" "seed" {
resource "equinix_metal_spot_market_request" "seed_spot_request" {
count = var.node_count >= 1 && var.spot_instance ? 1 : 0
project_id = local.project_id
max_bid_price = var.use_cheapest_metro ? local.cheapest_metro_price.price : var.max_bid_price
max_bid_price = (var.use_cheapest_metro && local.cheapest_metro_price != null) ? local.cheapest_metro_price.price : var.max_bid_price
metro = local.metro
devices_min = 1
devices_max = 1
Expand Down Expand Up @@ -103,7 +103,7 @@ resource "equinix_metal_device" "join" {
resource "equinix_metal_spot_market_request" "join_spot_request" {
count = var.spot_instance ? var.node_count - 1 : 0
project_id = local.project_id
max_bid_price = var.use_cheapest_metro ? local.cheapest_metro_price.price : var.max_bid_price
max_bid_price = (var.use_cheapest_metro && local.cheapest_metro_price != null) ? local.cheapest_metro_price.price : var.max_bid_price
metro = local.metro
devices_min = 1
devices_max = 1
Expand Down Expand Up @@ -152,4 +152,4 @@ resource "local_file" "harvester_kubeconfig" {
count = var.rancher_api_url != "" ? 1 : 0
content = rancher2_cluster.rancher_cluster[0].kube_config
filename = "${var.hostname_prefix}-kubeconfig.yaml"
}
}
55 changes: 37 additions & 18 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,106 +1,125 @@
variable "harvester_version" {
type = string
default = "v1.3.1"
description = "Harvester version to be installed (Must be a valid version tag from https://github.com/rancherlabs/terraform-harvester-equinix/tree/main/ipxe)"
}

variable "node_count" {
default = "3"
type = number
default = 3
description = "Number of nodes to deploy Harvester cluster"
}

variable "project_name" {
default = ""
type = string
default = "Harvester Labs"
description = "Name of the Equinix Metal project to deploy into, when not looking up by project_id"
}

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

variable "organization_id" {
description = "Equinix Metal organization ID to create or find a project in"
type = string
default = ""
description = "Equinix Metal organization ID to create or find a project in"
}

variable "project_id" {
description = "Equinix Metal project ID to deploy into, if not creating a new project or looking up by name"
type = string
default = ""
}

variable "metal_create_project" {
type = bool
default = false
description = "Create a Metal Project if this is 'true'. Else use provided 'project_name'"
description = "Equinix Metal project ID to deploy into, if not creating a new project or looking up by name"
}

variable "plan" {
default = "c3.small.x86"
type = string
default = "m3.small.x86"
description = "Size of the servers to be deployed on Equinix metal (https://deploy.equinix.com/developers/docs/metal/hardware/standard-servers/)"
}

variable "billing_cycle" {
default = "hourly"
description = "Equinix metal billing/invoice generation schedule (hourly/daily/monthly/yearly)"
type = string
default = "hourly"
}

variable "metro" {
type = string
default = "SG"
description = "Equinix metal data center location (https://deploy.equinix.com/developers/docs/metal/locations/metros/). Examples: SG,SV,AM,MA,Ny,LA,etc."
}

variable "ipxe_script" {
type = string
default = "https://raw.githubusercontent.com/rancherlabs/terraform-harvester-equinix/main/ipxe/ipxe-"
description = "URL to the iPXE script to use for booting the server (harvester_version will be appended to this without the 'v' prefix)"
}

variable "hostname_prefix" {
type = string
default = "harvester-pxe"
description = "Prefix for resources to be created in equinix metal"
}

variable "spot_instance" {
default = false
type = bool
default = true
description = "Set to true to use spot instance instead of on demand. Also set your max bid price if true."
}

variable "max_bid_price" {
default = "0.00"
description = "Maximum bid price for spot request."
type = string
default = "0.75"
description = "Maximum bid price for spot request"
}

variable "ssh_key" {
type = string
default = ""
description = "Your ssh key, examples: 'github: myghid' or 'ssh-rsa AAAAblahblah== keyname'"
}

variable "num_of_vlans" {
default = 0
type = number
default = 2
description = "Number of VLANs to be created"
}

variable "rancher_api_url" {
type = string
default = ""
description = "Rancher API endpoint to manager your Harvester cluster"
}

variable "rancher_access_key" {
type = string
default = ""
description = "Rancher access key"
}

variable "rancher_secret_key" {
type = string
default = ""
description = "Rancher secret key"
}

variable "rancher_insecure" {
type = bool
default = false
description = "Allow insecure connections to the Rancher API"
}

variable "api_key" {
type = string
default = ""
description = "Equinix Metal authentication token"
description = "Equinix Metal authentication token. Required when using Spot Instances for HTTP pricing lookups. METAL_AUTH_TOKEN should always be set as an environment variable"
}

variable "use_cheapest_metro" {
type = bool
default = true
description = "Equinix Metal authentication token. Required when using Spot Instances for HTTP pricing lookups. METAL_AUTH_TOKEN should always be set as an environment variable."
description = "A boolean variable to control cheapest metro selection"
}

0 comments on commit ec5b209

Please sign in to comment.