Skip to content

Commit bfcf3d3

Browse files
committed
Support EVC Mode property for VMs
1 parent 27b52e0 commit bfcf3d3

File tree

16 files changed

+146
-3
lines changed

16 files changed

+146
-3
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ To compile the provider, run `go install`. This will build the provider and put
3232

3333
To generate or update documentation, run `go generate`.
3434

35+
Run `make` to copy the provider binary to the default Terraform plugin directory.
36+
3537
In order to run the full suite of Acceptance tests, run `make testacc`.
3638

3739
*Note:* Acceptance tests create real resources, and often cost money to run.
@@ -70,6 +72,19 @@ This will use the locally installed provider which has been installed by `make`
7072

7173
Ensure the change is rolled back prior to committing
7274

75+
### Using a local dcloud-tb-go-client during development
76+
77+
If you are developing the provider and need to use a local version of the dcloud-tb-go-client then apply an override in the `go.mod` file.
78+
Make sure to use the same version of the dcloud-tb-go-client in the `replace` directive as defined in the `require` directive.
79+
80+
```go
81+
replace (
82+
github.com/cisco-open/dcloud-tb-go-client v1.0.6 => ../dcloud-tb-go-client
83+
)
84+
```
85+
86+
Ensure the change is rolled back prior to committing.
87+
7388
## Dependencies
7489

