Skip to content

Commit fc85e56

Browse files
castorskytenthirtyam
authored andcommitted
review: code fixed
- Made minor changes to documentation. - Standard `errors` and `fmt` were used for custom errors. - field `Node` was renamed to `Host`. - field `VmTags` was renamed to `Tags` - package `virtual_machine` was renamed to `virtualmachine` - `driver` and `testing` were moved to `common` location
1 parent 08527f1 commit fc85e56

File tree

24 files changed

+618
-587
lines changed

24 files changed

+618
-587
lines changed

.web-docs/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ packer plugins install github.com/hashicorp/vsphere
5151

5252
#### Data Sources
5353

54-
- [vsphere-virtual_machine](/packer/integrations/hashicorp/vsphere/latest/components/data-source/vsphere-virtual_machine) -
55-
This datasource returns name of existing virtual machine that matches all defined filters to use
56-
it as a builder source for `vsphere-clone`.
54+
- [vsphere-virtualmachine](/packer/integrations/hashicorp/vsphere/latest/components/data-source/vsphere-virtualmachine) -
55+
This data source returns the name of a virtual machine that matches all defined filters.
5756

5857
#### Post-Processors
5958

.web-docs/components/data-source/virtual_machine/README.md

Lines changed: 0 additions & 155 deletions
This file was deleted.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Type: `vsphere-virtualmachine`
2+
Artifact BuilderId: `vsphere.virtualmachine`
3+
4+
This data source retrieves information about existing virtual machines from vSphere
5+
and return name of one virtual machine that matches all specified filters. This virtual
6+
machine can be used in the vSphere Clone builder to select a template.
7+
8+
## Configuration Reference
9+
10+
### Filters Configuration
11+
12+
**Optional:**
13+
14+
<!-- Code generated from the comments of the Config struct in datasource/virtualmachine/data.go; DO NOT EDIT MANUALLY -->
15+
16+
- `name` (string) - Basic filter with glob support (e.g. `ubuntu_basic*`). Defaults to `*`.
17+
Using strict globs will not reduce execution time because vSphere API
18+
returns the full inventory. But can be used for better readability over
19+
regular expressions.
20+
21+
- `name_regex` (string) - Extended name filter with regular expressions support
22+
(e.g. `ubuntu[-_]basic[0-9]*`). Default is empty. The match of the
23+
regular expression is checked by substring. Use `^` and `$` to define a
24+
full string. For example, the `^[^_]+$` filter will search names
25+
without any underscores. The expression must use
26+
[Go Regex Syntax](https://pkg.go.dev/regexp/syntax).
27+
28+
- `template` (bool) - Filter to return only objects that are virtual machine templates.
29+
Defaults to `false` and returns all virtual machines.
30+
31+
- `host` (string) - Filter to search virtual machines only on the specified ESX host.
32+
33+
- `tags` ([]Tag) - Filter to return only that virtual machines that have attached all
34+
specifies tags. Specify one or more `tags` blocks to define list of tags
35+
for the filter.
36+
37+
- `latest` (bool) - This filter determines how to handle multiple machines that were
38+
matched with all previous filters. Machine creation time is being used
39+
to find latest. By default, multiple matching machines results in an
40+
error.
41+
42+
<!-- End of code generated from the comments of the Config struct in datasource/virtualmachine/data.go; -->
43+
44+
45+
### Tags Filter Configuration
46+
47+
<!-- Code generated from the comments of the Tag struct in datasource/virtualmachine/data.go; DO NOT EDIT MANUALLY -->
48+
49+
HCL Example:
50+
51+
```hcl
52+
53+
tags {
54+
category = "team"
55+
name = "operations"
56+
}
57+
tags {
58+
category = "sla"
59+
name = "gold"
60+
}
61+
62+
```
63+
64+
<!-- End of code generated from the comments of the Tag struct in datasource/virtualmachine/data.go; -->
65+
66+
67+
**Required:**
68+
69+
<!-- Code generated from the comments of the Tag struct in datasource/virtualmachine/data.go; DO NOT EDIT MANUALLY -->
70+
71+
- `name` (string) - Name of the tag added to virtual machine which must pass the `tags`
72+
filter.
73+
74+
- `category` (string) - Name of the tag category that contains the tag.
75+
76+
-> **Note:** Both `name` and `category` must be specified in the `tags`
77+
filter.
78+
79+
<!-- End of code generated from the comments of the Tag struct in datasource/virtualmachine/data.go; -->
80+
81+
82+
### Connection Configuration
83+
84+
**Optional:**
85+
86+
<!-- Code generated from the comments of the ConnectConfig struct in builder/vsphere/common/step_connect.go; DO NOT EDIT MANUALLY -->
87+
88+
- `vcenter_server` (string) - The fully qualified domain name or IP address of the vCenter Server
89+
instance.
90+
91+
- `username` (string) - The username to authenticate with the vCenter Server instance.
92+
93+
- `password` (string) - The password to authenticate with the vCenter Server instance.
94+
95+
- `insecure_connection` (bool) - Do not validate the certificate of the vCenter Server instance.
96+
Defaults to `false`.
97+
98+
-> **Note:** This option is beneficial in scenarios where the certificate
99+
is self-signed or does not meet standard validation criteria.
100+
101+
- `datacenter` (string) - The name of the datacenter object in the vSphere inventory.
102+
103+
-> **Note:** Required if more than one datacenter object exists in the
104+
vSphere inventory.
105+
106+
<!-- End of code generated from the comments of the ConnectConfig struct in builder/vsphere/common/step_connect.go; -->
107+
108+
109+
## Output
110+
111+
<!-- Code generated from the comments of the DatasourceOutput struct in datasource/virtualmachine/data.go; DO NOT EDIT MANUALLY -->
112+
113+
- `vm_name` (string) - Name of the found virtual machine.
114+
115+
<!-- End of code generated from the comments of the DatasourceOutput struct in datasource/virtualmachine/data.go; -->
116+
117+
118+
## Example Usage
119+
120+
This example demonstrates how to connect to vSphere cluster and search for the latest virtual machine
121+
that matches the filters. The name of the machine is then output to the console as an output variable.
122+
```hcl
123+
data "vsphere-virtualmachine" "default" {
124+
vcenter_server = "vcenter.example.com"
125+
insecure_connection = true
126+
username = "[email protected]"
127+
password = "VMware1!"
128+
datacenter = "dc-01"
129+
latest = true
130+
tags {
131+
category = "team"
132+
name = "operations"
133+
}
134+
tags {
135+
category = "sla"
136+
name = "gold"
137+
}
138+
139+
}
140+
141+
locals {
142+
vm_name = data.vsphere-virtualmachine.default.vm_name
143+
}
144+
145+
source "null" "example" {
146+
communicator = "none"
147+
}
148+
149+
build {
150+
sources = [
151+
"source.null.example"
152+
]
153+
154+
provisioner "shell-local" {
155+
inline = [
156+
"echo vm_name: ${local.vm_name}",
157+
]
158+
}
159+
}
160+
```

.web-docs/metadata.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ integration {
3636
component {
3737
type = "data-source"
3838
name = "vSphere Virtual Machine"
39-
slug = "vsphere-virtual_machine"
39+
slug = "vsphere-virtualmachine"
4040
}
4141
}

builder/vsphere/driver/vm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig)
449449
Device: adapter.(types.BaseVirtualDevice),
450450
Operation: types.VirtualDeviceConfigSpecOperationEdit,
451451
}
452-
453452
configSpec.DeviceChange = append(configSpec.DeviceChange, config)
454453
}
455454

0 commit comments

Comments
 (0)