From a35fb8a83a242d78cfad0cfc9911757db76a55dc Mon Sep 17 00:00:00 2001 From: Sczlog Date: Mon, 11 Sep 2023 00:16:13 +0800 Subject: [PATCH] update documentation --- docs/data-sources/cloudtower_cluster.md | 32 ++ .../cloudtower_content_library_vm_template.md | 50 ++- docs/data-sources/cloudtower_datacenter.md | 33 ++ docs/data-sources/cloudtower_host.md | 124 ++++++++ docs/data-sources/cloudtower_iso.md | 64 ++++ docs/data-sources/cloudtower_svt_iso.md | 58 ++++ docs/data-sources/cloudtower_vlan.md | 87 ++++++ docs/data-sources/cloudtower_vm.md | 109 +++++++ docs/data-sources/cloudtower_vm_snapshot.md | 97 ++++++ docs/index.md | 138 ++++++++- docs/resources/cloudtower_cluster.md | 34 +++ .../cloudtower_content_library_vm_template.md | 47 +++ docs/resources/cloudtower_datacenter.md | 11 + docs/resources/cloudtower_vm.md | 289 +++++++++++++++++- docs/resources/cloudtower_vm_snapshot.md | 33 ++ docs/resources/cloudtower_vm_template.md | 41 +++ ...data_source_content_library_vm_template.go | 16 +- 17 files changed, 1246 insertions(+), 17 deletions(-) diff --git a/docs/data-sources/cloudtower_cluster.md b/docs/data-sources/cloudtower_cluster.md index 86f0d0b..aad10b7 100644 --- a/docs/data-sources/cloudtower_cluster.md +++ b/docs/data-sources/cloudtower_cluster.md @@ -34,4 +34,36 @@ Read-Only: - `id` (String) - `name` (String) +## Usage +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific cluster + +use name will search a cluster by its name directly. Return of the data source will be a list, even if there is only one cluster found, use index 0 to get the cluster. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} +``` + +### Use name_contains to fuzzy search clusters + +use name_contains will search clusters by its name contains a certain string. Return a list of clusters, use index to get the cluster. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name_contains = "sample" +} +``` + +### Use name_in to search clusters in name array + +use name_in will search clusters by its name in a certain array. Return a list of clusters, use index to get the cluster. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name_in = ["sample_cluster", "sample_cluster2"] +} +``` \ No newline at end of file diff --git a/docs/data-sources/cloudtower_content_library_vm_template.md b/docs/data-sources/cloudtower_content_library_vm_template.md index 41c0bff..f23bd42 100644 --- a/docs/data-sources/cloudtower_content_library_vm_template.md +++ b/docs/data-sources/cloudtower_content_library_vm_template.md @@ -17,7 +17,7 @@ CloudTower content library vm template data source. ### Optional -- `cluster_in` (List of String) the cluster id which template has already distributed to. +- `cluster_id_in` (List of String) the cluster id which template has already distributed to. - `name` (String) content library vm template's name - `name_contains` (String) filter content_library vm template by its name contains characters - `name_in` (String) content library vm template's name as an array @@ -72,3 +72,51 @@ Read-Only: - `vlan_id` (String) +### Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific content library vm template + +use name will search a content library vm template by its name directly. Return of the data source will be a list, even if there is only one content library vm template found, use index 0 to get the content library vm template. + +```hcl +data "cloudtower_content_library_vm_template" "sample_content_library_vm_template" { + name = "sample_content_library_vm_template" +} +``` + +### Use name_contains to fuzzy search content library vm templates + +use name_contains will search content library vm templates by its name contains a certain string. Return a list of content library vm templates, use index to get the content library vm template. + +```hcl +data "cloudtower_content_library_vm_template" "sample_content_library_vm_template" { + name_contains = "sample" +} +``` + +### Use name_in to search content library vm templates in name array + +use name_in will search content library vm templates by its name in a certain array. Return a list of content library vm templates, use index to get the content library vm template. + +```hcl +data "cloudtower_content_library_vm_template" "sample_content_library_vm_template" { + name_in = ["sample1", "sample2"] +} +``` + +### Use cluster_id_in to restrict the content library vm template already distributed to certain clusters + +if need to search content library vm template already been distributed to certain clusters, use cluster_in to restrict the search. Recommand to use with other filters. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_content_library_vm_template" "sample_content_library_vm_template" { + name_contains = "sample" + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id] +} +``` \ No newline at end of file diff --git a/docs/data-sources/cloudtower_datacenter.md b/docs/data-sources/cloudtower_datacenter.md index 997a301..2e96e65 100644 --- a/docs/data-sources/cloudtower_datacenter.md +++ b/docs/data-sources/cloudtower_datacenter.md @@ -34,4 +34,37 @@ Read-Only: - `id` (String) - `name` (String) +## Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific datacenter + +use name will search a datacenter by its name directly. Return of the data source will be a list, even if there is only one datacenter found, use index 0 to get the datacenter. + +```hcl +data "cloudtower_datacenter" "sample_datacenter" { + name = "sample_datacenter" +} +``` + +### Use name_contains to fuzzy search datacenters + +use name_contains will search datacenters by its name contains a certain string. Return a list of datacenters, use index to get the datacenter. + +```hcl +data "cloudtower_datacenter" "sample_datacenter" { + name_contains = "sample" +} +``` + +### Use name_in to search datacenters in name array + +use name_in will search datacenters by its name in a certain array. Return a list of datacenters, use index to get the datacenter. + +```hcl +data "cloudtower_datacenter" "sample_datacenter" { + name_in = ["sample1", "sample2"] +} +``` diff --git a/docs/data-sources/cloudtower_host.md b/docs/data-sources/cloudtower_host.md index 7066561..c2fee73 100644 --- a/docs/data-sources/cloudtower_host.md +++ b/docs/data-sources/cloudtower_host.md @@ -45,3 +45,127 @@ Read-Only: - `name` (String) +## Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific host + +use name will search a host by its name directly. Return of the data source will be a list, even if there is only one host found, use index 0 to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + name = "sample_host" +} +``` + +### Use name_contains to fuzzy search hosts + +use name_contains will search hosts by its name contains a certain string. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + name_contains = "sample" +} +``` + +### Use name_in to search hosts in name array + +use name_in will search hosts by its name in a certain array. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + name_in = ["sample1", "sample2"] +} +``` + +### Use management_ip to get a specific host + +use management_ip will search a host by its management_ip directly. Return of the data source will be a list, even if there is only one host found, use index 0 to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + management_ip = "192.168.1.1" +} +``` + +### Use management_ip_contains to fuzzy search hosts + +use management_ip_contains will search hosts by its management_ip contains a certain string. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + management_ip_contains = "31.16" +} +``` + +### Use management_ip_in to search hosts in management_ip array + +use management_ip_in will search hosts by its management_ip in a certain array. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + management_ip_in = ["192.168.1.1", "192.168.1.2"] +} +``` + +### Use data_ip to get a specific host + +use data_ip will search a host by its data_ip directly. Return of the data source will be a list, even if there is only one host found, use index 0 to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + data_ip = "10.0.1.1" +} +``` + +### Use data_ip_contains to fuzzy search hosts + +use data_ip_contains will search hosts by its data_ip contains a certain string. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + data_ip_contains = "255.255" +} +``` + +### Use data_ip_in to search hosts in data_ip array + +use data_ip_in will search hosts by its data_ip in a certain array. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_host" "sample_host" { + data_ip_in = ["10.0.1.1", "10.0.255.255"] +} + +``` + +### Use cluster_id to get host in a specific cluster + +use cluster_id will search hosts in a specific cluster. Return a list of hosts, use index to get the host. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_host" "sample_host" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} +``` + +### Use cluster_id_in to get hosts in a one of clusters + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_host" "sample_host" { + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id] +} +``` + + + + diff --git a/docs/data-sources/cloudtower_iso.md b/docs/data-sources/cloudtower_iso.md index f880cb7..7a0d06f 100644 --- a/docs/data-sources/cloudtower_iso.md +++ b/docs/data-sources/cloudtower_iso.md @@ -37,3 +37,67 @@ Read-Only: - `name` (String) +## Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific image + +use name will search a image by its name directly. Return of the data source will be a list, even if there is only one image found, use index 0 to get the image. + +```hcl +data "cloudtower_iso" "sample_iso" { + name = "sample_iso" +} +``` + +### Use name_contains to fuzzy search images + +use name_contains will search images by its name contains a certain string. Return a list of images, use index to get the image. + +```hcl +data "cloudtower_iso" "sample_iso" { + name_contains = "sample" +} +``` + +### Use name_in to search images in name array + +use name_in will search images by its name in a certain array. Return a list of images, use index to get the image. + +```hcl +data "cloudtower_iso" "sample_iso" { + name_in = ["sample_iso", "sample_iso2"] +} +``` + +### Use cluster_id to get a specific image stored in a cluster + +use cluster_id will search a image by its cluster id directly. Return of the data source will be a list, even if there is only one image found, use index 0 to get the image. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_iso" "sample_iso" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id +} +``` + +### Use cluster_id_in to search images stored in clusters + +use cluster_id_in will search images by its cluster id in a certain array. Return a list of images, use index to get the image, recommend to use cluster_id, as vm could only mount svt iso directly from cluster it runs on. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_iso" "sample_iso" { + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].id] +} +``` + + + diff --git a/docs/data-sources/cloudtower_svt_iso.md b/docs/data-sources/cloudtower_svt_iso.md index 50508c1..50de70d 100644 --- a/docs/data-sources/cloudtower_svt_iso.md +++ b/docs/data-sources/cloudtower_svt_iso.md @@ -40,4 +40,62 @@ Read-Only: - `name` (String) - `version` (Number) +### Usage +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific image + +use name will search a image by its name directly. Return of the data source will be a list, even if there is only one image found, use index 0 to get the image. + +```hcl +data "cloudtower_svt_iso" "sample_iso" { + name = "sample_iso" +} +``` + +### Use name_contains to fuzzy search images + +use name_contains will search images by its name contains a certain string. Return a list of images, use index to get the image. + +```hcl +data "cloudtower_svt_iso" "sample_iso" { + name_contains = "sample" +} +``` + +### Use name_in to search images in name array + +use name_in will search images by its name in a certain array. Return a list of images, use index to get the image. + +```hcl +data "cloudtower_svt_iso" "sample_iso" { + name_in = ["sample_iso", "sample_iso2"] +} +``` + +### Use cluster_id to get a specific image stored in a cluster + +use cluster_id will search a image by its cluster id directly. Return of the data source will be a list, even if there is only one image found, use index 0 to get the image. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} +data "cloudtower_svt_iso" "sample_iso" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} +``` + +### Use cluster_id_in to search images stored in a cluster in a certain array + +use cluster_id_in will search images by its cluster id in a certain array. Return a list of images, use index to get the image. Recommend to use cluster_id, as vm could only mount svt iso directly from cluster it runs on. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} +data "cloudtower_svt_iso" "sample_iso" { + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id] +} +``` diff --git a/docs/data-sources/cloudtower_vlan.md b/docs/data-sources/cloudtower_vlan.md index b55448a..6385213 100644 --- a/docs/data-sources/cloudtower_vlan.md +++ b/docs/data-sources/cloudtower_vlan.md @@ -40,4 +40,91 @@ Read-Only: - `name` (String) - `type` (String) +### Usage +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific vlan + +use name will search a vlan by its name directly. Return of the data source will be a list, even if there is only one vlan found, use index 0 to get the vlan. + +```hcl +data "cloudtower_vlan" "sample_vlan" { + name = "sample_vlan" +} +``` + +### Use name_contains to fuzzy search vlans + +use name_contains will search vlans by its name contains a certain string. Return a list of vlans, use index to get the vlan. + +```hcl +data "cloudtower_vlan" "sample_vlan" { + name_contains = "sample" +} +``` + +### Use name_in to search vlans in name array + +use name_in will search vlans by its name in a certain array. Return a list of vlans, use index to get the vlan. + +```hcl +data "cloudtower_vlan" "sample_vlan" { + name_in = ["sample_vlan", "sample_vlan2"] +} +``` + +### Use type to get a filter vlans by type + +filter vlan by type, return a list of vlans, use index to get the vlan, recommand to use with other filters. + +Only accept `"ACCESS", "MANAGEMENT", "MIGRATION", "STORAGE", "VM"` + +```hcl +data "cloudtower_vlan" "sample_vlan" { + type = "VM" + name = "sample_vlan" +} +``` + +### Use type_in to filter vlans by type as array + +filter vlans by type in a certain array, return a list of vlans, use index to get the vlan, recommand to use with other filters. + +Only accept `"ACCESS", "MANAGEMENT", "MIGRATION", "STORAGE", "VM"` + +```hcl +data "cloudtower_vlan" "sample_vlan" { + type_in = ["VM", "STORAGE"] + name = "sample_vlan" +} +``` + +### Use cluster_id to get a specific vlan stored in a cluster + +use cluster_id will search a vlan by its cluster id directly. Return a list of vlans, use index to get the vlan. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vlan" "sample_vlan" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} +``` + +### Use cluster_id_in to search vlans stored in clusters + +use cluster_id_in will search vlans by its cluster id in a certain array. Return a list of vlans, use index to get the vlan, recommand to use with other filters. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vlan" "sample_vlan" { + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id] + name = "sample_vlan" +} +``` \ No newline at end of file diff --git a/docs/data-sources/cloudtower_vm.md b/docs/data-sources/cloudtower_vm.md index 71b2d70..2325e38 100644 --- a/docs/data-sources/cloudtower_vm.md +++ b/docs/data-sources/cloudtower_vm.md @@ -42,3 +42,112 @@ Read-Only: - `status` (String) +### Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific VM + +use name will search a VM by its name directly. Return of the data source will be a list, even if there is only one VM found, use index 0 to get the VM. + +```hcl +data "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} +``` + +### Use name_contains to fuzzy search VMs + +use name_contains will search VMs by its name contains a certain string. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_vm" "sample_vm" { + name_contains = "sample" +} +``` + +### Use name_in to search VMs in name array + +use name_in will search VMs by its name in a certain array. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_vm" "sample_vm" { + name_in = ["sample_vm", "sample_vm2"] +} +``` + +### Use status to get a filter VMs by power status + +use status will search VMs by its power status. Return a list of VMs, use index to get the VM. + +only accept `"RUNNING", "STOPPED", "SUSPENDED"` + +```hcl +data "cloudtower_vm" "sample_vm" { + status = "RUNNING" +} +``` + +### Use status_in to search VMs in status array + +use status_in will search VMs by its power status in a certain array. Return a list of VMs, use index to get the VM. + +only accept `"RUNNING", "STOPPED", "SUSPENDED"` + +```hcl +data "cloudtower_vm" "sample_vm" { + status_in = ["RUNNING", "STOPPED"] +} +``` + +### Use cluster_id to get VMs run on a specific cluster + +use cluster_id will search VMs by its cluster id it runs on. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vm" "sample_vm" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id +} +``` + +### Use cluster_id_in to search VMs run on multiple clusters + +use cluster_id_in will search VMs run on multiple clusters. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vm" "sample_vm" { + cluster_id_in = [data.cloudtower_cluster.sample_cluster.clusters[0].id, data.cloudtower_cluster.sample_cluster.clusters[1].id] +} +``` + +### Use host_id to get VMs run on a specific host + +use host_id will search VMs by its host id it runs on. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_host" "sample_host" { + name = "sample_host" +} + +data "cloudtower_vm" "sample_vm" { + host_id = data.cloudtower_host.sample_host.hosts[0].id +} +``` + +### Use host_id_in to search VMs run on multiple hosts + +use host_id_in will search VMs run on multiple hosts. Return a list of VMs, use index to get the VM. + +```hcl +data "cloudtower_host" "sample_host" { + name = "sample_host" +} +``` \ No newline at end of file diff --git a/docs/data-sources/cloudtower_vm_snapshot.md b/docs/data-sources/cloudtower_vm_snapshot.md index 067e819..6e3152c 100644 --- a/docs/data-sources/cloudtower_vm_snapshot.md +++ b/docs/data-sources/cloudtower_vm_snapshot.md @@ -75,3 +75,100 @@ Read-Only: - `vlan_id` (String) +### Usage + +All arguments are optional, and if multiple arguments are provided, they are ANDed together. + +### Use name to get a specific vm snapshot + +use name will search a vm snapshot by its name directly. Return of the data source will be a list, even if there is only one vm snapshot found, use index 0 to get the vm snapshot. + +```hcl +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name = "sample_vm_snapshot" +} +``` + +### Use name_contains to fuzzy search vm snapshots + +use name_contains will search vm snapshots by its name contains a certain string. Return a list of vm snapshots, use index to get the vm snapshot. + +```hcl +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name_contains = "sample" +} +``` + +### Use name_in to search vm snapshots in name array + +use name_in will search vm snapshots by its name in a certain array. Return a list of vm snapshots, use index to get the vm snapshot. + +```hcl +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name_in = ["sample_vm_snapshot", "sample_vm_snapshot2"] +} +``` + +### Use vm_id to get snapshot of a specific vm + +use vm_id will search a vm snapshot by its vm id directly. Return a list of vm snapshots, use index to get the vm snapshot. + +```hcl +data "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + vm_id = data.cloudtower_vm.sample_vm.vms[0].id +} +``` + +### Use vm_id_in to search vm snapshots of vms + +use vm_id_in will search vm snapshots by its vm id in a certain array. Return a list of vm snapshots, use index to get the vm snapshot. + +```hcl +data "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + vm_id_in = [data.cloudtower_vm.sample_vm.vms[0].id, data.cloudtower_vm.sample_vm.vms[1].id] +} +``` + +### rollback vm to specific snapshot + +if an snapshot is not managed by terraform, and you want to rollback vm to that snapshot, you can use this data source to get the snapshot id, and use it in cloudtower_vm resource. + +```hcl + +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name = "sample_vm_snapshot" +} + +// here is an vm already been managed by terraform, rollback_to will not take effect when create vm. +resource "cloudtower_vm" "sample_vm" { + name = "sample_vm" + # ... any other vm configuration + rollback_to = data.cloudtower_vm_snapshot.sample_vm_snapshot.vm_snapshots[0].id +} +``` + +### rebuild vm from specific snapshot + +if an snapshot is not managed by terraform, and you want to rebuild vm from that snapshot, you can use this data source to get the snapshot id, and use it in cloudtower_vm resource. + +```hcl +data "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name = "sample_vm_snapshot" +} + +resource "cloudtower_vm" "sample_vm_rebuild" { + name = "tf-test-vm-from-snapshot" + cluster_id = cloudtower_cluster.sample_cluster.id + create_effect { + rebuild_from_snapshot = data.cloudtower_vm_snapshot.sample_vm_snapshot.vm_snapshots[0].id + } +} +``` \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index cc4cd5e..bec84da 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,21 +3,151 @@ page_title: "cloudtower-terraform-provider Provider" subcategory: "" description: |- - --- # cloudtower-terraform-provider Provider +The `cloudtower-terraform-provider` provider is used to interact with the resources supported by CloudTower. The provider needs to be configured with the proper credentials before it can be used. - - +Use the navigation to the left to read about the available resources. + ## Schema ### Optional -- `cloudtower_server` (String) The CloudTower Server name. +- `cloudtower_server` (String) The CloudTower Server's endpoint, if not set, will use localhost. - `password` (String) The user password for CloudTower API operations. - `user_source` (String) The source type of user - `username` (String) The username for CloudTower API operations. + +## Features + +### Vm + +- create + + 1. create blank vm + 2. create vm from template/content library template + 3. clone vm + 4. rebuild vm + +- update + 1. update vm's cpu/memory + 2. cd-rom and disk + 3. nic + 4. ha + 5. power status + +### Template and content library template + +- clone from vm +- distribute to clusters (content library template only) + +### Snapshot + +- create snapshot for vm +- rollback to snapshot + +### Datacenter and cluster + +- connect cluster +- create datacenter +- move cluster in and out from datacenter + +## Quick Start + +Here is an example to create a VM with 2 disks and 1 cdrom on cluster "sample_cluster", with an already uploaded CD-ROM name contains ubuntu, also speiciy the host to run the VM on. + +```hcl +terraform { + required_providers { + cloudtower = { + version = "~> 0.1.7" + source = "registry.terraform.io/smartxworks/cloudtower" + } + } +} + +locals { + GB = 1024 * local.MB + MB = 1024 * local.KB + KB = 1024 +} + +// authentication block, password will be prompted when apply, otherwise you can use environment variables +provider "cloudtower" { + username = "username" + user_source = "LOCAL" + cloudtower_server = "http://terraform.tower.com" +} + +data "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vlan" "vm_vlan" { + name = "default" + type = "VM" + cluster_id = data.data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} + +data "cloudtower_iso" "ubuntu" { + name_contains = "ubuntu" + cluster_id = data.data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} + +data "cloudtower_host" "target_host" { + management_ip_contains = "17.42" + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id +} + +resource "cloudtower_vm" "tf_test" { + name = "tf-test" + description = "managed by terraform" + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id + host_id = data.cloudtower_host.target_host.hosts[0].id + vcpu = 4 + memory = 8 * local.GB + ha = true + firmware = "BIOS" + status = "STOPPED" + force_status_change = true + + cd_rom { + boot = 1 + iso_id = data.cloudtower_iso.ubuntu.isos[0].id + } + + + disk { + boot = 2 + bus = "VIRTIO" + vm_volume { + storage_policy = "REPLICA_2_THIN_PROVISION" + name = "disk1" + size = 10 * local.GB + } + } + + disk { + boot = 3 + bus = "VIRTIO" + vm_volume { + storage_policy = "REPLICA_3_THICK_PROVISION" + name = "disk2" + size = 1 * local.GB + } + } + + cd_rom { + boot = 4 + iso_id = "" + } + + nic { + vlan_id = data.cloudtower_vlan.vm_vlan.vlans[0].id + } +} +``` diff --git a/docs/resources/cloudtower_cluster.md b/docs/resources/cloudtower_cluster.md index 62c37f0..82aed6d 100644 --- a/docs/resources/cloudtower_cluster.md +++ b/docs/resources/cloudtower_cluster.md @@ -31,3 +31,37 @@ CloudTower cluster resource. - `name` (String) cluster's name +## Usage + +### Connect a cluster + +This will connect a cluster to cloudtower. + +```hcl +resource "cloudtower_cluster" "sample_cluster" { + ip = "192.168.1.1" + username = "admin" + password = "password" +} +``` + +### Connect a cluster and add it to a datacenter + +Connect a cluster, and also add the cluster to a datacenter. + +```hcl +data "cloudtower_datacenter" "sample_datacenter" { + name = "sample_datacenter" +} + +resource "cloudtower_cluster" "sample_cluster" { + ip = "192.168.1.1" + username = "admin" + password = "password" + datacenter_id = data.cloudtower_datacenter.sample_datacenter.datacenters[0].id +} +``` + +## Restrictions + +If an cluster has already been connected to cloudtower, it will throw an error if you try to connect it again. You can use datasource to handle it or import the cluster to terraform state. \ No newline at end of file diff --git a/docs/resources/cloudtower_content_library_vm_template.md b/docs/resources/cloudtower_content_library_vm_template.md index f00c19a..ca5567d 100644 --- a/docs/resources/cloudtower_content_library_vm_template.md +++ b/docs/resources/cloudtower_content_library_vm_template.md @@ -67,4 +67,51 @@ Read-Only: - `model` (String) - `vlan_id` (String) +## Usage +use content library vm template can help you share template accross clusters. + +### create a template from vm + +This will create a template from vm in cloudtower, the template store in specified cluster. + +use cloud_init_supported to mark if template support cloud_init. + +specified more cluster_id to distribute template to other clusters. + +```hcl + +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +datasource "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +resource "cloudtower_content_library_vm_template" "sample_template" { + name = "sample_template" + cloud_init_supported = false + cluster_id = [data.cloudtower_cluster.sample_cluster.clusters[0].id] + src_vm_id = data.cloudtower_vm.sample_vm.vms[0].id +} +``` + + +### clone a vm from content library template + +Clone a vm from content library template, this will create a vm directly from a template, without any modification, for further usage, please see cloudtower_vm resource. + +```hcl +datasource "cloudtower_vm_template" "sample_template" { + name = "tf-test-template" +} + +resource "cloudtower_vm" "sample_cloned_vm" { + name = "tf-test-cloned-vm-from-template" + create_effect { + is_full_copy = false + clone_from_template = data.cloudtower_vm_template.sample_template.vm_templates[0].id + } +} +``` \ No newline at end of file diff --git a/docs/resources/cloudtower_datacenter.md b/docs/resources/cloudtower_datacenter.md index 80c9878..0e9e134 100644 --- a/docs/resources/cloudtower_datacenter.md +++ b/docs/resources/cloudtower_datacenter.md @@ -24,3 +24,14 @@ CloudTower datacenter resource. - `id` (String) datacenter's id +## Usage + +### Create a datacenter + +This will create a datacenter in cloudtower, and will manage its lifecycle with terraform + +```hcl +resource "cloudtower_datacenter" "sample_datacenter" { + name = "sample_datacenter" +} +``` \ No newline at end of file diff --git a/docs/resources/cloudtower_vm.md b/docs/resources/cloudtower_vm.md index 1341bc4..b0b22aa 100644 --- a/docs/resources/cloudtower_vm.md +++ b/docs/resources/cloudtower_vm.md @@ -10,9 +10,8 @@ description: |- CloudTower vm resource. - - + ## Schema ### Required @@ -45,6 +44,7 @@ CloudTower vm resource. - `id` (String) VM's id + ### Nested Schema for `cd_rom` Required: @@ -56,8 +56,8 @@ Read-Only: - `id` (String) VM CD-ROM's id - + ### Nested Schema for `create_effect` Optional: @@ -70,6 +70,7 @@ Optional: - `rebuild_from_snapshot` (String) Id of snapshot for created vm to be rebuilt from + ### Nested Schema for `create_effect.cloud_init` Optional: @@ -82,6 +83,7 @@ Optional: - `user_data` (String) User-provided cloud-init user-data field. Base64 encoding is not supported. Size limit: 32KiB. + ### Nested Schema for `create_effect.cloud_init.networks` Required: @@ -96,6 +98,7 @@ Optional: - `routes` (Block List, Max: 1) Static route list (see [below for nested schema](#nestedblock--create_effect--cloud_init--networks--routes)) + ### Nested Schema for `create_effect.cloud_init.networks.routes` Optional: @@ -104,11 +107,8 @@ Optional: - `netmask` (String) Netmask of the network - `network` (String) Static route network address. If set to 0.0.0.0, then first use the user settings to configure the default route. - - - - + ### Nested Schema for `disk` Required: @@ -126,6 +126,7 @@ Read-Only: - `id` (String) the VM disk's id + ### Nested Schema for `disk.vm_volume` Required: @@ -143,9 +144,8 @@ Read-Only: - `id` (String) the VM volume's id - `path` (String) the VM volume's iscsi LUN path - - + ### Nested Schema for `nic` Required: @@ -167,4 +167,273 @@ Read-Only: - `id` (String) VM nic's id - `idx` (Number) VM nic's index - +## Usage + +### create a blank vm + +This will create a blank vm on speicifed cluster. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} +resource "cloudtower_vm" "sample_vm" { + name = "sample_vm" + cluster_id = datasource.cloudtower_cluster.sample_cluster.clusters[0].id + cpu_cores = 1 + cpu_sockets = 1 + memory = 1073741824 + vcpu = 1 + nic { + vlan_id = "vlan_id" + } + disk { + boot = 1 + bus = "scsi" + vm_volume { + name = "sample_vm_volume" + size = 1073741824 + storage_policy = "REPLICA_2_THICK_PROVISION" + } + } +} +``` + +### clone from another vm + +use create_effect.clone_from_vm can clone a new vm from another vm + +```hcl +resource "cloudtower_vm" "tf_test_cloned-vm" { + name = "tf-test-cloned-vm" + cluster_id = cloudtower_cluster.sample_cluster.id + create_effect { + clone_from_vm = cloudtower_vm.tf_test.id + } +} +``` + +### rebuild from snapshot + +use create_effect.rebuild_from_snapshot can rebuild a vm from a snapshot + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +datasource "cloudtower_vm_snapshot" "sample_snapshot" { + name = "sample-snapshot" +} + +resource "cloudtower_vm" "sample_vm_from_snapshot" { + name = "sample-vm-from_snapshot" + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id + create_effect { + rebuild_from_snapshot = data.cloudtower_vm_snapshot.sample_snapshot.snapshots[0].id + } +} +``` + +### clone from content library template + +Create a vm from content library template, which is support to be used between different cluster. + +Use effect.clone_from_content_library_template to clone a vm from content library template. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_content_library_vm_template" "sample_template" { + name = "sample_template" +} + +resource "cloudtower_vm" "sample_content_library_vm" { + name = "sample-content-library-template-vm" + create_effect { + is_full_copy = false + clone_from_content_library_template = data.cloudtower_content_library_vm_template.sample_template.vm_templates[0].id + } +} +``` + +### clone from content libarary template with modification + +Clone from content libarary template support modificiation from the origin template. + +#### computing resource + +cpu_cores, cpu_sockets, memory, vcpu can be modified from template. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_content_library_vm_template" "sample_template" { + name = "sample_template" +} + +resource "cloudtower_vm" "sample_content_library_vm" { + name = "sample-content-library-template-vm" + create_effect { + is_full_copy = false + clone_from_content_library_template = data.cloudtower_content_library_vm_template.sample_template.vm_templates[0].id + } + vcpu = 12 + cpu_cores = 3 + cpu_sockets = 4 + memory = 1073741824 +} +``` + +#### disk + +As use terraform to manage vm, if you want to modify disk from template, you should declare all disk in disk block, otherwise it will leave part of disk under management while others not, which may cause many side effect. + +If you want fully control the disks, declared any disk in disk block, it will override all disk from template, so you should declare all disk in disk block. + +To use disk from template with disk modification, you should configure origin_path of disk to make disk create base on template disk. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_content_library_vm_template" "sample_template" { + name = "sample_template" +} + +resource "cloudtower_vm" "sample_content_library_vm" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id + name = "sample-content-library-template-vm" + create_effect { + is_full_copy = false + clone_from_content_library_template = data.cloudtower_content_library_vm_template.sample_template.vm_templates[0].id + } + dynamic "disk" { + for_each = data.cloudtower_content_library_vm_template.sample_template.vm_templates[0].disks + content { + boot = disk.value.boot + bus = disk.value.bus + vm_volume { + storage_policy = disk.value.storage_policy + name = "${var.config["vm_name"][count.index]}-${disk.key + 1}" + size = disk.value.size + origin_path = disk.value.path + } + } + } + disk { + boot = length(data.cloudtower_content_library_vm_template.query_templates.content_library_vm_templates[0].vm_templates[0].disks) + disk.key + bus = "VIRTIO" + vm_volume { + storage_policy = "REPLICA_2_THIN_PROVISION" + name = "new-volume" + size = disk.value * local.GB + } + } + + cd_rom { + boot = length(data.cloudtower_content_library_vm_template.query_templates.content_library_vm_templates[0].vm_templates[0].disks) + 2 + iso_id = "" + } +} +``` + +#### nic + +If nic is not configured, it will use default vlan of cluster for every nic. + +The same to disk, if you want to modify nic from template, you should declare all nic in nic block. + +``` +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_content_library_vm_template" "sample_template" { + name = "sample_template" +} + +data "cloudtower_vlan" "sample_vlan" { + name = "default" + type = "VM" + cluster_id = data.data.cloudtower_cluster.sample_cluster.clusters[0].clusters[0].id +} + +resource "cloudtower_vm" "sample_content_library_vm" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id + name = "sample-content-library-template-vm" + create_effect { + is_full_copy = false + clone_from_content_library_template = data.cloudtower_content_library_vm_template.sample_template.vm_templates[0].id + } + + cd_rom { + boot = 0 + iso_id = "" + } + + nic { + vlan_id = data.cloudtower_vlan.sample_vlan.vlans[0].id + } +} +``` + +### clone from content library template with cloud init + +If template support cloud-init, pass cloudinit config can set up vm's starting ip, hostname, default user password, etc. + +Configure them in create_effect.cloud_init block. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} +resource "cloudtower_vm" "sample_cloud_init_vm" { + name = "tf-test-cloned-vm-from-template-modify-cloud-init" + create_effect { + is_full_copy = false + clone_from_template = data.cloudtower_vm_template.tf_test_template.vm_templates[0].id + cloud_init { + hostname = "tf-test-vm-hostname" + default_user_password = 111111 + networks { + type = "IPV4" + nic_index = 0 + ip_address = "192.168.11.2" + netmask = "255.255.255.0", + gateway = "192.168.11.1" + } + } + } +} +``` + +### clone from template + +Deprecated, content library template is preferred, but vm template is also supported, usage is close to content library template. + +use create_effect.clone_from_template can clone a new vm from template. + +```hcl +datasource "cloudtower_cluster" "sample_cluster" { + name = "sample_cluster" +} + +data "cloudtower_vm_template" "sample_template" { + cluster_id = data.cloudtower_cluster.sample_cluster.clusters[0].id + name = var.vm_template_with_cloud_init +} + +resource "cloudtower_vm" "tf_test_cloned_vm" { + name = "tf-test-cloned-vm-from-template" + create_effect { + is_full_copy = false + clone_from_template = data.cloudtower_vm_template.sample_template.vm_templates[0].id + } +} +``` diff --git a/docs/resources/cloudtower_vm_snapshot.md b/docs/resources/cloudtower_vm_snapshot.md index 2270456..0b50975 100644 --- a/docs/resources/cloudtower_vm_snapshot.md +++ b/docs/resources/cloudtower_vm_snapshot.md @@ -65,4 +65,37 @@ Read-Only: - `model` (String) - `vlan_id` (String) +## Usage +### Create a vm snapshot + +This will create a vm snapshot in cloudtower, and will manage its lifecycle with terraform + +```hcl +data "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +resource "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name = "sample_vm_snapshot" + vm_id = data.cloudtower_vm.sample_vm.vms[0].id +} +``` + +### Create a vm snapshot with consistent_type + +Consisent type can be defined when create a vm snapshot. + +Only accept `["CRASH_CONSISTENT", "FILE_SYSTEM_CONSISTENT"]`, and Only Vm tools is running on the VM, `FILE_SYSTEM_CONSISTENT` can be used. + +```hcl +data "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +resource "cloudtower_vm_snapshot" "sample_vm_snapshot" { + name = "sample_vm_snapshot" + vm_id = data.cloudtower_vm.sample_vm.vms[0].id + consistent_type = "FILE_SYSTEM_CONSISTENT" +} +``` \ No newline at end of file diff --git a/docs/resources/cloudtower_vm_template.md b/docs/resources/cloudtower_vm_template.md index 7485c57..3a5d358 100644 --- a/docs/resources/cloudtower_vm_template.md +++ b/docs/resources/cloudtower_vm_template.md @@ -67,3 +67,44 @@ Read-Only: - `vlan_id` (String) + +## Usage + +template usage is deprecated, please use content library vm template instead. + +### create a template from vm + +This will create a template from vm in cloudtower, the template will store in vm's cluster, and will manage its lifecycle with terraform. + +use cloud_init_supported to mark if template support cloud_init +```hcl + +datasource "cloudtower_vm" "sample_vm" { + name = "sample_vm" +} + +resource "cloudtower_vm_template" "sample_template" { + name = "sample_template" + cloud_init_supported = false + description = "sample template" + src_vm_id = data.cloudtower_vm.sample_vm.vms[0].id +} +``` + +### clone a vm from template + +Clone a vm from template, this will create a vm directly from a template, without any modification, for further usage, please see cloudtower_vm resource. + +```hcl +datasource "cloudtower_vm_template" "sample_template" { + name = "tf-test-template" +} + +resource "cloudtower_vm" "sample_cloned_vm" { + name = "tf-test-cloned-vm-from-template" + create_effect { + is_full_copy = false + clone_from_template = data.cloudtower_vm_template.sample_template.vm_templates[0].id + } +} +``` \ No newline at end of file diff --git a/internal/provider/data_source_content_library_vm_template.go b/internal/provider/data_source_content_library_vm_template.go index 23abfeb..dfeabb2 100644 --- a/internal/provider/data_source_content_library_vm_template.go +++ b/internal/provider/data_source_content_library_vm_template.go @@ -42,7 +42,7 @@ func dataSourceContentLibraryVmTemplate() *schema.Resource { Optional: true, Description: "filter content_library vm template by its name contains characters", }, - "cluster_in": { + "cluster_id_in": { Type: schema.TypeList, Optional: true, Elem: &schema.Schema{ @@ -50,6 +50,15 @@ func dataSourceContentLibraryVmTemplate() *schema.Resource { }, Description: "the cluster id which template has already distributed to.", }, + "cluster_in": { + Type: schema.TypeList, + Optional: true, + Deprecated: "cluster_in is deprecated, use cluster_id_in instead.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "the cluster id which template has already distributed to.", + }, "content_library_vm_templates": { Type: schema.TypeList, Computed: true, @@ -195,7 +204,10 @@ func dataSourceContentLibraryVmTemplateRead(ctx context.Context, d *schema.Resou gp.RequestBody.Where.NameContains = &nameContains } - raw_cluster_id, ok := d.GetOk("cluster_id") + raw_cluster_id, ok := d.GetOk("cluster_id_in") + if !ok { + raw_cluster_id, ok = d.GetOk("cluster_in") + } if ok { bytes, err := json.Marshal(raw_cluster_id) if err != nil {