Skip to content

Commit

Permalink
Simplified the Sanity test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Arman Keyoumarsi committed Jul 6, 2021
1 parent 490558f commit a833107
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 70 deletions.
36 changes: 1 addition & 35 deletions tests/sanity/README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -11,67 +11,33 @@ vipassword = "fill"
vm = {
linuxvm = {
vmname = "example-server-linux",
vmtemp = "Template name",
instances = 2
is_windows_image = false
vmrp = "fill"
dc = "fill",
datastore = "fill"
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
}
```

85 changes: 50 additions & 35 deletions tests/sanity/main.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" {
Expand Down
5 changes: 5 additions & 0 deletions tests/smoke/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#######################################
# This workspace is for smoke test
# do not modify this file
# #####################################

variable "vm" {
type = map(object({
vmname = string
Expand Down

0 comments on commit a833107

Please sign in to comment.