diff --git a/docs/resources/cluster_vsphere.md b/docs/resources/cluster_vsphere.md index 1dd92466..5b194726 100644 --- a/docs/resources/cluster_vsphere.md +++ b/docs/resources/cluster_vsphere.md @@ -65,6 +65,7 @@ Required: Optional: +- `host_endpoint` (String) The host endpoint to use for the cluster. This can be `IP` or `FQDN(External/DDNS)`. - `image_template_folder` (String) The name of the image template folder in vSphere. This is the name of the folder as it appears in vSphere. - `network_search_domain` (String) The search domain to use for the cluster in case of DHCP. - `network_type` (String) The type of network to use for the cluster. This can be `VIP` or `DDNS`. diff --git a/spectrocloud/resource_cluster_edge_vsphere.go b/spectrocloud/resource_cluster_edge_vsphere.go index c87439fa..5c3d489f 100644 --- a/spectrocloud/resource_cluster_edge_vsphere.go +++ b/spectrocloud/resource_cluster_edge_vsphere.go @@ -577,17 +577,6 @@ func toEdgeVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V return cluster, nil } -func getSSHKey(cloudConfig map[string]interface{}) []string { - - sshKeys, _ := toSSHKeys(cloudConfig) - return sshKeys -} - -func getStaticIP(cloudConfig map[string]interface{}) bool { - staticIP := cloudConfig["static_ip"].(bool) - return staticIP -} - func getImageTemplateFolder(cloudConfig map[string]interface{}) string { imageTemplateFolder := "spectro-templates" if cloudConfig["image_template_folder"] != nil { @@ -596,20 +585,6 @@ func getImageTemplateFolder(cloudConfig map[string]interface{}) string { return imageTemplateFolder } -func getClusterConfigEntity(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity { - clusterConfigEntity := &models.V1VsphereClusterConfigEntity{ - NtpServers: toNtpServers(cloudConfig), - Placement: &models.V1VspherePlacementConfigEntity{ - Datacenter: cloudConfig["datacenter"].(string), - Folder: cloudConfig["folder"].(string), - ImageTemplateFolder: getImageTemplateFolder(cloudConfig), - }, - SSHKeys: getSSHKey(cloudConfig), - StaticIP: getStaticIP(cloudConfig), - } - return clusterConfigEntity -} - func toMachinePoolEdgeVsphere(machinePool interface{}) (*models.V1VsphereMachinePoolConfigEntity, error) { m := machinePool.(map[string]interface{}) diff --git a/spectrocloud/resource_cluster_vsphere.go b/spectrocloud/resource_cluster_vsphere.go index 887cb3af..d0da8cec 100644 --- a/spectrocloud/resource_cluster_vsphere.go +++ b/spectrocloud/resource_cluster_vsphere.go @@ -188,6 +188,11 @@ func resourceClusterVsphere() *schema.Resource { Optional: true, Description: "The type of network to use for the cluster. This can be `VIP` or `DDNS`.", }, + "host_endpoint": { + Type: schema.TypeString, + Optional: true, + Description: "The host endpoint to use for the cluster. This can be `IP` or `FQDN(External/DDNS)`.", + }, "network_search_domain": { Type: schema.TypeString, Optional: true, @@ -488,6 +493,9 @@ func flattenClusterConfigsVsphere(d *schema.ResourceData, cloudConfig *models.V1 if cpEndpoint.DdnsSearchDomain != "" { ret["network_search_domain"] = cpEndpoint.DdnsSearchDomain } + if cpEndpoint.Host != "" { + ret["host_endpoint"] = cpEndpoint.Host + } } //Setting up placement attributes if its defined if cloudConfig.Spec.ClusterConfig.Placement != nil { @@ -812,15 +820,12 @@ func toVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe } func toCloudConfigCreate(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity { - staticIP := cloudConfig["static_ip"].(bool) V1VsphereClusterConfigEntity := getClusterConfigEntity(cloudConfig) - - if !staticIP { - V1VsphereClusterConfigEntity.ControlPlaneEndpoint = &models.V1ControlPlaneEndPoint{ - DdnsSearchDomain: cloudConfig["network_search_domain"].(string), - Type: cloudConfig["network_type"].(string), - } + V1VsphereClusterConfigEntity.ControlPlaneEndpoint = &models.V1ControlPlaneEndPoint{ + DdnsSearchDomain: cloudConfig["network_search_domain"].(string), + Type: cloudConfig["network_type"].(string), + Host: cloudConfig["host_endpoint"].(string), } return V1VsphereClusterConfigEntity @@ -920,3 +925,28 @@ func toMachinePoolVsphere(machinePool interface{}) (*models.V1VsphereMachinePool return mp, nil } + +func getSSHKey(cloudConfig map[string]interface{}) []string { + + sshKeys, _ := toSSHKeys(cloudConfig) + return sshKeys +} + +func getStaticIP(cloudConfig map[string]interface{}) bool { + staticIP := cloudConfig["static_ip"].(bool) + return staticIP +} + +func getClusterConfigEntity(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity { + clusterConfigEntity := &models.V1VsphereClusterConfigEntity{ + NtpServers: toNtpServers(cloudConfig), + Placement: &models.V1VspherePlacementConfigEntity{ + Datacenter: cloudConfig["datacenter"].(string), + Folder: cloudConfig["folder"].(string), + ImageTemplateFolder: getImageTemplateFolder(cloudConfig), + }, + SSHKeys: getSSHKey(cloudConfig), + StaticIP: getStaticIP(cloudConfig), + } + return clusterConfigEntity +} diff --git a/spectrocloud/resource_cluster_vsphere_test.go b/spectrocloud/resource_cluster_vsphere_test.go index 6cc47ae7..c2e1fe58 100644 --- a/spectrocloud/resource_cluster_vsphere_test.go +++ b/spectrocloud/resource_cluster_vsphere_test.go @@ -106,6 +106,7 @@ func TestToCloudConfigUpdate(t *testing.T) { "datacenter": "Datacenter", "folder": "sc_test/terraform", "network_type": "DDNS", + "host_endpoint": "tt.tt.test.com", "network_search_domain": "spectrocloud.dev", "static_ip": false, } @@ -116,6 +117,7 @@ func TestToCloudConfigUpdate(t *testing.T) { assert.Equal("sc_test/terraform", cloudEntity.ClusterConfig.Placement.Folder) assert.Equal("spectro-templates", cloudEntity.ClusterConfig.Placement.ImageTemplateFolder) assert.Equal("ssh-rsa AAAAB3NzaC1y", cloudEntity.ClusterConfig.SSHKeys[0]) + assert.Equal("tt.tt.test.com", cloudEntity.ClusterConfig.ControlPlaneEndpoint.Host) assert.Equal(false, cloudEntity.ClusterConfig.StaticIP) }