Skip to content

Commit

Permalink
Merge pull request #93 from Cloud-Temple/feature/54
Browse files Browse the repository at this point in the history
Feature/54
  • Loading branch information
pbesret authored Nov 7, 2023
2 parents b00c8d9 + e954aa7 commit 5e9a3fe
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 2 deletions.
107 changes: 107 additions & 0 deletions docs/resources/compute_virtual_controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cloudtemple_compute_virtual_controller Resource - terraform-provider-cloudtemple"
subcategory: "Compute"
description: |-
Create and manage virtual controllers of a virtual machine.
To manage this resource you will need the following roles:
- compute_write
- compute_read
- activity_read
---

# cloudtemple_compute_virtual_controller (Resource)

Create and manage virtual controllers of a virtual machine.

To manage this resource you will need the following roles:
- `compute_write`
- `compute_read`
- `activity_read`

## Example Usage

```terraform
data "cloudtemple_compute_machine_manager" "vstack01" {
name = "vc-vstack-001-t0001"
}
data "cloudtemple_compute_virtual_datacenter" "th3s" {
name = "DC-TH3S"
machine_manager_id = data.cloudtemple_compute_machine_manager.vstack01.id
}
data "cloudtemple_compute_host_cluster" "clu001" {
name = "clu001-ucs12"
datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
}
data "cloudtemple_compute_datastore_cluster" "sdrs001" {
name = "sdrs001-LIVE_"
datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
}
data "cloudtemple_compute_content_library" "cl001" {
name = "local-vc-vstack-001-t0001"
}
data "cloudtemple_compute_content_library_item" "ubuntu-cloudinit" {
content_library_id = data.cloudtemple_compute_content_library.cl001.id
name = "ubuntu-22.04.1-desktop-amd64"
}
resource "cloudtemple_compute_virtual_machine" "foo" {
name = "test-terraform-example-controller"
power_state = "on"
memory = 8 * 1024 * 1024 * 1024
cpu = 4
num_cores_per_socket = 1
datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
host_cluster_id = data.cloudtemple_compute_host_cluster.clu001.id
datastore_cluster_id = data.cloudtemple_compute_datastore_cluster.sdrs001.id
guest_operating_system_moref = "ubuntu64Guest"
}
resource "cloudtemple_compute_virtual_controller" "bar" {
virtual_machine_id = cloudtemple_compute_virtual_machine.foo.id
type = "CD/DVD"
content_library_item_id = data.cloudtemple_compute_content_library_item.ubuntu-cloudinit.id
connected = true
mounted = true
}
resource "cloudtemple_compute_virtual_controller" "baz" {
virtual_machine_id = cloudtemple_compute_virtual_machine.pbt-crashtest.id
type = "SCSI"
sub_type = "ParaVirtual"
}
```

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

### Required

- `type` (String) Can be one of : USB2, USB3, SCSI, CD/DVD
- `virtual_machine_id` (String)

### Optional

- `connected` (Boolean) Only compatible with CDROM controllers
- `content_library_item_id` (String) Content library item identifier. (Conflicts with `iso_path`)
- `iso_path` (String) If exists, the datastore ISO path. (Conflicts with `content_library_item_id`)
- `mounted` (Boolean) Only compatible with CDROM controllers
- `sub_type` (String) Can be one of : BusLogic, LSILogic, LSILogicSAS, ParaVirtual

### Read-Only

