mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-02 03:22:59 +00:00
Add entries attribute to hosts data source
This commit is contained in:
parent
2d824e37bc
commit
9ac2a3eba9
@ -155,6 +155,7 @@ This data source doesn't accept arguments.
|
|||||||
###### Attributes
|
###### Attributes
|
||||||
* `addresses` - The IP addresses
|
* `addresses` - The IP addresses
|
||||||
* `digest` - The SHA1 digest
|
* `digest` - The SHA1 digest
|
||||||
|
* `entries` - The entries (conversion of `addresses` and `hostnames` into objects)
|
||||||
* `hostnames` - The hostnames associated with each of the IP addresses
|
* `hostnames` - The hostnames associated with each of the IP addresses
|
||||||
|
|
||||||
##### Nodes (proxmox_virtual_environment_nodes)
|
##### Nodes (proxmox_virtual_environment_nodes)
|
||||||
|
@ -10,6 +10,10 @@ output "data_proxmox_virtual_environment_hosts_example_digest" {
|
|||||||
value = "${data.proxmox_virtual_environment_hosts.example.digest}"
|
value = "${data.proxmox_virtual_environment_hosts.example.digest}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_hosts_example_entries" {
|
||||||
|
value = "${data.proxmox_virtual_environment_hosts.example.entries}"
|
||||||
|
}
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_hosts_example_hostnames" {
|
output "data_proxmox_virtual_environment_hosts_example_hostnames" {
|
||||||
value = "${data.proxmox_virtual_environment_hosts.example.hostnames}"
|
value = "${data.proxmox_virtual_environment_hosts.example.hostnames}"
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ import (
|
|||||||
const (
|
const (
|
||||||
mkDataSourceVirtualEnvironmentHostsAddresses = "addresses"
|
mkDataSourceVirtualEnvironmentHostsAddresses = "addresses"
|
||||||
mkDataSourceVirtualEnvironmentHostsDigest = "digest"
|
mkDataSourceVirtualEnvironmentHostsDigest = "digest"
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntries = "entries"
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesAddress = "address"
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesHostnames = "hostnames"
|
||||||
mkDataSourceVirtualEnvironmentHostsHostnames = "hostnames"
|
mkDataSourceVirtualEnvironmentHostsHostnames = "hostnames"
|
||||||
mkDataSourceVirtualEnvironmentHostsNodeName = "node_name"
|
mkDataSourceVirtualEnvironmentHostsNodeName = "node_name"
|
||||||
)
|
)
|
||||||
@ -32,6 +35,26 @@ func dataSourceVirtualEnvironmentHosts() *schema.Resource {
|
|||||||
Description: "The SHA1 digest",
|
Description: "The SHA1 digest",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntries: &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Description: "The entries",
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesAddress: {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Description: "The address",
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesHostnames: &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Description: "The hostnames",
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
mkDataSourceVirtualEnvironmentHostsHostnames: &schema.Schema{
|
mkDataSourceVirtualEnvironmentHostsHostnames: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The hostnames",
|
Description: "The hostnames",
|
||||||
@ -70,6 +93,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
|||||||
|
|
||||||
// Parse the entries in the hosts file.
|
// Parse the entries in the hosts file.
|
||||||
addresses := []interface{}{}
|
addresses := []interface{}{}
|
||||||
|
entries := []interface{}{}
|
||||||
hostnames := []interface{}{}
|
hostnames := []interface{}{}
|
||||||
lines := strings.Split(hosts.Data, "\n")
|
lines := strings.Split(hosts.Data, "\n")
|
||||||
|
|
||||||
@ -86,6 +110,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
addresses = append(addresses, values[0])
|
addresses = append(addresses, values[0])
|
||||||
|
entry := map[string]interface{}{}
|
||||||
hostnamesForAddress := []interface{}{}
|
hostnamesForAddress := []interface{}{}
|
||||||
|
|
||||||
for _, hostname := range values[1:] {
|
for _, hostname := range values[1:] {
|
||||||
@ -94,6 +119,10 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry[mkDataSourceVirtualEnvironmentHostsEntriesAddress] = values[0]
|
||||||
|
entry[mkDataSourceVirtualEnvironmentHostsEntriesHostnames] = hostnamesForAddress
|
||||||
|
|
||||||
|
entries = append(entries, entry)
|
||||||
hostnames = append(hostnames, hostnamesForAddress)
|
hostnames = append(hostnames, hostnamesForAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +134,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
|||||||
d.Set(mkDataSourceVirtualEnvironmentHostsDigest, "")
|
d.Set(mkDataSourceVirtualEnvironmentHostsDigest, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set(mkDataSourceVirtualEnvironmentHostsEntries, entries)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentHostsHostnames, hostnames)
|
d.Set(mkDataSourceVirtualEnvironmentHostsHostnames, hostnames)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -29,18 +29,36 @@ func TestDataSourceVirtualEnvironmentHostsSchema(t *testing.T) {
|
|||||||
testComputedAttributes(t, s, []string{
|
testComputedAttributes(t, s, []string{
|
||||||
mkDataSourceVirtualEnvironmentHostsAddresses,
|
mkDataSourceVirtualEnvironmentHostsAddresses,
|
||||||
mkDataSourceVirtualEnvironmentHostsDigest,
|
mkDataSourceVirtualEnvironmentHostsDigest,
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntries,
|
||||||
mkDataSourceVirtualEnvironmentHostsHostnames,
|
mkDataSourceVirtualEnvironmentHostsHostnames,
|
||||||
})
|
})
|
||||||
|
|
||||||
testSchemaValueTypes(t, s, []string{
|
testSchemaValueTypes(t, s, []string{
|
||||||
mkDataSourceVirtualEnvironmentHostsAddresses,
|
mkDataSourceVirtualEnvironmentHostsAddresses,
|
||||||
mkDataSourceVirtualEnvironmentHostsDigest,
|
mkDataSourceVirtualEnvironmentHostsDigest,
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntries,
|
||||||
mkDataSourceVirtualEnvironmentHostsHostnames,
|
mkDataSourceVirtualEnvironmentHostsHostnames,
|
||||||
mkDataSourceVirtualEnvironmentHostsNodeName,
|
mkDataSourceVirtualEnvironmentHostsNodeName,
|
||||||
}, []schema.ValueType{
|
}, []schema.ValueType{
|
||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
|
schema.TypeList,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
entriesSchema := testNestedSchemaExistence(t, s, mkDataSourceVirtualEnvironmentHostsEntries)
|
||||||
|
|
||||||
|
testComputedAttributes(t, entriesSchema, []string{
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesAddress,
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesHostnames,
|
||||||
|
})
|
||||||
|
|
||||||
|
testSchemaValueTypes(t, entriesSchema, []string{
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesAddress,
|
||||||
|
mkDataSourceVirtualEnvironmentHostsEntriesHostnames,
|
||||||
|
}, []schema.ValueType{
|
||||||
|
schema.TypeString,
|
||||||
|
schema.TypeList,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user