From a833107b81da2927aa486a6bbf589ed1887f3368 Mon Sep 17 00:00:00 2001 From: Arman Keyoumarsi Date: Tue, 6 Jul 2021 20:23:25 +0200 Subject: [PATCH] Simplified the Sanity test structure --- tests/sanity/README.md | 36 +----------------- tests/sanity/main.tf | 85 +++++++++++++++++++++++++----------------- tests/smoke/main.tf | 5 +++ 3 files changed, 56 insertions(+), 70 deletions(-) diff --git a/tests/sanity/README.md b/tests/sanity/README.md index 2a86956..7ba03e1 100644 --- a/tests/sanity/README.md +++ b/tests/sanity/README.md @@ -1,6 +1,6 @@ # Sanity Test for new Functionality -**Copy of a TF Plan shoud be submmited with each PR, new functionality/variable should be explicitly added here.** +**Copy of a TF Plan shoud be submmited with each PR, new functionality/variable should be explicitly added here under static values section in the main.tf file.** ### tfvars Example: @@ -11,9 +11,7 @@ vipassword = "fill" vm = { linuxvm = { - vmname = "example-server-linux", vmtemp = "Template name", - instances = 2 is_windows_image = false vmrp = "fill" dc = "fill", @@ -21,57 +19,25 @@ vm = { vmfolder = "fill" vmgateway = "10.13.13.1" dns_servers = ["1.1.1.1"] - data_disk = { - disk1 = { - size_gb = 3, - thin_provisioned = false, - data_disk_scsi_controller = 0, - }, - disk2 = { - size_gb = 4, - thin_provisioned = true, - data_disk_scsi_controller = 1, - storage_policy_id = "D680B3D4-ACBE-40B5-BD9C-2EB1526A5EDD" - }, - disk3 = { - size_gb = 5, - thin_provisioned = true, - data_disk_scsi_controller = 1, - datastore_id = "datastore-90679" - } - disk4 = { - size_gb = 5, - thin_provisioned = true, - unit_number = 30, - datastore_id = "datastore-90679" - } - } network = { "VM Port Group" = ["10.13.13.2", ""], # To use DHCP create Empty list for each instance "VM Port Group" = ["", ""] } - tags = {} - annotation = null }, windowsvm = { - vmname = "example-server-windows", vmtemp = "fill" - instances = 2 is_windows_image = true vmrp = "fill" dc = "fill" vmfolder = "fill" datastore = "fill" dns_servers = null - data_disk = {} vmgateway = "10.13.13.1" network = { "VM Port Group" = ["10.13.13.2", ""], # To use DHCP create Empty list for each instance "VM Port Group" = ["", ""] } } - tags = {} - annotation = null } ``` diff --git a/tests/sanity/main.tf b/tests/sanity/main.tf index 521eab7..dff53af 100644 --- a/tests/sanity/main.tf +++ b/tests/sanity/main.tf @@ -1,3 +1,6 @@ +# This workspace id to test the newly added functionality of the changes. +# +# Testing Tags resource "vsphere_tag_category" "category" { name = "terraform-test-category" cardinality = "SINGLE" @@ -14,59 +17,71 @@ resource "vsphere_tag" "tag" { category_id = vsphere_tag_category.category.id description = "Managed by Terraform" } - +#to test naming convention variable "env" { default = "dev" } +#Do not add any new variables here unless it is sensitive variable "vm" { type = map(object({ - vmname = string - vmtemp = string - dc = string - vmrp = string - vmfolder = string - datastore = string - is_windows_image = bool - tags = map(string) - instances = number - network = map(list(string)) - vmgateway = string - dns_servers = list(string) - data_disk = map(map(string)) - cpu_share_level = string - cpu_share_count = number - memory_share_level = string - memory_share_count = number - io_reservation = list(number) - io_share_level = list(string) - io_share_count = list(number) + vmname = string + vmtemp = string + dc = string + vmrp = string + vmfolder = string + datastore = string + is_windows_image = bool + network = map(list(string)) + vmgateway = string + dns_servers = list(string) })) } +#add the new added function/variables here module "example-server-basic" { source = "../../" for_each = var.vm - vmnameformat = "%03d${var.env}" - tag_depends_on = [vsphere_tag.tag.id] - tags = each.value.tags - vmtemp = each.value.vmtemp - is_windows_image = each.value.is_windows_image - instances = each.value.instances - vmname = each.value.vmname vmrp = each.value.vmrp vmfolder = each.value.vmfolder + vmtemp = each.value.vmtemp + is_windows_image = each.value.is_windows_image network = each.value.network vmgateway = each.value.vmgateway dc = each.value.dc datastore = each.value.datastore - data_disk = each.value.data_disk - cpu_share_level = each.value.cpu_share_level - # cpu_share_count = each.value.cpu_share_level == "custom" ? each.value.cpu_share_count : null - # memory_share_level = each.value.memory_share_level - # memory_share_count = each.value.memory_share_level == "custom" ? each.value.memory_share_count : null - # io_share_level = each.value.io_share_level - # io_share_count = each.value.io_share_level == "custom" ? each.value.io_share_count : null + #starting of static values + instances = 2 + vmnameformat = "%03d${var.env}" + vmname = "terraform-sanitytest" + annotation = "Terraform Sanity Test" + tag_depends_on = [vsphere_tag.tag.id] + tags = { + "terraform-test-category" = "terraform-test-tag", + } + data_disk = { + disk1 = { + size_gb = 30, + thin_provisioned = false, + data_disk_scsi_controller = 0, + storage_policy_id = "ff45cc66-b624-4621-967f-1aef6437f568" + }, + disk2 = { + size_gb = 70, + thin_provisioned = true, + data_disk_scsi_controller = 1, + io_reservation = 15 + io_share_level = "custom" + io_share_count = 2000 + } + } + io_reservation = [15] + io_share_level = ["custom"] + io_share_count = [2000] + memory_share_level = "custom" + memory_share_count = 2000 + cpu_share_level = "custom" + cpu_share_count = 2000 } output "DC_ID" { diff --git a/tests/smoke/main.tf b/tests/smoke/main.tf index ae072bd..f6464e2 100644 --- a/tests/smoke/main.tf +++ b/tests/smoke/main.tf @@ -1,3 +1,8 @@ +####################################### +# This workspace is for smoke test +# do not modify this file +# ##################################### + variable "vm" { type = map(object({ vmname = string