- `hot_add_remove` (Boolean)
- `id` (String) The ID of this resource.
- `label` (String)
- `shared_bus` (String)
- `summary` (String)
- `virtual_disks` (List of String)


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
cloudtemple = {
source = "Cloud-Temple/cloudtemple"
version = "0.1.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
data "cloudtemple_compute_machine_manager" "vstack01" {
name = "vc-vstack-001-t0001"
}

data "cloudtemple_compute_virtual_datacenter" "th3s" {
name = "DC-TH3S"
machine_manager_id = data.cloudtemple_compute_machine_manager.vstack01.id
}

data "cloudtemple_compute_host_cluster" "clu001" {
name = "clu001-ucs12"
datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
}

data "cloudtemple_compute_datastore_cluster" "sdrs001" {
name = "sdrs001-LIVE_"
datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
}

data "cloudtemple_compute_content_library" "cl001" {
name = "local-vc-vstack-001-t0001"
}

data "cloudtemple_compute_content_library_item" "ubuntu-cloudinit" {
content_library_id = data.cloudtemple_compute_content_library.cl001.id
name = "ubuntu-22.04.1-desktop-amd64"
}

resource "cloudtemple_compute_virtual_machine" "foo" {
name = "test-terraform-example-controller"
power_state = "on"

memory = 8 * 1024 * 1024 * 1024
cpu = 4
num_cores_per_socket = 1

datacenter_id = data.cloudtemple_compute_virtual_datacenter.th3s.id
host_cluster_id = data.cloudtemple_compute_host_cluster.clu001.id
datastore_cluster_id = data.cloudtemple_compute_datastore_cluster.sdrs001.id
guest_operating_system_moref = "ubuntu64Guest"
}

resource "cloudtemple_compute_virtual_controller" "bar" {
virtual_machine_id = cloudtemple_compute_virtual_machine.foo.id
type = "CD/DVD"
content_library_item_id = data.cloudtemple_compute_content_library_item.ubuntu-cloudinit.id
connected = true
mounted = true
}

resource "cloudtemple_compute_virtual_controller" "baz" {
virtual_machine_id = cloudtemple_compute_virtual_machine.pbt-crashtest.id
type = "SCSI"
sub_type = "ParaVirtual"
}
4 changes: 2 additions & 2 deletions internal/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func closeResponseBody(resp *http.Response) error {

// requireOK is used to wrap doRequest and check for a 200
func requireOK(resp *http.Response) error {
return requireHttpCodes(resp, 200, 201)
return requireHttpCodes(resp, 200, 201, 206)
}

// requireHttpCodes checks for the "allowable" http codes for a response
Expand All @@ -339,7 +339,7 @@ func requireHttpCodes(resp *http.Response, httpCodes ...int) error {

func requireNotFoundOrOK(resp *http.Response, notFoundCode int) (bool, error) {
switch resp.StatusCode {
case 200:
case 200, 206:
return true, nil
case 404, notFoundCode:
return false, nil
Expand Down
67 changes: 67 additions & 0 deletions internal/client/compute_virtual_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,70 @@ func (v *VirtualControllerClient) List(

return out, nil
}

type CreateVirtualControllerRequest struct {
VirtualMachineId string `json:"virtualMachineId"`
Type string `json:"type"`
SubType string `json:"subType,omitempty"`
}

func (n *VirtualControllerClient) Create(ctx context.Context, req *CreateVirtualControllerRequest) (string, error) {
r := n.c.newRequest("POST", "/api/compute/v1/vcenters/virtual_controllers")
r.obj = req
return n.c.doRequestAndReturnActivity(ctx, r)
}

func (v *VirtualControllerClient) Read(ctx context.Context, id string) (*VirtualController, error) {
r := v.c.newRequest("GET", "/api/compute/v1/vcenters/virtual_controllers/%s", id)
resp, err := v.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
found, err := requireNotFoundOrOK(resp, 403)
if err != nil || !found {
return nil, err
}

var out VirtualController
if err := decodeBody(resp, &out); err != nil {
return nil, err
}

return &out, nil
}

type MountVirtualControllerRequest struct {
ID string `json:"id"`
IsoPath string `json:"isoPath,omitempty"`
ContentLibraryItemId string `json:"contentLibraryItemId,omitempty"`
}

func (n *VirtualControllerClient) Mount(ctx context.Context, req *MountVirtualControllerRequest) (string, error) {
r := n.c.newRequest("PATCH", "/api/compute/v1/vcenters/virtual_controllers/cdrom/mount")
r.obj = req
return n.c.doRequestAndReturnActivity(ctx, r)
}

func (n *VirtualControllerClient) Unmount(ctx context.Context, id string) (string, error) {
r := n.c.newRequest("PATCH", "/api/compute/v1/vcenters/virtual_controllers/cdrom/unmount")
r.obj = map[string]string{"id": id}
return n.c.doRequestAndReturnActivity(ctx, r)
}

func (n *VirtualControllerClient) Connect(ctx context.Context, id string) (string, error) {
r := n.c.newRequest("PATCH", "/api/compute/v1/vcenters/virtual_controllers/cdrom/connect")
r.obj = map[string]string{"id": id}
return n.c.doRequestAndReturnActivity(ctx, r)
}

func (n *VirtualControllerClient) Disconnect(ctx context.Context, id string) (string, error) {
r := n.c.newRequest("PATCH", "/api/compute/v1/vcenters/virtual_controllers/cdrom/disconnect")
r.obj = map[string]string{"id": id}
return n.c.doRequestAndReturnActivity(ctx, r)
}

func (n *VirtualControllerClient) Delete(ctx context.Context, id string) (string, error) {
r := n.c.newRequest("DELETE", "/api/compute/v1/vcenters/virtual_controllers/%s", id)
return n.c.doRequestAndReturnActivity(ctx, r)
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func New(version string) func() *schema.Provider {
ResourcesMap: map[string]*schema.Resource{
"cloudtemple_backup_sla_policy_assignment": documentResource(resourceBackupSLAPolicyAssignment(), "backup_read", "backup_write", "activity_read"),
"cloudtemple_compute_network_adapter": documentResource(resourceNetworkAdapter(), "compute_write", "compute_read", "activity_read"),
"cloudtemple_compute_virtual_controller": documentResource(resourceVirtualController(), "compute_write", "compute_read", "activity_read"),
"cloudtemple_compute_virtual_disk": documentResource(resourceVirtualDisk(), "compute_write", "compute_read", "compute_management_read", "compute_management_write", "activity_read"),
"cloudtemple_compute_virtual_machine": documentResource(resourceVirtualMachine(), "compute_write", "compute_read", "activity_read", "tag_read", "tag_write"),
"cloudtemple_iam_personal_access_token": documentResource(resourcePersonalAccessToken(), "iam_offline_access"),
Expand Down
Loading

0 comments on commit 5e9a3fe

Please sign in to comment.