diff --git a/data.tf b/data.tf index e37de65..b6a4a2b 100644 --- a/data.tf +++ b/data.tf @@ -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 } diff --git a/main.tf b/main.tf index 4091181..ad53aa9 100644 --- a/main.tf +++ b/main.tf @@ -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 @@ -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 @@ -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 @@ -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" -} +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 8ff5bee..4cf9fd3 100644 --- a/variables.tf +++ b/variables.tf @@ -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" }