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

adding edge-native example #395

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
61 changes: 60 additions & 1 deletion docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,66 @@ description: |-

## Example Usage


Here's an example on how to provision a vSphere cluster with:
- based on a profile "spectrocloud_cluster_profile"
- name: vsphere-cluster-1
- two node pool: 1 master, 1 worker with 8 CPUs, 8Gb RAM and 60Gb disk

```terraform
resource "spectrocloud_cluster_vsphere" "cluster" {
name = "vsphere-cluster-1"
cluster_profile {
id = spectrocloud_cluster_profile.profile.id
}
cloud_account_id = data.spectrocloud_cloudaccount_vsphere.account.id

cloud_config {
ssh_key = var.cluster_ssh_public_key

datacenter = var.vsphere_datacenter
folder = var.vsphere_folder

network_type = "DDNS"
network_search_domain = var.cluster_network_search
}

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

placement {
cluster = var.vsphere_cluster
resource_pool = var.vsphere_resource_pool
datastore = var.vsphere_datastore
network = var.vsphere_network
}
instance_type {
disk_size_gb = 60
memory_mb = 8192
cpu = 8
}
}

machine_pool {
name = "worker-basic"
count = 1

placement {
cluster = var.vsphere_cluster
resource_pool = var.vsphere_resource_pool
datastore = var.vsphere_datastore
network = var.vsphere_network
}
instance_type {
disk_size_gb = 60
memory_mb = 8192
cpu = 8
}
}
}
```


<!-- schema generated by tfplugindocs -->
Expand Down
28 changes: 28 additions & 0 deletions examples/e2e/coxedge/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.1"
source = "spectrocloud/spectrocloud"
}
}
}

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"
}

provider "spectrocloud" {
host = var.sc_host
api_key = var.sc_api_key
project_name = var.sc_project_name
}
12 changes: 12 additions & 0 deletions examples/e2e/coxedge/resource_cloudaccount.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "spectrocloud_cloudaccount_coxedge" "account" {
name = var.shared_coxedge_cloud_account_name
}

resource "spectrocloud_cloudaccount_coxedge" "account" {
name = "coxedge-account"
organization_id = var.organization_id
environment = var.environment
service = var.service
api_base_url = var.api_base_url
api_key = var.api_key
}
45 changes: 45 additions & 0 deletions examples/e2e/coxedge/resource_cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
resource "spectrocloud_cluster_coxedge" "cluster" {
name = "tf-coxedge-cluster01"
cloud_account_id = data.spectrocloud_cloudaccount_coxedge.account.id

cluster_profile {
id = spectrocloud_cluster_profile.profile.id
}

cloud_config {
environment = "dev"
organization_id = "abcd-efg-hij-klm"
ssh_keys = [
"ssh-rsa ",
]

lb_config {
pops = [
"LAS",
]
}

worker_lb {
pops = [
"LAS",
]
}
}
machine_pool {
control_plane = true
control_plane_as_worker = true
name = "master-pool"
count = 1
cox_config {
spec = "SP-4"
}
}

machine_pool {
name = "worker-basic"
count = 1
cox_config {
spec = "SP-4"
}
}
}
63 changes: 63 additions & 0 deletions examples/e2e/coxedge/resource_clusterprofile.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
data "spectrocloud_registry" "registry" {
name = "Public Repo"
}

data "spectrocloud_pack" "csi" {
name = "csi-longhorn"
registry_uid = data.spectrocloud_registry.registry.id
version = "1.5.1"
}

data "spectrocloud_pack" "cni" {
name = "cni-calico"
registry_uid = data.spectrocloud_registry.registry.id
version = "3.26.1"
}

data "spectrocloud_pack" "k8s" {
name = "kubernetes-coxedge"
registry_uid = data.spectrocloud_registry.registry.id
version = "1.27.2"
}

data "spectrocloud_pack" "ubuntu" {
name = "ubuntu-coxedge"
registry_uid = data.spectrocloud_registry.registry.id
version = "20.04"
}

resource "spectrocloud_cluster_profile" "profile" {
name = "coxedge-profile-tf"
description = "basic cp"
cloud = "coxedge"
type = "cluster"

pack {
name = "ubuntu-coxedge"
tag = data.spectrocloud_pack.ubuntu.version
uid = data.spectrocloud_pack.ubuntu.id
values = data.spectrocloud_pack.ubuntu.values
}

pack {
name = "kubernetes-coxedge"
tag = data.spectrocloud_pack.k8s.version
uid = data.spectrocloud_pack.k8s.id
values = data.spectrocloud_pack.k8s.values
}

pack {
name = "cni-calico"
tag = data.spectrocloud_pack.cni.version
uid = data.spectrocloud_pack.cni.id
values = data.spectrocloud_pack.cni.values
}

pack {
name = "csi-longhorn"
tag = data.spectrocloud_pack.csi.version
uid = data.spectrocloud_pack.csi.id
values = data.spectrocloud_pack.csi.values
}

}
9 changes: 9 additions & 0 deletions examples/e2e/coxedge/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "organization_id" {}
variable "environment" {}
variable "service" {}
variable "api_key" {}
variable "api_base_url" {
default = "https://portal.coxedge.com/api/v2"
}

