[clc] add packages to server at create
This commit is contained in:
parent
c93bc5ccb5
commit
8ab63c2d52
|
@ -203,3 +203,26 @@ func parseAdditionalDisks(d *schema.ResourceData) ([]server.Disk, error) {
|
|||
}
|
||||
return disks, nil
|
||||
}
|
||||
|
||||
func parsePackages(d *schema.ResourceData) ([]server.Package, error) {
|
||||
var pkgs []server.Package
|
||||
if e := d.Get("packages"); e != nil {
|
||||
for _, e := range e.([]interface{}) {
|
||||
m := e.(map[string]interface{})
|
||||
id := m["id"].(string)
|
||||
delete(m, "id")
|
||||
ms := make(map[string]string)
|
||||
for k, v := range m {
|
||||
if s, ok := v.(string); ok {
|
||||
ms[k] = s
|
||||
}
|
||||
}
|
||||
p := server.Package{
|
||||
ID: id,
|
||||
Params: ms,
|
||||
}
|
||||
pkgs = append(pkgs, p)
|
||||
}
|
||||
}
|
||||
return pkgs, nil
|
||||
}
|
||||
|
|
|
@ -69,6 +69,11 @@ func resourceCLCServer() *schema.Resource {
|
|||
Optional: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeMap},
|
||||
},
|
||||
"packages": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeMap},
|
||||
},
|
||||
|
||||
// optional: misc state storage. non-CLC field
|
||||
"metadata": &schema.Schema{
|
||||
|
@ -149,6 +154,12 @@ func resourceCLCServerCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
spec.Customfields = fields
|
||||
|
||||
pkgs, err := parsePackages(d)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed setting packages: %v", err)
|
||||
}
|
||||
spec.Packages = pkgs
|
||||
|
||||
resp, err := client.Server.Create(spec)
|
||||
if err != nil || !resp.IsQueued {
|
||||
return fmt.Errorf("Failed creating server: %v", err)
|
||||
|
|
|
@ -105,3 +105,25 @@ up in advance. Each `custom_fields` block supports the following:
|
|||
* `id` - (Required, string) The ID of the custom field to set.
|
||||
* `value` - (Required, string) The value for the specified field.
|
||||
|
||||
<a id="packages"></a>
|
||||
## Packages
|
||||
|
||||
`packages` is a block within the configuration that may be repeated to
|
||||
specify packages and their associated parameters to be run at
|
||||
instantiation. Packages facilitate various tasks like ssh key
|
||||
installation, kernel upgrades, etc. Package ID as well as parameters
|
||||
are configured via this block.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# Configure the CLC Provider
|
||||
provider "clc_server" "ubuntu" {
|
||||
...
|
||||
packages
|
||||
{
|
||||
id = "77abb844-579d-478d-3955-c69ab4a7ba1a"
|
||||
SshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAA..."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue