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
|
||||
* `addresses` - The IP addresses
|
||||
* `digest` - The SHA1 digest
|
||||
* `entries` - The entries (conversion of `addresses` and `hostnames` into objects)
|
||||
* `hostnames` - The hostnames associated with each of the IP addresses
|
||||
|
||||
##### 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}"
|
||||
}
|
||||
|
||||
output "data_proxmox_virtual_environment_hosts_example_entries" {
|
||||
value = "${data.proxmox_virtual_environment_hosts.example.entries}"
|
||||
}
|
||||
|
||||
output "data_proxmox_virtual_environment_hosts_example_hostnames" {
|
||||
value = "${data.proxmox_virtual_environment_hosts.example.hostnames}"
|
||||
}
|
||||
|
@ -12,10 +12,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
mkDataSourceVirtualEnvironmentHostsAddresses = "addresses"
|
||||
mkDataSourceVirtualEnvironmentHostsDigest = "digest"
|
||||
mkDataSourceVirtualEnvironmentHostsHostnames = "hostnames"
|
||||
mkDataSourceVirtualEnvironmentHostsNodeName = "node_name"
|
||||
mkDataSourceVirtualEnvironmentHostsAddresses = "addresses"
|
||||
mkDataSourceVirtualEnvironmentHostsDigest = "digest"
|
||||
mkDataSourceVirtualEnvironmentHostsEntries = "entries"
|
||||
mkDataSourceVirtualEnvironmentHostsEntriesAddress = "address"
|
||||
mkDataSourceVirtualEnvironmentHostsEntriesHostnames = "hostnames"
|
||||
mkDataSourceVirtualEnvironmentHostsHostnames = "hostnames"
|
||||
mkDataSourceVirtualEnvironmentHostsNodeName = "node_name"
|
||||
)
|
||||
|
||||
func dataSourceVirtualEnvironmentHosts() *schema.Resource {
|
||||
@ -32,6 +35,26 @@ func dataSourceVirtualEnvironmentHosts() *schema.Resource {
|
||||
Description: "The SHA1 digest",
|
||||
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{
|
||||
Type: schema.TypeList,
|
||||
Description: "The hostnames",
|
||||
@ -70,6 +93,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
||||
|
||||
// Parse the entries in the hosts file.
|
||||
addresses := []interface{}{}
|
||||
entries := []interface{}{}
|
||||
hostnames := []interface{}{}
|
||||
lines := strings.Split(hosts.Data, "\n")
|
||||
|
||||
@ -86,6 +110,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
||||
}
|
||||
|
||||
addresses = append(addresses, values[0])
|
||||
entry := map[string]interface{}{}
|
||||
hostnamesForAddress := []interface{}{}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -105,6 +134,7 @@ func dataSourceVirtualEnvironmentHostsRead(d *schema.ResourceData, m interface{}
|
||||
d.Set(mkDataSourceVirtualEnvironmentHostsDigest, "")
|
||||
}
|
||||
|
||||
d.Set(mkDataSourceVirtualEnvironmentHostsEntries, entries)
|
||||
d.Set(mkDataSourceVirtualEnvironmentHostsHostnames, hostnames)
|
||||
|
||||
return nil
|
||||
|
@ -29,18 +29,36 @@ func TestDataSourceVirtualEnvironmentHostsSchema(t *testing.T) {
|
||||
testComputedAttributes(t, s, []string{
|
||||
mkDataSourceVirtualEnvironmentHostsAddresses,
|
||||
mkDataSourceVirtualEnvironmentHostsDigest,
|
||||
mkDataSourceVirtualEnvironmentHostsEntries,
|
||||
mkDataSourceVirtualEnvironmentHostsHostnames,
|
||||
})
|
||||
|
||||
testSchemaValueTypes(t, s, []string{
|
||||
mkDataSourceVirtualEnvironmentHostsAddresses,
|
||||
mkDataSourceVirtualEnvironmentHostsDigest,
|
||||
mkDataSourceVirtualEnvironmentHostsEntries,
|
||||
mkDataSourceVirtualEnvironmentHostsHostnames,
|
||||
mkDataSourceVirtualEnvironmentHostsNodeName,
|
||||
}, []schema.ValueType{
|
||||
schema.TypeList,
|
||||
schema.TypeString,
|
||||
schema.TypeList,
|
||||
schema.TypeList,
|
||||
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