WIP : Add instance resource and data source
This breaks in the data source since a number of the maps, eg. beparams, contain key/value paires where the values can have differing type (eg. string, bool, int, ...). I haven't seen a way to specify that the map value may be of any type.
This commit is contained in:
parent
a4a1bc5f1f
commit
cfe445a761
|
@ -14,3 +14,9 @@ data "ganeti_networks" "all" {}
|
|||
output "all_networks" {
|
||||
value = data.ganeti_networks.all.networks
|
||||
}
|
||||
|
||||
|
||||
data "ganeti_instances" "all" {}
|
||||
output "instance" {
|
||||
value = data.ganeti_instances.all.instances
|
||||
}
|
||||
|
|
|
@ -0,0 +1,242 @@
|
|||
package ganeti
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
rapi "burntworld.ca/go-rapi-client"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceInstance() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
ReadContext: dataSourceInstanceRead,
|
||||
Schema: map[string]*schema.Schema{
|
||||
"instances": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"disk_usage": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"oper_vcpus": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"network_port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"serial_no": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ctime": &schema.Schema{
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"mtime": &schema.Schema{
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"oper_state": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"disk_template": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"oper_ram": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pnode": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"admin_state": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"os": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"nic.uuids": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic_modes": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.names": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.networks.names": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"disk.spindles": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"disk.uuids": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"disk.sizes": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"tags": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.networks": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.macs": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString
|
||||
},
|
||||
},
|
||||
"nic.bridges": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.ips": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"nic.links": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Deprecated: "to satisfy terraform?",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"snodes": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"hvparams": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"beparams": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"custom_hvparams": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"custom_beparams": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"custom_nicparams": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
var diags diag.Diagnostics
|
||||
client := m.(*rapi.Client)
|
||||
instances, err := client.GetInstancesBulk()
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if err = d.Set("instances", instances); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
return diags;
|
||||
}
|
|
@ -42,6 +42,7 @@ func Provider() *schema.Provider {
|
|||
ConfigureContextFunc: providerConfigure,
|
||||
DataSourcesMap: map[string]*schema.Resource {
|
||||
"ganeti_networks": dataSourceNetworks(),
|
||||
"ganeti_instances": dataSourceInstance(),
|
||||
},
|
||||
ResourcesMap: map[string]*schema.Resource{},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package ganeti
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
rapi "burntworld.ca/go-rapi-client"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceInstance() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
CreateContext: resourceInstanceCreate,
|
||||
ReadContext: resourceInstanceRead,
|
||||
UpdateContext: resourceInstanceUpdate,
|
||||
DeleteContext: resourceInstanceDelete,
|
||||
}
|
||||
}
|
||||
|
||||
func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
// Warning or errors can be collected in a slice type
|
||||
var diags diag.Diagnostics
|
||||
return diags
|
||||
}
|
||||
|
||||
func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
// Warning or errors can be collected in a slice type
|
||||
var diags diag.Diagnostics
|
||||
client := m.(*rapi.Client)
|
||||
instances, err := client.GetInstancesBulk()
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if err = d.Set("instances", instances); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
return diags
|
||||
}
|
||||
|
||||
func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
return resourceInstanceRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
// Warning or errors can be collected in a slice type
|
||||
var diags diag.Diagnostics
|
||||
|
||||
return diags
|
||||
}
|
Loading…
Reference in New Issue