2020-10-24 18:53:11 +00:00
|
|
|
package ganeti
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
rapi "burntworld.ca/go-rapi-client"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func dataSourceNetworks() *schema.Resource {
|
2020-10-25 01:26:54 +00:00
|
|
|
return &schema.Resource{
|
2020-10-24 18:53:11 +00:00
|
|
|
ReadContext: dataSourceNetworksRead,
|
2020-10-25 01:26:54 +00:00
|
|
|
Schema: map[string]*schema.Schema{
|
2020-10-24 18:53:11 +00:00
|
|
|
"networks": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeList,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
Elem: &schema.Resource{
|
2020-10-25 01:26:54 +00:00
|
|
|
Schema: map[string]*schema.Schema{
|
2020-10-24 18:53:11 +00:00
|
|
|
"name": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"ctime": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeFloat,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"external_reservations": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"free_count": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeInt,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"gateway": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"gateway6": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"group_list": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeList,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
2020-10-25 01:26:54 +00:00
|
|
|
Elem: &schema.Schema{
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Elemb: &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
},
|
2020-10-24 18:53:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"inst_list": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeList,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
2020-10-25 01:26:54 +00:00
|
|
|
Elem: &schema.Schema{
|
2020-10-24 18:53:11 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"mac_prefix": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"map": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"mtime": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeFloat,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"network": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"network6": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"reserved_count": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeInt,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"serial_no": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeInt,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
"tags": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeList,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
2020-10-25 01:26:54 +00:00
|
|
|
Elem: &schema.Schema{
|
2020-10-24 18:53:11 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"uuid": &schema.Schema{
|
2020-10-25 01:26:54 +00:00
|
|
|
Type: schema.TypeString,
|
2020-10-24 18:53:11 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dataSourceNetworksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
|
|
|
client := m.(*rapi.Client)
|
|
|
|
var diags diag.Diagnostics
|
|
|
|
networks, err := client.GetNetworksBulk()
|
|
|
|
if err != nil {
|
|
|
|
return diag.FromErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = d.Set("networks", networks); err != nil {
|
|
|
|
return diag.FromErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// always run
|
|
|
|
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
|
|
|
|
|
|
|
|
return diags
|
|
|
|
}
|