Skip to content

Commit

Permalink
Updates module to use project name rather than ID, creates if does no…
Browse files Browse the repository at this point in the history
…t exist, references it via datasource if it does.

Signed-off-by: Joseph Marhee <[email protected]>
  • Loading branch information
jmarhee committed Mar 21, 2024
1 parent c1594ee commit ee9dd02
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module "multiarch-k8s" {
# version = "0.5.0" # Use the latest version, according to https://github.com/equinix/terraform-metal-multiarch-k8s/releases

auth_token = var.auth_token
project_id = var.project_id
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project.project_id
metro = var.metro
count_arm = var.count_arm
count_x86 = var.count_x86
Expand Down
4 changes: 2 additions & 2 deletions kubernetes-controller-pool.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource "equinix_metal_ssh_key" "kubernetes-on-metal" {
}

resource "equinix_metal_reserved_ip_block" "kubernetes" {
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : var.project_id
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project.project_id
metro = var.metro != "" ? var.metro : null
quantity = 4
}
Expand All @@ -45,7 +45,7 @@ module "controllers" {
metro = var.metro
cluster_name = var.cluster_name
kubernetes_lb_block = equinix_metal_reserved_ip_block.kubernetes.cidr_notation
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : var.project_id
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project.project_id
auth_token = var.auth_token
secrets_encryption = var.secrets_encryption
configure_ingress = var.configure_ingress
Expand Down
4 changes: 2 additions & 2 deletions kubernetes-node-pool.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module "node_pool_blue" {
metro = var.metro
cluster_name = var.cluster_name
controller_address = module.controllers.controller_addresses
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : var.project_id
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project.project_id
storage = var.storage
ccm_enabled = var.ccm_enabled

Expand All @@ -28,7 +28,7 @@ module "node_pool_gpu_green" {
metro = var.metro
cluster_name = var.cluster_name
controller_address = module.controllers.controller_addresses
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : var.project_id
project_id = var.metal_create_project ? equinix_metal_project.new_project[0].id : data.equinix_metal_project.project.project_id
storage = var.storage
ccm_enabled = var.ccm_enabled
}
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ resource "equinix_metal_project" "new_project" {
asn = 65000
}
}

data "equinix_metal_project" "project" {
name = var.metal_create_project ? equinix_metal_project.new_project[0].name : var.project_name
}
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ variable "metro" {
default = "dc"
}

variable "project_id" {
variable "project_name" {
type = string
default = "null"
description = "Equinix Metal Project ID"
description = "Equinix Metal Project name"
}

variable "metal_create_project" {
Expand Down

0 comments on commit ee9dd02

Please sign in to comment.