Skip to content

Commit

Permalink
PLT-274: Datasource for ippool. (#208)
Browse files Browse the repository at this point in the history
* PLT-274: Datasource for ippool.

* PLT-274: Refresh docs.

* PLT-274: addressing review comments and adding examples for vmware static placement.

* PLT-274: correcting provider version for a vmware static example.

---------

Co-authored-by: nikolay-spectro <[email protected]>
  • Loading branch information
nikchern and nikchern authored Jan 31, 2023
1 parent dd7b969 commit e7ad017
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 14 deletions.
27 changes: 27 additions & 0 deletions docs/data-sources/ippool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "spectrocloud_ippool Data Source - terraform-provider-spectrocloud"
subcategory: ""
description: |-
---

# spectrocloud_ippool (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the IP pool.
- `private_cloud_gateway_id` (String) The ID of the private cloud gateway.

### Read-Only

- `id` (String) The ID of this resource.


23 changes: 23 additions & 0 deletions docs/data-sources/private_cloud_gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "spectrocloud_private_cloud_gateway Data Source - terraform-provider-spectrocloud"
subcategory: ""
description: |-
---

# spectrocloud_private_cloud_gateway (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of Private Cloud Gateway.
- `name` (String) The Name of Private Cloud Gateway.


16 changes: 16 additions & 0 deletions examples/data-sources/spectrocloud_ip_pool/datasource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "spectrocloud_private_cloud_gateway" "gateway" {
name = "pcg-benoitcamp-vcenter"
}

data "spectrocloud_ippool" "ippool" {
name = "IP Pool Jesse"
private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.gateway.id
}

variable "private_cloud_gateway_id" {
type = string
}

output "same" {
value = data.spectrocloud_ippool.ippool.id
}
21 changes: 21 additions & 0 deletions examples/data-sources/spectrocloud_ip_pool/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.11.1"
source = "spectrocloud/spectrocloud"
}
}
}

variable "sc_host" {}
variable "sc_username" {}
variable "sc_password" {}
variable "sc_project_name" {}

provider "spectrocloud" {
host = var.sc_host
username = var.sc_username
password = var.sc_password
project_name = var.sc_project_name
trace = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "spectrocloud_private_cloud_gateway" "gateway" {
name = "pcg-benoitcamp-vcenter"
}

output "same" {
value = data.spectrocloud_private_cloud_gateway.gateway.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.11.1"
source = "spectrocloud/spectrocloud"
}
}
}

variable "sc_host" {}
variable "sc_username" {}
variable "sc_password" {}
variable "sc_project_name" {}

provider "spectrocloud" {
host = var.sc_host
username = var.sc_username
password = var.sc_password
project_name = var.sc_project_name
trace = true
}
50 changes: 50 additions & 0 deletions examples/e2e/vsphere_static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Basic Cluster demo

End-to-end example of provisioning a new VMware K8s cluster with all of its dependencies. This terraform configuration
will provision the following resources on Spectro Cloud:
- VMware Cluster Profile
- VMware Cluster

For SaaS deployments, there is a dependency to install the Private Cloud Gateway before VMware K8s clusters can be provisioned.
Please proceed with installation of this appliance by following the documentation:
[Spectro Cloud VMware Cluster](https://docs.spectrocloud.com/getting-started/?getting_started=vmware#yourfirstvmwarecluster).

Once the private cloud gateway is running, please note the name of the created vSphere cloud account. Cloud accounts are managed
in Spectro Cloud Admin view:
- Login to Spectro Cloud UI (e.g for SaaS: https://console.spectrocloud.com)
- Switch to the Admin view (bottom left in the main-menu)
- Select _Settings_ in the main-menu
- Select _Cloud Accounts_
- Note the name of the newly added vSphere cloud account

This name will be specified as the `shared_Vmware_cloud_account_name` option in `terraform.tfvars`.

Alternatively, look at using a `spectrocloud_cloud_account_vsphere` resource to have Terraform create
a dedicated cloud account for this e2e example.

## Instructions:

Clone this repository to a local directory, and change directory to `examples/e2e/vsphere`. Proceed with the following:
1. Follow the Spectro Cloud documentation to create a Private Cloud Gateway:
[VMware First Cluster](https://docs.spectrocloud.com/getting-started/?getting_started=vmware#yourfirstvmwarecluster).
2. From the current directory, copy the template variable file `terraform.template.tfvars` to a new file `terraform.tfvars`.
3. Specify and update all the placeholder values in the `terraform.tfvars` file.
4. Initialize and run terraform: `terraform init && terraform apply`.
5. Wait for the cluster creation to finish.

Once the cluster is provisioned, the cluster _kubeconfig_ file is exported in the current working directly.

Export the kubeconfig and check cluster pods:

```shell
export KUBECONFIG=kubeconfig_vsphere-2
kubectl get pod -A
```

## Clean up:

Run the destroy operation:

```shell
terraform destroy
```
15 changes: 15 additions & 0 deletions examples/e2e/vsphere_static/datasource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data "spectrocloud_private_cloud_gateway" "gateway" {
name = var.gateway_name
}

data "spectrocloud_ippool" "ippool" {
name = var.ippool_name
private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.gateway.id
}


data "spectrocloud_cluster_profile" "profile" {
name = "vmware-jben"
version = "1.0.0"
context = "project"
}
6 changes: 6 additions & 0 deletions examples/e2e/vsphere_static/kubectl.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "local_file" "kubeconfig" {
content = local.cluster_kubeconfig
filename = "kubeconfig_vsphere-2"
file_permission = "0644"
directory_permission = "0755"
}
3 changes: 3 additions & 0 deletions examples/e2e/vsphere_static/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
cluster_kubeconfig = spectrocloud_cluster_vsphere.cluster.kubeconfig
}
11 changes: 11 additions & 0 deletions examples/e2e/vsphere_static/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "cluster_id" {
value = spectrocloud_cluster_vsphere.cluster.id
}

output "cluster_kubeconfig" {
value = local.cluster_kubeconfig
}

output "clusterprofile_id" {
value = data.spectrocloud_cluster_profile.profile.id
}
35 changes: 35 additions & 0 deletions examples/e2e/vsphere_static/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.11.1"
source = "spectrocloud/spectrocloud"
}
}
}

