Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-1451: Added network related setting in machine_pool for edge-native cluster #528

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ resource "spectrocloud_cluster_edge_native" "cluster" {
edge_host {
host_uid = spectrocloud_appliance.appliance1.uid
static_ip = "1.2.3.4"
dns_servers = ["tf.test.com"]
host_name = "test-test"
nic_name = "auto160"
static_ip = "112.21.12.21"
subnet_mask = "2.2.1.0"
}
}

Expand Down Expand Up @@ -152,8 +157,12 @@ Required:

Optional:

- `default_gateway` (String) Edge host default gateway
- `dns_servers` (Set of String) Edge host DNS servers
- `host_name` (String) Edge host name
- `static_ip` (String) Edge host static IP
- `nic_name` (String) NIC Name for edge host.
- `static_ip` (String) Edge host static IP address
- `subnet_mask` (String) Edge host subnet mask
- `two_node_role` (String) Two node role for edge host. Valid values are `primary` and `secondary`.


Expand Down
14 changes: 14 additions & 0 deletions examples/resources/spectrocloud_cluster_edge_native/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.1"
source = "spectrocloud/spectrocloud"
}
}
}

provider "spectrocloud" {
host = var.sc_host
api_key = var.sc_api_key
project_name = var.sc_project_name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "spectrocloud_cluster_edge_native" "cluster" {
name = "ran-edge-tf"

cluster_profile {
id = "test-profile-id"
}

cloud_config {
ssh_keys = ["spectro2023"]
vip = "10.10.232.57"
# overlay_cidr_range = "100.64.192.0/23"
}

machine_pool {
control_plane = true
control_plane_as_worker = true
name = "cp-pool"

edge_host {
host_uid = "edge-fsdsdedadfasdtest"
static_ip = "10.10.32.12"
default_gateway = "10.10.12.1"
dns_servers = ["tf.test.com"]
host_name = "test-test"
nic_name = "auto162"
subnet_mask = "255.255.12.0"
}
}

machine_pool {
name = "wp-pool"

edge_host {
host_uid = "edge-bef8384adfasdtest"
default_gateway = "10.10.12.1"
dns_servers = ["tf.test.com"]
host_name = "test-test"
nic_name = "auto160"
static_ip = "10.10.132449.22"
subnet_mask = "255.255.92.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Spectro Cloud credentials
sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS)
sc_api_key = "{Enter Spectro Cloud API Key}"
sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default
13 changes: 13 additions & 0 deletions examples/resources/spectrocloud_cluster_edge_native/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "sc_host" {
description = "Spectro Cloud Endpoint"
default = "api.spectrocloud.com"
}

variable "sc_api_key" {
description = "Spectro Cloud API key"
}

variable "sc_project_name" {
description = "Spectro Cloud Project (e.g: Default)"
default = "Default"
}
66 changes: 59 additions & 7 deletions spectrocloud/resource_cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,33 @@ func resourceClusterEdgeNative() *schema.Resource {
},
"static_ip": {
Type: schema.TypeString,
Description: "Edge host static IP",
Description: "Edge host static IP address",
Optional: true,
},
"nic_name": {
Type: schema.TypeString,
Description: "NIC Name for edge host.",
Optional: true,
},
"default_gateway": {
Type: schema.TypeString,
Description: "Edge host default gateway",
Optional: true,
},
"subnet_mask": {
Type: schema.TypeString,
Description: "Edge host subnet mask",
Optional: true,
},
"dns_servers": {
Type: schema.TypeSet,
Optional: true,
Set: schema.HashString,
Description: "Edge host DNS servers",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"two_node_role": {
Type: schema.TypeString,
Description: "Two node role for edge host. Valid values are `primary` and `secondary`.",
Expand Down Expand Up @@ -418,12 +442,16 @@ func flattenMachinePoolConfigsEdgeNative(machinePools []*models.V1EdgeNativeMach
oi["control_plane_as_worker"] = machinePool.UseControlPlaneAsWorker
oi["name"] = machinePool.Name

var hosts []map[string]string
var hosts []map[string]interface{}
for _, host := range machinePool.Hosts {
rawHost := map[string]string{
"host_name": host.HostName,
"host_uid": *host.HostUID,
"static_ip": host.StaticIP,
rawHost := map[string]interface{}{
"host_name": host.HostName,
"host_uid": *host.HostUID,
"static_ip": host.Nic.IP,
"nic_name": host.Nic.NicName,
"default_gateway": host.Nic.Gateway,
"subnet_mask": host.Nic.Subnet,
"dns_servers": host.Nic.DNS,
}
if host.TwoNodeCandidatePriority != "" {
rawHost["two_node_role"] = host.TwoNodeCandidatePriority
Expand Down Expand Up @@ -694,8 +722,32 @@ func toEdgeHosts(m map[string]interface{}) (*models.V1EdgeNativeMachinePoolCloud
edgeHost := &models.V1EdgeNativeMachinePoolHostEntity{
HostName: hostName,
HostUID: &hostId,
StaticIP: host.(map[string]interface{})["static_ip"].(string),
Nic: &models.V1Nic{},
// Hubble deprecated it and need to set it inside nic
// StaticIP: host.(map[string]interface{})["static_ip"].(string),
}
if v, ok := host.(map[string]interface{})["dns_servers"].(*schema.Set); ok {
if v.Len() > 0 {
var result []string
for _, val := range v.List() {
result = append(result, val.(string)) // Type assertion
}
edgeHost.Nic.DNS = result
}
}
if v, ok := host.(map[string]interface{})["default_gateway"]; ok {
edgeHost.Nic.Gateway = v.(string)
}
if v, ok := host.(map[string]interface{})["static_ip"]; ok {
edgeHost.Nic.IP = v.(string)
}
if v, ok := host.(map[string]interface{})["nic_name"]; ok {
edgeHost.Nic.NicName = v.(string)
}
if v, ok := host.(map[string]interface{})["subnet_mask"]; ok {
edgeHost.Nic.Subnet = v.(string)
}

if v, ok := host.(map[string]interface{})["two_node_role"].(string); ok {
if v != "" {
if _, ok := twoNodeHostRoles[v]; ok {
Expand Down
Loading
Loading