Skip to content

Commit

Permalink
Added resource 'cloudtemple_compute_iaas_opensource_virtual_machine'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbesret committed Nov 12, 2024
1 parent b5d41c0 commit 130ce7a
Show file tree
Hide file tree
Showing 7 changed files with 617 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/data-sources/compute_iaas_opensource_virtual_machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ To query this datasource you will need the `compute_iaas_opensource_read` role.
- `pool` (List of Object) (see [below for nested schema](#nestedatt--pool))
- `power_state` (String)
- `secure_boot` (Boolean)
- `tools` (List of Object) (see [below for nested schema](#nestedatt--tools))

<a id="nestedatt--addresses"></a>
### Nested Schema for `addresses`
Expand Down Expand Up @@ -86,3 +87,12 @@ Read-Only:
- `name` (String)


<a id="nestedatt--tools"></a>
### Nested Schema for `tools`

Read-Only:

- `detected` (Boolean)
- `version` (String)


125 changes: 125 additions & 0 deletions docs/resources/compute_iaas_opensource_virtual_machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cloudtemple_compute_iaas_opensource_virtual_machine Resource - terraform-provider-cloudtemple"
subcategory: "Compute"
description: |-
Create and manage virtual machines over an Open IaaS infrastructure.
To manage this resource you will need the following roles:
- compute_iaas_opensource_infrastructure_read
- compute_iaas_opensource_infrastructure_write
- compute_iaas_opensource_management
- compute_iaas_opensource_read
- compute_iaas_opensource_virtual_machine_power
- backup_iaas_opensource_read
- backup_iaas_opensource_write
- activity_read
- tag_read
- tag_write
---

# cloudtemple_compute_iaas_opensource_virtual_machine (Resource)

Create and manage virtual machines over an Open IaaS infrastructure.

To manage this resource you will need the following roles:
- `compute_iaas_opensource_infrastructure_read`
- `compute_iaas_opensource_infrastructure_write`
- `compute_iaas_opensource_management`
- `compute_iaas_opensource_read`
- `compute_iaas_opensource_virtual_machine_power`
- `backup_iaas_opensource_read`
- `backup_iaas_opensource_write`
- `activity_read`
- `tag_read`
- `tag_write`



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cpu` (Number) The number of virtual CPUs.
- `memory` (Number) The amount of memory in MB.
- `name` (String) The name of the virtual machine.
- `template_id` (String) The template identifier.

### Optional

- `auto_power_on` (Boolean) Whether to automatically start the virtual machine when the host boots.
- `backup_sla_policies` (Set of String) The IDs of the SLA policies to assign to the virtual machine.
- `boot_order` (List of String) The boot order of the virtual machine.
- `high_availability` (String) HA mode to enable on the virtual machine.
- `host_id` (String) The host identifier.
- `num_cores_per_socket` (Number) The number of cores per socket.
- `power_state` (String) The desired power state of the virtual machine.
- `secure_boot` (Boolean) Whether to enable secure boot.
- `tags` (Map of String) The tags to attach to the virtual machine.

### Read-Only

- `addresses` (List of Object) (see [below for nested schema](#nestedatt--addresses))
- `dvd_drive` (List of Object) (see [below for nested schema](#nestedatt--dvd_drive))
- `host` (List of Object) (see [below for nested schema](#nestedatt--host))
- `id` (String) The ID of this resource.
- `internal_id` (String)
- `machine_manager` (List of Object) (see [below for nested schema](#nestedatt--machine_manager))
- `operating_system_name` (String)
- `pool` (List of Object) (see [below for nested schema](#nestedatt--pool))
- `tools` (List of Object) (see [below for nested schema](#nestedatt--tools))

<a id="nestedatt--addresses"></a>
### Nested Schema for `addresses`

Read-Only:

- `ipv4` (String)
- `ipv6` (String)


<a id="nestedatt--dvd_drive"></a>
### Nested Schema for `dvd_drive`

Read-Only:

- `attached` (Boolean)
- `name` (String)


<a id="nestedatt--host"></a>
### Nested Schema for `host`

Read-Only:

- `id` (String)
- `name` (String)


<a id="nestedatt--machine_manager"></a>
### Nested Schema for `machine_manager`

Read-Only:

- `id` (String)
- `name` (String)


<a id="nestedatt--pool"></a>
### Nested Schema for `pool`

Read-Only:

- `id` (String)
- `name` (String)


<a id="nestedatt--tools"></a>
### Nested Schema for `tools`

Read-Only:

- `detected` (Boolean)
- `version` (String)


11 changes: 11 additions & 0 deletions internal/client/backup_openiaas_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ func (v *BackupOpenIaasPolicyClient) List(ctx context.Context) ([]*BackupOpenIaa

return out, nil
}

type BackupOpenIaasAssignPolicyRequest struct {
VirtualMachineId string `json:"virtualMachineId"`
PolicyIds []string `json:"policyIds"`
}

func (v *BackupOpenIaasPolicyClient) Assign(ctx context.Context, req *BackupOpenIaasAssignPolicyRequest) (string, error) {
r := v.c.newRequest("POST", "/backup/v1/open_iaas/policies/assign")
r.obj = req
return v.c.doRequestAndReturnActivity(ctx, r)
}
61 changes: 60 additions & 1 deletion internal/client/compute_openiaas_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ type OpenIaaSVirtualMachine struct {
CPU int `terraform:"cpu"`
NumCoresPerSocket int `terraform:"num_cores_per_socket"`
Memory int `terraform:"memory"`
Addresses struct {
Tools struct {
Detected bool `terraform:"detected"`
Version string `terraform:"version"`
} `terraform:"tools"`
Addresses struct {
IPv6 string `terraform:"ipv6"`
IPv4 string `terraform:"ipv4"`
} `terraform:"addresses"`
Expand All @@ -50,6 +54,19 @@ type OpenIaaSVirtualMachineFilter struct {
MachineManagerID string `filter:"machineManagerId"`
}

type CreateOpenIaasVirtualMachineRequest struct {
Name string `json:"name"`
TemplateID string `json:"templateId"`
CPU int `json:"cpu"`
Memory int `json:"memory"`
}

func (c *OpenIaaSVirtualMachineClient) Create(ctx context.Context, req *CreateOpenIaasVirtualMachineRequest) (string, error) {
r := c.c.newRequest("POST", "/compute/v1/open_iaas/virtual_machines")
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}

func (v *OpenIaaSVirtualMachineClient) List(
ctx context.Context,
filter *OpenIaaSVirtualMachineFilter) ([]*OpenIaaSVirtualMachine, error) {
Expand Down Expand Up @@ -92,3 +109,45 @@ func (v *OpenIaaSVirtualMachineClient) Read(ctx context.Context, id string) (*Op

return &out, nil
}

type UpdateOpenIaasVirtualMachineRequest struct {
Name string `json:"name"`
CPU int `json:"cpu"`
NumCoresPerSocket int `json:"numCoresPerSocket"`
Memory int `json:"memory"`
SecureBoot bool `json:"secureBoot"`
AutoPowerOn bool `json:"autoPowerOn"`
HighAvailability string `json:"highAvailability"`
}

func (v *OpenIaaSVirtualMachineClient) Update(ctx context.Context, id string, req *UpdateOpenIaasVirtualMachineRequest) (string, error) {
r := v.c.newRequest("PATCH", "/compute/v1/open_iaas/virtual_machines/%s", id)
r.obj = req
return v.c.doRequestAndReturnActivity(ctx, r)
}

func (v *OpenIaaSVirtualMachineClient) Delete(ctx context.Context, id string) (string, error) {
r := v.c.newRequest("DELETE", "/compute/v1/open_iaas/virtual_machines/%s", id)
return v.c.doRequestAndReturnActivity(ctx, r)
}

type UpdateOpenIaasVirtualMachinePowerRequest struct {
PowerState string `json:"powerState"`
HostId string `json:"hostId,omitempty"`
Force bool `json:"force,omitempty"`
BypassMacAddressesCheck bool `json:"bypassMacAddressesCheck,omitempty"`
ForceShutdownDelay int `json:"forceShutdownDelay,omitempty"`
BypassBlockedOperation bool `json:"bypassBlockedOperation,omitempty"`
}

func (v *OpenIaaSVirtualMachineClient) Power(ctx context.Context, id string, req *UpdateOpenIaasVirtualMachinePowerRequest) (string, error) {
r := v.c.newRequest("PATCH", "/compute/v1/open_iaas/virtual_machines/%s/power", id)
r.obj = req
return v.c.doRequestAndReturnActivity(ctx, r)
}

func (v *OpenIaaSVirtualMachineClient) UpdateBootOrder(ctx context.Context, id string, bootOrder []string) (string, error) {
r := v.c.newRequest("PATCH", "/compute/v1/open_iaas/virtual_machines/%s/boot_order", id)
r.obj = map[string][]string{"order": bootOrder}
return v.c.doRequestAndReturnActivity(ctx, r)
}
16 changes: 16 additions & 0 deletions internal/provider/data_source_compute_openiaas_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ func dataSourceOpenIaasVirtualMachine() *schema.Resource {
},
},
},
"tools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"detected": {
Type: schema.TypeBool,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"boot_order": {
Type: schema.TypeList,
Computed: true,
Expand Down
16 changes: 11 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ func New(version string) func() *schema.Provider {
"cloudtemple_iam_users": documentDatasource(dataSourceUsers(), "iam_read"),
},
ResourcesMap: map[string]*schema.Resource{
// Backup - IaaS VMWare
"cloudtemple_backup_sla_policy_assignment": documentResource(resourceBackupSLAPolicyAssignment(), "backup_iaas_spp_read", "backup_iaas_spp_write", "activity_read"),
"cloudtemple_compute_network_adapter": documentResource(resourceNetworkAdapter(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_controller": documentResource(resourceVirtualController(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_disk": documentResource(resourceVirtualDisk(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_machine": documentResource(resourceVirtualMachine(), "compute_iaas_vmware_infrastructure_read", "compute_iaas_vmware_infrastructure_write", "compute_iaas_vmware_management", "compute_iaas_vmware_read", "compute_iaas_vmware_virtual_machine_power", "backup_iaas_spp_read", "backup_iaas_spp_write", "activity_read", "tag_read", "tag_write"),
"cloudtemple_iam_personal_access_token": documentResource(resourcePersonalAccessToken(), "iam_offline_access"),

// Compute - IaaS VMWare
"cloudtemple_compute_network_adapter": documentResource(resourceNetworkAdapter(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_controller": documentResource(resourceVirtualController(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_disk": documentResource(resourceVirtualDisk(), "compute_iaas_vmware_management", "compute_iaas_vmware_read", "activity_read"),
"cloudtemple_compute_virtual_machine": documentResource(resourceVirtualMachine(), "compute_iaas_vmware_infrastructure_read", "compute_iaas_vmware_infrastructure_write", "compute_iaas_vmware_management", "compute_iaas_vmware_read", "compute_iaas_vmware_virtual_machine_power", "backup_iaas_spp_read", "backup_iaas_spp_write", "activity_read", "tag_read", "tag_write"),
"cloudtemple_iam_personal_access_token": documentResource(resourcePersonalAccessToken(), "iam_offline_access"),

// Compute - Open IaaS
"cloudtemple_compute_iaas_opensource_virtual_machine": documentResource(resourceOpenIaasVirtualMachine(), "compute_iaas_opensource_infrastructure_read", "compute_iaas_opensource_infrastructure_write", "compute_iaas_opensource_management", "compute_iaas_opensource_read", "compute_iaas_opensource_virtual_machine_power", "backup_iaas_opensource_read", "backup_iaas_opensource_write", "activity_read", "tag_read", "tag_write"),
},
}

Expand Down
Loading

0 comments on commit 130ce7a

Please sign in to comment.