initial commit
This commit is contained in:
commit
4510ee9073
|
@ -0,0 +1 @@
|
|||
terraform-provider-proxmox
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,11 @@
|
|||
# Proxmox 4 Terraform
|
||||
|
||||
Terraform provider plugin for proxmox
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
go build -o terraform-provider-proxmox
|
||||
```
|
||||
|
||||
## Work in progress
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/Telmate/terraform-provider-proxmox/proxmox"
|
||||
"github.com/hashicorp/terraform/plugin"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func main() {
|
||||
plugin.Serve(&plugin.ServeOpts{
|
||||
ProviderFunc: func() terraform.ResourceProvider {
|
||||
return proxmox.Provider()
|
||||
},
|
||||
})
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
type providerConfiguration struct {
|
||||
Client *pxapi.Client
|
||||
}
|
||||
|
||||
func Provider() *schema.Provider {
|
||||
return &schema.Provider{
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pm_user": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("PM_USER", nil),
|
||||
Description: "username, maywith with @pam",
|
||||
},
|
||||
"pm_password": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("PM_PASS", nil),
|
||||
Description: "secret",
|
||||
},
|
||||
"pm_api_url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("PM_API_URL", nil),
|
||||
Description: "https://host.fqdn:8006/api2/json",
|
||||
},
|
||||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"vm_qemu": resourceVmQemu(),
|
||||
// TODO - storage_iso
|
||||
// TODO - bridge
|
||||
// TODO - vm_qemu_template
|
||||
},
|
||||
|
||||
ConfigureFunc: providerConfigure,
|
||||
}
|
||||
}
|
||||
|
||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
client, _ := pxapi.NewClient(d.Get("pm_api_url").(string), nil, nil)
|
||||
err := client.Login(d.Get("pm_user").(string), d.Get("pm_password").(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &providerConfiguration{
|
||||
Client: client,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceVmQemu() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceVmQemuCreate,
|
||||
Read: resourceVmQemuRead,
|
||||
Update: resourceVmQemuUpdate,
|
||||
Delete: resourceVmQemuDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"vmid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Required: false,
|
||||
},
|
||||
// memory
|
||||
// diskGB
|
||||
// storage
|
||||
// os
|
||||
// cores
|
||||
// sockets
|
||||
// iso
|
||||
// nic
|
||||
// bridge
|
||||
// vlan
|
||||
}}
|
||||
}
|
||||
|
||||
func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*providerConfiguration).Client
|
||||
config := pxapi.ConfigQemu{
|
||||
Name: d.Get("Name").(string),
|
||||
Description: d.Get("desc").(string),
|
||||
}
|
||||
vmr := pxapi.NewVmRef(d.Get("vmid").(int))
|
||||
config.CreateVm(vmr, client)
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*providerConfiguration).Client
|
||||
vmr := pxapi.NewVmRef(d.Get("vmid").(int))
|
||||
_, err := client.DeleteVm(vmr)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue