@@ -91,6 +91,10 @@ type Datasource struct {
9191type DatasourceOutput struct {
9292 // Identifier of the found guest.
9393 VmId uint `mapstructure:"vm_id"`
94+ // Name of the found guest.
95+ VmName string `mapstructure:"vm_name"`
96+ // Tags of the found guest separated with semicolon.
97+ VmTags string `mapstructure:"vm_tags"`
9498}
9599
96100type vmConfig map [string ]interface {}
@@ -162,6 +166,7 @@ func (d *Datasource) OutputSpec() hcldec.ObjectSpec {
162166func (d * Datasource ) Execute () (cty.Value , error ) {
163167 // This value of VM ID the function should return
164168 var vmId uint
169+ var vmName , vmTags string
165170
166171 client , err := newProxmoxClient (d .config )
167172 if err != nil {
@@ -190,15 +195,21 @@ func (d *Datasource) Execute() (cty.Value, error) {
190195 }
191196
192197 vmId = latestConfig ["vmid" ].(uint )
198+ vmName = latestConfig ["name" ].(string )
199+ vmTags = latestConfig ["tags" ].(string )
193200 } else {
194201 if len (filteredVms ) > 1 {
195202 return cty .NullVal (cty .EmptyObject ), errors .New ("more than one guest passed filters, cannot return vm_id" )
196203 }
197204 vmId = filteredVms [0 ].Id
205+ vmName = filteredVms [0 ].Name
206+ vmTags = joinTags (filteredVms [0 ].Tags , ";" )
198207 }
199208
200209 output := DatasourceOutput {
201- VmId : vmId ,
210+ VmId : vmId ,
211+ VmName : vmName ,
212+ VmTags : vmTags ,
202213 }
203214 return hcl2helper .HCL2ValueFromConfig (output , d .OutputSpec ()), nil
204215}
@@ -391,3 +402,11 @@ func parseMetaField(field string) (int, error) {
391402 }
392403 return value , nil
393404}
405+
406+ func joinTags (tags []proxmox.Tag , separator string ) string {
407+ tagsAsStrings := make ([]string , len (tags ))
408+ for i , tag := range tags {
409+ tagsAsStrings [i ] = string (tag )
410+ }
411+ return strings .Join (tagsAsStrings , separator )
412+ }
0 commit comments