variable "sc_host" {
description = "Spectro Cloud Endpoint"
default = "api.spectrocloud.com"
}

variable "sc_username" {
description = "Spectro Cloud Username"
}

variable "sc_password" {
description = "Spectro Cloud Password"
sensitive = true
}

variable "sc_project_name" {
description = "Spectro Cloud Project (e.g: Default)"
default = "Default"
}

provider "spectrocloud" {
host = var.sc_host
username = var.sc_username
password = var.sc_password
project_name = var.sc_project_name
# ignore_insecure_tls_error = true
}
9 changes: 9 additions & 0 deletions examples/e2e/vsphere_static/resource_cloudaccount.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "spectrocloud_cloudaccount_vsphere" "account" {
name = var.new_vmware_cloud_account_name
context = "project"
private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.gateway.id
vsphere_vcenter = var.vsphere_vcenter
vsphere_username = var.vsphere_username
vsphere_password = var.vsphere_password
vsphere_ignore_insecure_error = true
}
42 changes: 42 additions & 0 deletions examples/e2e/vsphere_static/resource_cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "spectrocloud_cluster_vsphere" "cluster" {
name = "vsphere-static2"
cloud_account_id = spectrocloud_cloudaccount_vsphere.account.id

cluster_profile {
id = data.spectrocloud_cluster_profile.profile.id
}

cloud_config {
ssh_key = var.cluster_ssh_public_key
image_template_folder = var.vsphere_image_template_folder

datacenter = var.vsphere_datacenter
folder = var.vsphere_folder

static_ip = true
#network_type = "DDNS"
network_search_domain = var.cluster_network_search
}


machine_pool {
control_plane = true
control_plane_as_worker = true
name = "master-pool"
count = 3

placement {
cluster = var.vsphere_cluster
resource_pool = var.vsphere_resource_pool
datastore = var.vsphere_datastore
network = var.vsphere_network
static_ip_pool_id = data.spectrocloud_ippool.ippool.id
}
instance_type {
disk_size_gb = 40
memory_mb = 8192
cpu = 4
}
}

}
29 changes: 29 additions & 0 deletions examples/e2e/vsphere_static/terraform.template.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Spectro Cloud credentials
sc_host = "{enter Spectro Cloud API endpoint}" #e.g: api.spectrocloud.com (for SaaS)
sc_username = "{enter Spectro Cloud username}" #e.g: [email protected]
sc_password = "{enter Spectro Cloud password}" #e.g: supereSecure1!
sc_project_name = "{enter Spectro Cloud project Name}" #e.g: Default

# Cloud Account lookup by name
# See README.md for instructions how to obtain this name
shared_vmware_cloud_account_name = "{enter Spectro Cloud VMware Cloud Account name}"

# SSH public key to inject into all K8s nodes
# Insert your public key between the EOT markers
# The public key starts with "ssh-rsa ...."
cluster_ssh_public_key = <<-EOT
{enter SSH Public Key}
EOT

# For DHCP, the search domain
cluster_network_search = "{enter DHCP Search domain}" #e.g spectrocloud.local

# VMware cluster placement properties
# All fields except _vsphere\_resource\_pool_ are required fields
vsphere_datacenter = "{enter vSphere Datacenter}"
vsphere_folder = "{enter vSphere Folder}"

vsphere_cluster = "{enter vSphere ESX Cluster}"
vsphere_resource_pool = "{enter vSphere Resource Pool}" # Leave "" blank for Cluster Resource pool
vsphere_datastore = "{enter vSphere Datastore}"
vsphere_network = "{enter vSphere Network}"
37 changes: 37 additions & 0 deletions examples/e2e/vsphere_static/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#cluster variables
variable "vsphere_image_template_folder" {}
variable "cluster_ssh_public_key" {}
variable "cluster_network_search" {}

variable "vsphere_datacenter" {}
variable "vsphere_folder" {}

variable "vsphere_cluster" {}
variable "vsphere_resource_pool" {}
variable "vsphere_datastore" {}
variable "vsphere_network" {}

# common
variable "gateway_name" {
type = string
}

variable "ippool_name" {
type = string
}

# cloud account variables
variable "new_vmware_cloud_account_name" {}

variable "vsphere_vcenter" {
type = string
}

variable "vsphere_username" {
type = string
}

variable "vsphere_password" {
type = string
sensitive = true
}
Loading

0 comments on commit e7ad017

Please sign in to comment.