add parameters for /nodes/{n}/lxc

This commit is contained in:
Andreas Gruhler 2019-06-05 22:32:29 +02:00
parent 97851be443
commit aab63df6e4
2 changed files with 258 additions and 30 deletions

View File

@ -6,18 +6,18 @@ provider "proxmox" {
} }
resource "proxmox_lxc" "lxc-test" { resource "proxmox_lxc" "lxc-test" {
force = true
hostname = "terraform-new-container" hostname = "terraform-new-container"
ostemplate = "shared:vztmpl/centos-7-default_20171212_amd64.tar.xz" network {
target_node = "node-01"
network = {
id = 0 id = 0
name = "eth0" name = "eth0"
bridge = "vmbr0" bridge = "vmbr0"
ip = "dhcp" ip = "dhcp"
ip6 = "dhcp" ip6 = "dhcp"
} }
storage = "local-lvm" ostemplate = "shared:vztmpl/centos-7-default_20171212_amd64.tar.xz"
pool = "terraform"
password = "rootroot" password = "rootroot"
force = true pool = "terraform"
storage = "local-lvm"
target_node = "node-01"
} }

View File

@ -22,54 +22,282 @@ func resourceLxc() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
}, },
"force": { "arch": {
Type: schema.TypeString,
Optional: true,
Default: "amd64",
},
"bwlimit": {
Type: schema.TypeInt,
Optional: true,
},
"cmode": {
Type: schema.TypeString,
Optional: true,
Default: "tty",
},
"console": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false, Default: true,
}, },
"hostname": { "cores": {
Type: schema.TypeInt,
Optional: true,
},
"cpulimit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"cpuunits": {
Type: schema.TypeInt,
Optional: true,
Default: 1024,
},
"description": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
}, },
"networks": &schema.Schema{ "features": {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "fuse": {
Type: schema.TypeString, Type: schema.TypeBool,
Required: true, Required: true,
}, },
"bridge": &schema.Schema{ "keyctl": {
Type: schema.TypeString, Type: schema.TypeBool,
Optional: true, Required: true,
Default: "vmbr0",
}, },
"ip": &schema.Schema{ "mount": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "dhcp",
}, },
"ip6": &schema.Schema{ "nesting": {
Type: schema.TypeString, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: "dhcp",
}, },
}, },
}, },
}, },
"force": {
Type: schema.TypeBool,
Optional: true,
},
"hookscript": {
Type: schema.TypeString,
Optional: true,
},
"hostname": {
Type: schema.TypeString,
Optional: true,
},
"ignore_unpack_errors": {
Type: schema.TypeBool,
Optional: true,
},
"lock": {
Type: schema.TypeString,
Optional: true,
},
"memory": {
Type: schema.TypeInt,
Optional: true,
Default: 512,
},
"mountpoints": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"volume": {
Type: schema.TypeString,
Required: true,
},
"mp": {
Type: schema.TypeString,
Required: true,
},
"acl": {
Type: schema.TypeBool,
Optional: true,
},
"backup": {
Type: schema.TypeBool,
Optional: true,
},
"quota": {
Type: schema.TypeBool,
Optional: true,
},
"replicate": {
Type: schema.TypeBool,
Optional: true,
},
"shared": {
Type: schema.TypeBool,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
"nameserver": {
Type: schema.TypeString,
Optional: true,
},
"network": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"bridge": {
Type: schema.TypeString,
Optional: true,
},
"firewall": {
Type: schema.TypeBool,
Optional: true,
},
"gw": {
Type: schema.TypeBool,
Optional: true,
},
"gw6": {
Type: schema.TypeBool,
Optional: true,
},
"hwaddr": {
Type: schema.TypeBool,
Optional: true,
},
"ip": {
Type: schema.TypeString,
Optional: true,
},
"ip6": {
Type: schema.TypeString,
Optional: true,
},
"mtu": {
Type: schema.TypeString,
Optional: true,
},
"rate": {
Type: schema.TypeInt,
Optional: true,
},
"tag": {
Type: schema.TypeInt,
Optional: true,
},
"trunks": {
Type: schema.TypeString,
Optional: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"onboot": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"ostype": {
Type: schema.TypeString,
Optional: true,
},
"password": { "password": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
}, },
"pool": { "pool": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
},
"protection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"restore": {
Type: schema.TypeBool,
Optional: true,
},
"rootfs": {
Type: schema.TypeString,
Optional: true,
},
"searchdomain": {
Type: schema.TypeString,
Optional: true,
},
"ssh_public_keys": {
Type: schema.TypeString,
Optional: true,
},
"start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"startup": {
Type: schema.TypeString,
Optional: true,
}, },
"storage": { "storage": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "local-lvm", Default: "local",
},
"swap": {
Type: schema.TypeInt,
Optional: true,
Default: 512,
},
"template": {
Type: schema.TypeBool,
Optional: true,
},
"tty": {
Type: schema.TypeInt,
Optional: true,
Default: 2,
},
"unique": {
Type: schema.TypeBool,
Optional: true,
},
"unprivileged": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"unused": {
Type: schema.TypeString,
Optional: true,
}, },
"target_node": { "target_node": {
Type: schema.TypeString, Type: schema.TypeString,
@ -85,7 +313,7 @@ func resourceLxcCreate(d *schema.ResourceData, meta interface{}) error {
pmParallelBegin(pconf) pmParallelBegin(pconf)
client := pconf.Client client := pconf.Client
vmName := d.Get("hostname").(string) vmName := d.Get("hostname").(string)
networks := d.Get("networks").(*schema.Set) networks := d.Get("network").(*schema.Set)
lxcNetworks := DevicesSetToMap(networks) lxcNetworks := DevicesSetToMap(networks)
config := pxapi.NewConfigLxc() config := pxapi.NewConfigLxc()