Skip to content

Commit

Permalink
Add launch parameters for mem, disk and cloudinit
Browse files Browse the repository at this point in the history
  • Loading branch information
larstobi committed Jun 30, 2022
1 parent 37338e6 commit 5390a6f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
9 changes: 6 additions & 3 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ Multipass instance resource.

### Required

- `name` (String)
- `name` (String) Name for the instance. If it is 'primary' (the configured primary instance name), the user's home directory is mounted inside the newly launched instance, in 'Home'.

### Optional

- `cpus` (Number)
- `image` (String)
- `cloudinit_file` (String) Path to a user-data cloud-init configuration.
- `cpus` (Number) Number of CPUs to allocate. Minimum: 1, default: 1.
- `disk` (String) Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 512M, default: 5G.
- `image` (String) Optional image to launch. If omitted, then the default Ubuntu LTS will be used. <remote> can be either ‘release’ or ‘daily‘. If <remote> is omitted, ‘release’ will be used. <image> can be a partial image hash or an Ubuntu release version, codename or alias. <url> is a custom image URL that is in http://, https://, or file:// format.
- `memory` (String) Amount of memory to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G.

### Read-Only

Expand Down
46 changes: 39 additions & 7 deletions multipass/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,52 @@ func resourceInstance() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Description: "Name for the instance. If it is 'primary' " +
"(the configured primary instance name), the user's " +
"home directory is mounted inside the newly launched " +
"instance, in 'Home'.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"image": {
Description: "Optional image to launch. If omitted, then " +
"the default Ubuntu LTS will be used. <remote> can be " +
"either ‘release’ or ‘daily‘. If <remote> is " +
"omitted, ‘release’ will be used. <image> can be a " +
"partial image hash or an Ubuntu release version, " +
"codename or alias. <url> is a custom image URL " +
"that is in http://, https://, or file:// format.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"cpus": {
Type: schema.TypeInt,
Description: "Number of CPUs to allocate. Minimum: 1, default: 1.",
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"memory": {
Description: "Amount of memory to allocate. Positive integers, " +
"in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"disk": {
Description: "Disk space to allocate. Positive integers, in bytes, " +
"or with K, M, G suffix. Minimum: 512M, default: 5G.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"cloudinit_file": {
Description: "Path to a user-data cloud-init configuration.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}
Expand All @@ -55,15 +87,15 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa

func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
name := d.Get("name").(string)
image := d.Get("image").(string)
cpus := d.Get("cpus").(int)

d.SetId(name)

_, err := multipass.Launch(&multipass.LaunchReq{
Image: image,
Name: name,
CPU: cpus,
Name: name,
Image: d.Get("image").(string),
CPU: d.Get("cpus").(int),
Memory: d.Get("memory").(string),
Disk: d.Get("disk").(string),
CloudInitFile: d.Get("cloudinit_file").(string),
})

if err != nil {
Expand Down

0 comments on commit 5390a6f

Please sign in to comment.