7590
The provider makes extensive use of the dCloud Topology Builder Go Client (https://github.com/cisco-open/dcloud-tb-go-client).

docs/data-sources/inventory_vms.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Read-Only:
3131

3232
- `cpu_qty` (Number)
3333
- `datacenter` (String)
34+
- `evc_mode` (Number)
3435
- `id` (String)
3536
- `memory_mb` (Number)
3637
- `network_interfaces` (List of Object) (see [below for nested schema](#nestedobjatt--inventory_vms--network_interfaces))

docs/data-sources/vms.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Read-Only:
5050

5151
- `all_disks_non_persistent` (Boolean)
5252
- `bios_uuid` (String)
53+
- `evc_mode` (String)
5354
- `name_in_hypervisor` (String)
5455
- `not_started` (Boolean)
5556

docs/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ resource "dcloud_vm" "vm1" {
6262
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
6363
name_in_hypervisor = "ubuntu"
6464
not_started = false
65+
evc_mode = "SKYLAKE"
6566
}
6667
6768
network_interfaces {
@@ -114,6 +115,7 @@ resource "dcloud_vm" "vm2" {
114115
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 ad"
115116
name_in_hypervisor = "ubuntu"
116117
not_started = false
118+
evc_mode = "HASWELL"
117119
}
118120
119121
remote_access {
@@ -163,6 +165,7 @@ resource "dcloud_vm" "vm3" {
163165
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
164166
name_in_hypervisor = "ubuntu"
165167
not_started = false
168+
evc_mode = "WESTMERE"
166169
}
167170
168171
remote_access {

docs/resources/vm.md

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Required:
7070
- `name_in_hypervisor` (String)
7171
- `not_started` (Boolean)
7272

73+
Optional:
74+
75+
- `evc_mode` (String) The EVC mode of the VM, defaults to the EVC mode of the inventory VM if not specified
76+
7377

7478
<a id="nestedblock--guest_automation"></a>
7579
### Nested Schema for `guest_automation`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
dcloud = {
4+
version = "0.1"
5+
source = "cisco-open/dcloud"
6+
}
7+
}
8+
}
9+
10+
provider "dcloud" {
11+
tb_url = "https://tbv3-production.ciscodcloud.com/api"
12+
}
13+
14+
data "dcloud_evc_modes" "evc_modes" {}
15+
16+
output "evc_modes" {
17+
value = data.dcloud_evc_modes.evc_modes
18+
}

examples/data-sources/vm_data_source/data-source.tf

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "dcloud_vm" "vm1" {
4747
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
4848
name_in_hypervisor = "cmm"
4949
not_started = false
50+
evc_mode = "SKYLAKE"
5051
}
5152

5253
remote_access {

examples/provider/provider.tf

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "dcloud_vm" "vm1" {
4747
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
4848
name_in_hypervisor = "ubuntu"
4949
not_started = false
50+
evc_mode = "SKYLAKE"
5051
}
5152

5253
network_interfaces {
@@ -99,6 +100,7 @@ resource "dcloud_vm" "vm2" {
99100
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 ad"
100101
name_in_hypervisor = "ubuntu"
101102
not_started = false
103+
evc_mode = "HASWELL"
102104
}
103105

104106
remote_access {
@@ -148,6 +150,7 @@ resource "dcloud_vm" "vm3" {
148150
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
149151
name_in_hypervisor = "ubuntu"
150152
not_started = false
153+
evc_mode = "WESTMERE"
151154
}
152155

153156
remote_access {

examples/resources/vm_resource/resource.tf

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ resource "dcloud_vm" "vm1" {
4040
bios_uuid = "42 3a 5f 9d f1 a8 7c 0e-7d c2 44 27 2e d6 67 aa"
4141
name_in_hypervisor = "cmm"
4242
not_started = false
43+
evc_mode = "SKYLAKE"
4344
}
4445

4546
network_interfaces {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cisco-open/terraform-provider-dcloud
33
go 1.18
44

55
require (
6-
github.com/cisco-open/dcloud-tb-go-client v1.0.4
6+
github.com/cisco-open/dcloud-tb-go-client v1.0.6
77
github.com/hashicorp/terraform-plugin-docs v0.13.0
88
github.com/hashicorp/terraform-plugin-log v0.7.0
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
2828
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
2929
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
3030
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
31-
github.com/cisco-open/dcloud-tb-go-client v1.0.4 h1:RPi+7DWf7dqaGQYY12ttF7ljCDH4PfpEA1wKC67FRkc=
32-
github.com/cisco-open/dcloud-tb-go-client v1.0.4/go.mod h1:nswounfrrUZqPfRZ4fF1BpmnTXcJIM37RaSGUNbZlpg=
31+
github.com/cisco-open/dcloud-tb-go-client v1.0.6 h1:uHGwsCsThJqANI1Tc5vIcu1rgFO91Ug4veCkYyswbJk=
32+
github.com/cisco-open/dcloud-tb-go-client v1.0.6/go.mod h1:nswounfrrUZqPfRZ4fF1BpmnTXcJIM37RaSGUNbZlpg=
3333
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3434
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3535
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2023 Cisco Systems, Inc. and its affiliates
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
//
7+
// SPDX-License-Identifier: MPL-2.0
8+
9+
package dcloud
10+
11+
import (
12+
"context"
13+
"github.com/cisco-open/dcloud-tb-go-client/tbclient"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
16+
"strconv"
17+
"time"
18+
)
19+
20+
func dataSourceEvcModes() *schema.Resource {
21+
22+
return &schema.Resource{
23+
Description: "All the EVC Modes available to be used with VMs",
24+
25+
ReadContext: dataSourceEvcModesRead,
26+
27+
Schema: map[string]*schema.Schema{
28+
"evc_modes": {
29+
Type: schema.TypeList,
30+
Computed: true,
31+
Elem: &schema.Resource{
32+
Schema: map[string]*schema.Schema{
33+
"id": {
34+
Type: schema.TypeString,
35+
Computed: true,
36+
},
37+
"name": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
},
41+
},
42+
},
43+
},
44+
},
45+
}
46+
}
47+
48+
func dataSourceEvcModesRead(ctx context.Context, data *schema.ResourceData, m interface{}) diag.Diagnostics {
49+
tb := m.(*tbclient.Client)
50+
51+
evcModes, err := tb.GetAllEvcModes()
52+
if err != nil {
53+
return diag.FromErr(err)
54+
}
55+
56+
evcModeResources := make([]map[string]interface{}, len(evcModes))
57+
for i, evcMode := range evcModes {
58+
evcModeResources[i] = convertEvcModeToDataResource(evcMode)
59+
}
60+
61+
if err := data.Set("evc_modes", evcModeResources); err != nil {
62+
return diag.FromErr(err)
63+
}
64+
data.SetId(strconv.FormatInt(time.Now().Unix(), 10))
65+
66+
return diag.Diagnostics{}
67+
}
68+
69+
func convertEvcModeToDataResource(evcMode tbclient.EvcMode) map[string]interface{} {
70+
resource := make(map[string]interface{})
71+
resource["id"] = evcMode.Id
72+
resource["name"] = evcMode.Name
73+
74+
return resource
75+
}

internal/dcloud/data_source_inventory_vms.go

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func dataSourceInventoryVms() *schema.Resource {
5757
Type: schema.TypeInt,
5858
Computed: true,
5959
},
60+
"evc_mode": {
61+
Type: schema.TypeInt,
62+
Computed: true,
63+
},
6064
"remote_access_rdp_auto_login": {
6165
Type: schema.TypeBool,
6266
Computed: true,
@@ -145,6 +149,7 @@ func convertInventoryVmToDataResource(inventoryVm tbclient.InventoryVm) map[stri
145149
resource["original_description"] = inventoryVm.OriginalDescription
146150
resource["cpu_qty"] = inventoryVm.CpuQty
147151
resource["memory_mb"] = inventoryVm.MemoryMb
152+
resource["evc_mode"] = inventoryVm.EvcMode
148153

149154
if remoteAccess := inventoryVm.RemoteAccess; remoteAccess != nil {
150155
resource["remote_access_rdp_auto_login"] = remoteAccess.RdpAutoLogin

internal/dcloud/data_source_vms.go

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func dataSourceVms() *schema.Resource {
8888
Type: schema.TypeBool,
8989
Computed: true,
9090
},
91+
"evc_mode": {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
},
9195
},
9296
},
9397
},

internal/dcloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func Provider() *schema.Provider {
7272
"dcloud_external_dns": dataSourceExternalDns(),
7373
"dcloud_inventory_dns_assets": dataSourceInventoryDnsAssets(),
7474
"dcloud_inventory_srv_protocols": dataSourceInventorySrvProtocols(),
75+
"dcloud_evc_modes": dataSourceEvcModes(),
7576
},
7677
ResourcesMap: map[string]*schema.Resource{
7778
"dcloud_topology": resourceTopology(),

internal/dcloud/resource_vm.go

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func resourceVm() *schema.Resource {
7878
Type: schema.TypeBool,
7979
Required: true,
8080
},
81+
"evc_mode": {
82+
Type: schema.TypeString,
83+
Optional: true,
84+
Description: "The EVC mode of the VM, defaults to the EVC mode of the inventory VM if not specified",
85+
},
8186
},
8287
},
8388
},
@@ -294,11 +299,17 @@ func extractVm(data *schema.ResourceData, ctx context.Context) tbclient.Vm {
294299

295300
if advancedSettings := data.Get("advanced_settings"); advancedSettings != nil && (len(advancedSettings.([]interface{})) > 0) {
296301
as := advancedSettings.([]interface{})[0].(map[string]interface{})
302+
var evcMode *string
303+
if as["evc_mode"].(string) != "" {
304+
s := as["evc_mode"].(string)
305+
evcMode = &s
306+
}
297307
vm.AdvancedSettings = &tbclient.VmAdvancedSettings{
298308
NameInHypervisor: as["name_in_hypervisor"].(string),
299309
BiosUuid: as["bios_uuid"].(string),
300310
NotStarted: as["not_started"].(bool),
301311
AllDisksNonPersistent: as["all_disks_non_persistent"].(bool),
312+
EvcMode: evcMode,
302313
}
303314
}
304315

0 commit comments

Comments
 (0)