|
|
@ -94,18 +94,18 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error {
|
|
|
|
// by separate API calls)
|
|
|
|
// by separate API calls)
|
|
|
|
d.Partial(true)
|
|
|
|
d.Partial(true)
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
url_values := &url.Values{}
|
|
|
|
urlValues := &url.Values{}
|
|
|
|
url_values.Add("cloudspaceId", fmt.Sprintf("%d", machine.ResGroupID))
|
|
|
|
urlValues.Add("cloudspaceId", fmt.Sprintf("%d", machine.ResGroupID))
|
|
|
|
url_values.Add("name", machine.Name)
|
|
|
|
urlValues.Add("name", machine.Name)
|
|
|
|
url_values.Add("description", machine.Description)
|
|
|
|
urlValues.Add("description", machine.Description)
|
|
|
|
url_values.Add("vcpus", fmt.Sprintf("%d", machine.Cpu))
|
|
|
|
urlValues.Add("vcpus", fmt.Sprintf("%d", machine.Cpu))
|
|
|
|
url_values.Add("memory", fmt.Sprintf("%d", machine.Ram))
|
|
|
|
urlValues.Add("memory", fmt.Sprintf("%d", machine.Ram))
|
|
|
|
url_values.Add("imageId", fmt.Sprintf("%d", machine.ImageID))
|
|
|
|
urlValues.Add("imageId", fmt.Sprintf("%d", machine.ImageID))
|
|
|
|
url_values.Add("disksize", fmt.Sprintf("%d", machine.BootDisk.Size))
|
|
|
|
urlValues.Add("disksize", fmt.Sprintf("%d", machine.BootDisk.Size))
|
|
|
|
if len(machine.SshKeys) > 0 {
|
|
|
|
if len(machine.SshKeys) > 0 {
|
|
|
|
url_values.Add("userdata", makeSshKeysArgString(machine.SshKeys))
|
|
|
|
urlValues.Add("userdata", makeSshKeysArgString(machine.SshKeys))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
api_resp, err := controller.decortAPICall("POST", MachineCreateAPI, url_values)
|
|
|
|
api_resp, err := controller.decortAPICall("POST", MachineCreateAPI, urlValues)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -218,8 +218,8 @@ func resourceComputeRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
log.Printf("resourceComputeRead: called for VM name %q, ResGroupID %d",
|
|
|
|
log.Printf("resourceComputeRead: called for VM name %q, ResGroupID %d",
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
|
|
|
|
|
|
|
|
comp_facts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
compFacts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
if comp_facts == "" {
|
|
|
|
if compFacts == "" {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -227,7 +227,7 @@ func resourceComputeRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err = flattenCompute(d, comp_facts); err != nil {
|
|
|
|
if err = flattenCompute(d, compFacts); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("resourceComputeRead: after flattenCompute: VM ID %s, VM name %q, ResGroupID %d",
|
|
|
|
log.Printf("resourceComputeRead: after flattenCompute: VM ID %s, VM name %q, ResGroupID %d",
|
|
|
@ -236,12 +236,12 @@ func resourceComputeRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
// Not all parameters, that we may need, are returned by machines/get API
|
|
|
|
// Not all parameters, that we may need, are returned by machines/get API
|
|
|
|
// Continue with further reading of VM subresource parameters:
|
|
|
|
// Continue with further reading of VM subresource parameters:
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
url_values := &url.Values{}
|
|
|
|
urlValues := &url.Values{}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
// Obtain information on external networks
|
|
|
|
// Obtain information on external networks
|
|
|
|
url_values.Add("machineId", d.Id())
|
|
|
|
urlValues.Add("machineId", d.Id())
|
|
|
|
body_string, err := controller.decortAPICall("POST", VmExtNetworksListAPI, url_values)
|
|
|
|
body_string, err := controller.decortAPICall("POST", VmExtNetworksListAPI, urlValues)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -271,10 +271,10 @@ func resourceComputeRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Obtain information on port forwards
|
|
|
|
// Obtain information on port forwards
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
url_values.Add("cloudspaceId", fmt.Sprintf("%d", d.Get("rgid")))
|
|
|
|
urlValues.Add("cloudspaceId", fmt.Sprintf("%d", d.Get("rgid")))
|
|
|
|
url_values.Add("machineId", d.Id())
|
|
|
|
urlValues.Add("machineId", d.Id())
|
|
|
|
pfw_list := PortforwardsResp{}
|
|
|
|
pfw_list := PortforwardsResp{}
|
|
|
|
body_string, err := controller.decortAPICall("POST", PortforwardsListAPI, url_values)
|
|
|
|
body_string, err := controller.decortAPICall("POST", PortforwardsListAPI, urlValues)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -301,24 +301,24 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func resourceComputeDelete(d *schema.ResourceData, m interface{}) error {
|
|
|
|
func resourceComputeDelete(d *schema.ResourceData, m interface{}) error {
|
|
|
|
// NOTE: this method destroys target VM with flag "permanently", so there is no way to
|
|
|
|
// NOTE: this method destroys target Compute instance with flag "permanently", so
|
|
|
|
// restore destroyed VM
|
|
|
|
// there is no way to restore destroyed Compute
|
|
|
|
log.Printf("resourceComputeDelete: called for VM name %q, ResGroupID %d",
|
|
|
|
log.Printf("resourceComputeDelete: called for VM name %q, ResGroupID %d",
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
|
|
|
|
|
|
|
|
comp_facts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
compFacts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
if comp_facts == "" {
|
|
|
|
if compFacts == "" {
|
|
|
|
// the target VM does not exist - in this case according to Terraform best practice
|
|
|
|
// the target Compute does not exist - in this case according to Terraform best practice
|
|
|
|
// we exit from Destroy method without error
|
|
|
|
// we exit from Destroy method without error
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
params := &url.Values{}
|
|
|
|
params := &url.Values{}
|
|
|
|
params.Add("machineId", d.Id())
|
|
|
|
params.Add("computeId", d.Id())
|
|
|
|
params.Add("permanently", "true")
|
|
|
|
params.Add("permanently", "true")
|
|
|
|
|
|
|
|
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
controller := m.(*ControllerCfg)
|
|
|
|
comp_facts, err = controller.decortAPICall("POST", MachineDeleteAPI, params)
|
|
|
|
compFacts, err = controller.decortAPICall("POST", ComputeDeleteAPI, params)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -331,8 +331,8 @@ func resourceComputeExists(d *schema.ResourceData, m interface{}) (bool, error)
|
|
|
|
log.Printf("resourceComputeExist: called for VM name %q, ResGroupID %d",
|
|
|
|
log.Printf("resourceComputeExist: called for VM name %q, ResGroupID %d",
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
d.Get("name").(string), d.Get("rgid").(int))
|
|
|
|
|
|
|
|
|
|
|
|
comp_facts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
compFacts, err := utilityComputeCheckPresence(d, m)
|
|
|
|
if comp_facts == "" {
|
|
|
|
if compFacts == "" {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -363,123 +363,132 @@ func resourceCompute() *schema.Resource {
|
|
|
|
"name": {
|
|
|
|
"name": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
Required: true,
|
|
|
|
Description: "Name of this virtual machine. This parameter is case sensitive.",
|
|
|
|
Description: "Name of this compute. This parameter is case sensitive and must be unique in the resource group.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"rgid": {
|
|
|
|
"rg_id": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Required: true,
|
|
|
|
ValidateFunc: validation.IntAtLeast(1),
|
|
|
|
ValidateFunc: validation.IntAtLeast(1),
|
|
|
|
Description: "ID of the resource group where this virtual machine should be deployed.",
|
|
|
|
Description: "ID of the resource group where this compute should be deployed.",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"arch": {
|
|
|
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
|
|
|
Required: true,
|
|
|
|
|
|
|
|
ForceNew: true,
|
|
|
|
|
|
|
|
Description: "Hardware architecture of this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"cpu": {
|
|
|
|
"cpu": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Required: true,
|
|
|
|
ValidateFunc: validation.IntBetween(1, 64),
|
|
|
|
ValidateFunc: validation.IntBetween(1, 64),
|
|
|
|
Description: "Number of CPUs to allocate to this virtual machine.",
|
|
|
|
Description: "Number of CPUs to allocate to this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"ram": {
|
|
|
|
"ram": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Required: true,
|
|
|
|
ValidateFunc: validation.IntAtLeast(512),
|
|
|
|
ValidateFunc: validation.IntAtLeast(512),
|
|
|
|
Description: "Amount of RAM in MB to allocate to this virtual machine.",
|
|
|
|
Description: "Amount of RAM in MB to allocate to this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"image_id": {
|
|
|
|
"image_id": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Description: "ID of the OS image to base this virtual machine on.",
|
|
|
|
Description: "ID of the OS image to base this compute instance on.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"boot_disk": {
|
|
|
|
"boot_disk_size": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 1,
|
|
|
|
Description: "Size of the boot disk on this compute instance.",
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
|
|
|
Schema: diskSubresourceSchema(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Description: "Specification for a boot disk on this virtual machine.",
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"data_disks": {
|
|
|
|
"extra_disks": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 12,
|
|
|
|
MaxItems: MaxExtraDisksPerCompute,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
Schema: diskSubresourceSchema(),
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "Specification for data disks on this virtual machine.",
|
|
|
|
Description: "Optional list of IDs of the extra disks to attach to this compute.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"guest_logins": {
|
|
|
|
"ssh_keys": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Computed: true,
|
|
|
|
Optional: true,
|
|
|
|
|
|
|
|
MaxItems: MaxSshKeysPerCompute,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: loginsSubresourceSchema(),
|
|
|
|
Schema: sshSubresourceSchemaMake(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "Specification for guest logins on this virtual machine.",
|
|
|
|
Description: "SSH keys to authorize on this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"networks": {
|
|
|
|
"description": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 8,
|
|
|
|
Description: "Description of this compute instance.",
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
|
|
|
Schema: networkSubresourceSchema(),
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "Specification for the networks to connect this virtual machine to.",
|
|
|
|
|
|
|
|
|
|
|
|
// The rest are Compute properties, which are "computed" once it is created
|
|
|
|
|
|
|
|
"rg_name": {
|
|
|
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
|
|
|
Computed: true,
|
|
|
|
|
|
|
|
Description: "Name of the resource group where this compute instance is located.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"nics": {
|
|
|
|
"account_id": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
Computed: true,
|
|
|
|
MaxItems: 8,
|
|
|
|
Description: "ID of the account this compute instance belongs to.",
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
|
|
|
Schema: nicSubresourceSchema(),
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "Specification for the virutal NICs allocated to this virtual machine.",
|
|
|
|
|
|
|
|
|
|
|
|
"account_name": {
|
|
|
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
|
|
|
Computed: true,
|
|
|
|
|
|
|
|
Description: "Name of the account this compute instance belongs to.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"ssh_keys": {
|
|
|
|
"disks": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
MaxItems: 12,
|
|
|
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: sshSubresourceSchema(),
|
|
|
|
Schema: dataSourceDiskSchemaMake(), // ID, type, name, size, account ID, SEP ID, SEP type, pool, status, tech status, compute ID, image ID
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "SSH keys to authorize on this virtual machine.",
|
|
|
|
Description: "Detailed specification for all disks attached to this compute instance (including bood disk).",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"port_forwards": {
|
|
|
|
"interfaces": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
MaxItems: 12,
|
|
|
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: portforwardSubresourceSchema(),
|
|
|
|
Schema: interfaceSubresourceSchemaMake(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: "Specification for the port forwards to configure for this virtual machine.",
|
|
|
|
Description: "Specification for the virtual NICs configured on this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"description": {
|
|
|
|
"guest_logins": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Description: "Description of this virtual machine.",
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
|
|
|
Schema: loginsSubresourceSchemaMake(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Description: "Specification for guest logins on this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"user": {
|
|
|
|
"status": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
Computed: true,
|
|
|
|
Description: "Default login name for the guest OS on this virtual machine.",
|
|
|
|
Description: "Current model status of this compute instance.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
"password": {
|
|
|
|
"tech_status": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
Computed: true,
|
|
|
|
Sensitive: true,
|
|
|
|
Description: "Current technical status of this compute instance.",
|
|
|
|
Description: "Default password for the guest OS login on this virtual machine.",
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|