variable "shared_coxedge_cloud_account_name" {}
5 changes: 2 additions & 3 deletions examples/e2e/edge-native/kubectl.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
resource "local_file" "kubeconfig" {
content = spectrocloud_cluster_edge_native.cluster.kubeconfig
filename = "kubeconfig_ne-2"
content = local.cluster_kubeconfig
filename = "kubeconfig_edge-1"
file_permission = "0644"
directory_permission = "0755"
# sensitive_content = true
}
14 changes: 14 additions & 0 deletions examples/e2e/edge-native/resource_addon_deployment.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "spectrocloud_addon_deployment" "depl" {
cluster_uid = spectrocloud_cluster_edge_native.cluster.id
context = "project"

cluster_profile {
id = spectrocloud_cluster_profile.profile-addon.id
pack {
name = data.spectrocloud_pack.dashboard.name
tag = data.spectrocloud_pack.dashboard.version
uid = data.spectrocloud_pack.dashboard.id
values = data.spectrocloud_pack.dashboard.values
}
}
}
29 changes: 12 additions & 17 deletions examples/e2e/edge-native/resource_cluster.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
## Here's an example on how to provision an edge cluster with:
## - based on a profile "spectrocloud_cluster_profile"
## - name: edge-native-tf-1
## - single-node cluster with VIP and UID of edge device taken from variables

resource "spectrocloud_cluster_edge_native" "cluster" {
name = "edge-native-example"
skip_completion = true
name = "edge-native-tf-1"
skip_completion = false

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

cloud_config {
ssh_keys = ["spectro2022", "spectro2023"]
vip = "192.168.100.15"
ssh_keys = ["spectro2023", "spectro2024"]
vip = var.vip
}

machine_pool {
Expand All @@ -17,19 +22,9 @@ resource "spectrocloud_cluster_edge_native" "cluster" {
name = "master-pool"

edge_host {
host_uid = spectrocloud_appliance.appliance0.uid
static_ip = "126.10.10.23"
host_uid = var.edge_id
#static_ip = "123.45.67.89"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put some description about use-cases where static IP may be optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I would wait for overlay feature to land before we revisit this example.

}

}

machine_pool {
name = "worker-pool"

edge_host {
host_uid = spectrocloud_appliance.appliance1.uid
static_ip = "136.10.10.24"
}
}

}
69 changes: 64 additions & 5 deletions examples/e2e/edge-native/resource_clusterprofile.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
data "spectrocloud_cluster_profile" "profile" {
name = "edge-native-infra"
#Define a public repo as registry for packs
data "spectrocloud_registry" "registry" {
name = "Public Repo"
}

output "same" {
value = data.spectrocloud_cluster_profile.profile
}
data "spectrocloud_pack" "cni" {
registry_uid = data.spectrocloud_registry.registry.id
name = "cni-calico"
version = "3.26.1"
}

data "spectrocloud_pack" "k8s" {
registry_uid = data.spectrocloud_registry.registry.id
name = "edge-k3s"
version = "1.27.2"
}

data "spectrocloud_pack" "os" {
registry_uid = data.spectrocloud_registry.registry.id
name = "edge-native-byoi"
version = "1.0.0"
}

resource "spectrocloud_cluster_profile" "profile" {
name = "edge-profile-tf"
description = "basic cp"
tags = ["dev", "department:devops", "owner:alice"]
cloud = "edge-native"
type = "cluster"

pack {
name = data.spectrocloud_pack.os.name
tag = data.spectrocloud_pack.os.version
uid = data.spectrocloud_pack.os.id
#values = data.spectrocloud_pack.os.values
values = <<-EOT
pack:
content:
images:
- image: "{{.spectro.pack.edge-native-byoi.options.system.uri}}"
options:
system.uri: "{{ .spectro.pack.edge-native-byoi.options.system.registry }}/{{ .spectro.pack.edge-native-byoi.options.system.repo }}:{{ .spectro.pack.edge-native-byoi.options.system.k8sDistribution }}-{{ .spectro.system.kubernetes.version }}-{{ .spectro.pack.edge-native-byoi.options.system.peVersion }}-{{ .spectro.pack.edge-native-byoi.options.system.customTag }}"
system.registry: harbor.mycompany.tld
system.repo: ubuntu
system.k8sDistribution: k3s
system.osName: ubuntu
system.peVersion: v4.1.2
system.customTag: mytag
system.osVersion: 22
EOT
}

pack {
name = data.spectrocloud_pack.k8s.name
tag = data.spectrocloud_pack.k8s.version
uid = data.spectrocloud_pack.k8s.id
values = data.spectrocloud_pack.k8s.values
}

pack {
name = data.spectrocloud_pack.cni.name
tag = data.spectrocloud_pack.cni.version
uid = data.spectrocloud_pack.cni.id
values = data.spectrocloud_pack.cni.values
}
}
20 changes: 20 additions & 0 deletions examples/e2e/edge-native/resource_clusterprofile_addon.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
data "spectrocloud_pack" "dashboard" {
registry_uid = data.spectrocloud_registry.registry.id
name = "spectro-k8s-dashboard"
version = "2.7.1"
}

resource "spectrocloud_cluster_profile" "profile-addon" {
name = "edge-profile-addon-tf"
description = "addon cp"
tags = ["dev", "department:devops", "owner:alice"]
cloud = "edge-native"
type = "add-on"

pack {
name = data.spectrocloud_pack.dashboard.name
tag = data.spectrocloud_pack.dashboard.version
uid = data.spectrocloud_pack.dashboard.id
values = data.spectrocloud_pack.dashboard.values
}
}
Loading
Loading