Skip to content

Commit 98efa29

Browse files
committed
refactor: move to hcx package
Moves all resources and data sources from the `main` package to the `hcx` package. Signed-off-by: Ryan Johnson <[email protected]>
1 parent 85211ef commit 98efa29

15 files changed

+203
-216
lines changed

data_source_compute_profile.go renamed to hcx/data_source_compute_profile.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33
// SPDX-License-Identifier: MPL-2.0
44

5-
package main
5+
package hcx
66

77
import (
88
"context"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
"github.com/vmware/terraform-provider-hcx/hcx"
1312
)
1413

1514
// dataSourceComputeProfile defines the data source schema to retrieve information about a compute profile.
@@ -36,16 +35,16 @@ func dataSourceComputeProfile() *schema.Resource {
3635
func dataSourceComputeProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
3736
var diags diag.Diagnostics
3837

39-
client := m.(*hcx.Client)
38+
client := m.(*Client)
4039

41-
res, err := hcx.GetLocalCloudList(client)
40+
res, err := GetLocalCloudList(client)
4241
if err != nil {
4342
return diag.FromErr(err)
4443
}
4544

4645
network := d.Get("name").(string)
4746

48-
cp, err := hcx.GetComputeProfile(client, res.Data.Items[0].EndpointID, network)
47+
cp, err := GetComputeProfile(client, res.Data.Items[0].EndpointID, network)
4948

5049
if err != nil {
5150
return diag.FromErr(err)

data_source_network_backing.go renamed to hcx/data_source_network_backing.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33
// SPDX-License-Identifier: MPL-2.0
44

5-
package main
5+
package hcx
66

77
import (
88
"context"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
"github.com/vmware/terraform-provider-hcx/hcx"
1312
)
1413

1514
// dataSourceNetworkBacking defines a data source schema to retrieve information about a network backing.
@@ -47,13 +46,13 @@ func dataSourceNetworkBacking() *schema.Resource {
4746
func dataSourceNetworkBackingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
4847
var diags diag.Diagnostics
4948

50-
client := m.(*hcx.Client)
49+
client := m.(*Client)
5150

5251
network := d.Get("name").(string)
5352
vcUUID := d.Get("vcuuid").(string)
5453
networkType := d.Get("network_type").(string)
5554

56-
res, err := hcx.GetNetworkBacking(client, vcUUID, network, networkType)
55+
res, err := GetNetworkBacking(client, vcUUID, network, networkType)
5756

5857
if err != nil {
5958
return diag.FromErr(err)

provider.go renamed to hcx/provider.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33
// SPDX-License-Identifier: MPL-2.0
44

5-
package main
5+
package hcx
66

77
import (
88
"context"
99

1010
"github.com/hashicorp/go-cty/cty"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13-
hcx "github.com/vmware/terraform-provider-hcx/hcx"
1413
)
1514

16-
// Provider -
15+
// Provider returns the schema.Provider object configured with resources, data sources, and schema for the HCX provider.
1716
func Provider() *schema.Provider {
1817
return &schema.Provider{
1918
Schema: map[string]*schema.Schema{
@@ -95,7 +94,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
9594
allowUnverifiedSSL := d.Get("allow_unverified_ssl").(bool)
9695
vmcToken := d.Get("vmc_token").(string)
9796

98-
c, err := hcx.NewClient(&hcxURL, &username, &password, &adminUsername, &adminPassword, &allowUnverifiedSSL, &vmcToken)
97+
c, err := NewClient(&hcxURL, &username, &password, &adminUsername, &adminPassword, &allowUnverifiedSSL, &vmcToken)
9998

10099
if err != nil {
101100
return nil, diag.FromErr(err)

resource_activation.go renamed to hcx/resource_activation.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33
// SPDX-License-Identifier: MPL-2.0
44

5-
package main
5+
package hcx
66

77
import (
88
"context"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
"github.com/vmware/terraform-provider-hcx/hcx"
1312
)
1413

1514
// resourceActivation defines the resource schema for managing activation configurations.
@@ -39,16 +38,16 @@ func resourceActivation() *schema.Resource {
3938
// resourceActivationCreate creates the activation configuration resource.
4039
func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
4140

42-
client := m.(*hcx.Client)
41+
client := m.(*Client)
4342

4443
url := d.Get("url").(string)
4544
activationkey := d.Get("activationkey").(string)
4645

47-
body := hcx.ActivateBody{
48-
Data: hcx.ActivateData{
49-
Items: []hcx.ActivateDataItem{
46+
body := ActivateBody{
47+
Data: ActivateData{
48+
Items: []ActivateDataItem{
5049
{
51-
Config: hcx.ActivateDataItemConfig{
50+
Config: ActivateDataItemConfig{
5251
URL: url,
5352
ActivationKey: activationkey,
5453
},
@@ -58,14 +57,14 @@ func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m int
5857
}
5958

6059
// First, check if already activated
61-
res, err := hcx.GetActivate(client)
60+
res, err := GetActivate(client)
6261
if err != nil {
6362
return diag.FromErr(err)
6463
}
6564

6665
if len(res.Data.Items) == 0 {
6766
// No activation config found
68-
_, err := hcx.PostActivate(client, body)
67+
_, err := PostActivate(client, body)
6968

7069
if err != nil {
7170
return diag.FromErr(err)
@@ -83,9 +82,9 @@ func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m int
8382
func resourceActivationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
8483
var diags diag.Diagnostics
8584

86-
client := m.(*hcx.Client)
85+
client := m.(*Client)
8786

88-
res, err := hcx.GetActivate(client)
87+
res, err := GetActivate(client)
8988
if err != nil {
9089
return diag.FromErr(err)
9190
}

resource_compute_profile.go renamed to hcx/resource_compute_profile.go

+31-32
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
33
// SPDX-License-Identifier: MPL-2.0
44

5-
package main
5+
package hcx
66

77
import (
88
"bytes"
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
16-
"github.com/vmware/terraform-provider-hcx/hcx"
1716
)
1817

1918
// resourceComputeProfile defines the resource schema for managing compute profile configuration.
@@ -94,12 +93,12 @@ func resourceComputeProfile() *schema.Resource {
9493
// resourceComputeProfileCreate creates the compute profile configuration.
9594
func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
9695

97-
client := m.(*hcx.Client)
96+
client := m.(*Client)
9897

9998
name := d.Get("name").(string)
10099
cluster := d.Get("cluster").(string)
101100

102-
res, err := hcx.GetVcInventory(client)
101+
res, err := GetVcInventory(client)
103102
if err != nil {
104103
return diag.FromErr(err)
105104
}
@@ -121,26 +120,26 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
121120

122121
// Get Datastore info
123122
datastore := d.Get("datastore").(string)
124-
datastoreFromAPI, err := hcx.GetVcDatastore(client, datastore, res.EntityID, clusterID)
123+
datastoreFromAPI, err := GetVcDatastore(client, datastore, res.EntityID, clusterID)
125124
if err != nil {
126125
return diag.FromErr(err)
127126
}
128127

129128
// Get DVS info
130129
dvs := d.Get("dvs").(string)
131-
dvsFromAPI, err := hcx.GetVcDvs(client, dvs, res.EntityID, clusterID)
130+
dvsFromAPI, err := GetVcDvs(client, dvs, res.EntityID, clusterID)
132131
if err != nil {
133132
return diag.FromErr(err)
134133
}
135134

136135
// Get Services from schema
137136
services := d.Get("service").([]interface{})
138-
servicesFromSchema := []hcx.Service{}
137+
servicesFromSchema := []Service{}
139138
for _, j := range services {
140139
s := j.(map[string]interface{})
141140
name := s["name"].(string)
142141

143-
sTmp := hcx.Service{
142+
sTmp := Service{
144143
Name: name,
145144
}
146145
servicesFromSchema = append(servicesFromSchema, sTmp)
@@ -152,40 +151,40 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
152151
uplinkNetwork := d.Get("uplink_network").(string)
153152
vmotionNetwork := d.Get("vmotion_network").(string)
154153

155-
networksList := []hcx.Network{}
156-
np, err := hcx.GetNetworkProfileByID(client, managementNetwork)
154+
networksList := []Network{}
155+
np, err := GetNetworkProfileByID(client, managementNetwork)
157156
if err != nil {
158157
return diag.FromErr(err)
159158
}
160159
managementNetworkName := np.Name
161160
managementNetworkID := np.ObjectID
162161

163-
np, err = hcx.GetNetworkProfileByID(client, replicationNetwork)
162+
np, err = GetNetworkProfileByID(client, replicationNetwork)
164163
if err != nil {
165164
return diag.FromErr(err)
166165
}
167166
replicationNetworkName := np.Name
168167
replicationNetworkID := np.ObjectID
169168

170-
np, err = hcx.GetNetworkProfileByID(client, uplinkNetwork)
169+
np, err = GetNetworkProfileByID(client, uplinkNetwork)
171170
if err != nil {
172171
return diag.FromErr(err)
173172
}
174173
uplinkNetworkName := np.Name
175174
uplinkNetworkID := np.ObjectID
176175

177-
np, err = hcx.GetNetworkProfileByID(client, vmotionNetwork)
176+
np, err = GetNetworkProfileByID(client, vmotionNetwork)
178177
if err != nil {
179178
return diag.FromErr(err)
180179
}
181180
vmotionNetworkName := np.Name
182181
vmotionNetworkID := np.ObjectID
183182

184-
netTmp := hcx.Network{
183+
netTmp := Network{
185184
Name: managementNetworkName,
186185
ID: managementNetworkID,
187186
Tags: []string{"management"},
188-
Status: hcx.Status{
187+
Status: Status{
189188
State: "REALIZED",
190189
},
191190
}
@@ -203,11 +202,11 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
203202
if found {
204203
networksList[index].Tags = append(networksList[index].Tags, "replication")
205204
} else {
206-
netTmp := hcx.Network{
205+
netTmp := Network{
207206
Name: replicationNetworkName,
208207
ID: replicationNetworkID,
209208
Tags: []string{"replication"},
210-
Status: hcx.Status{
209+
Status: Status{
211210
State: "REALIZED",
212211
},
213212
}
@@ -226,11 +225,11 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
226225
if found {
227226
networksList[index].Tags = append(networksList[index].Tags, "uplink")
228227
} else {
229-
netTmp := hcx.Network{
228+
netTmp := Network{
230229
Name: uplinkNetworkName,
231230
ID: uplinkNetworkID,
232231
Tags: []string{"uplink"},
233-
Status: hcx.Status{
232+
Status: Status{
234233
State: "REALIZED",
235234
},
236235
}
@@ -249,30 +248,30 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
249248
if found {
250249
networksList[index].Tags = append(networksList[index].Tags, "vmotion")
251250
} else {
252-
netTmp := hcx.Network{
251+
netTmp := Network{
253252
Name: vmotionNetworkName,
254253
ID: vmotionNetworkID,
255254
Tags: []string{"vmotion"},
256-
Status: hcx.Status{
255+
Status: Status{
257256
State: "REALIZED",
258257
},
259258
}
260259
networksList = append(networksList, netTmp)
261260
}
262261

263-
body := hcx.InsertComputeProfileBody{
262+
body := InsertComputeProfileBody{
264263
Name: name,
265264
Services: servicesFromSchema,
266-
Computes: []hcx.Compute{{
265+
Computes: []Compute{{
267266
ComputeID: res.EntityID,
268267
ComputeType: "VC",
269268
ComputeName: res.Name,
270269
ID: res.Children[0].EntityID,
271270
Name: res.Children[0].Name,
272271
Type: res.Children[0].EntityType,
273272
}},
274-
DeploymentContainers: hcx.DeploymentContainer{
275-
Computes: []hcx.Compute{{
273+
DeploymentContainers: DeploymentContainer{
274+
Computes: []Compute{{
276275
ComputeID: res.EntityID,
277276
ComputeType: "VC",
278277
ComputeName: res.Name,
@@ -281,7 +280,7 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
281280
Type: "ClusterComputeResource",
282281
},
283282
},
284-
Storage: []hcx.Storage{{
283+
Storage: []Storage{{
285284
ComputeID: res.EntityID,
286285
ComputeType: "VC",
287286
ComputeName: res.Name,
@@ -291,7 +290,7 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
291290
}},
292291
},
293292
Networks: networksList,
294-
Switches: []hcx.Switch{{
293+
Switches: []Switch{{
295294
ComputeID: res.EntityID,
296295
MaxMTU: dvsFromAPI.MaxMTU,
297296
ID: dvsFromAPI.ID,
@@ -305,14 +304,14 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
305304
return diag.FromErr(err)
306305
}
307306

308-
res2, err := hcx.InsertComputeProfile(client, body)
307+
res2, err := InsertComputeProfile(client, body)
309308
if err != nil {
310309
return diag.FromErr(err)
311310
}
312311

313312
// Wait for task completion
314313
for {
315-
jr, err := hcx.GetTaskResult(client, res2.Data.InterconnectTaskID)
314+
jr, err := GetTaskResult(client, res2.Data.InterconnectTaskID)
316315
if err != nil {
317316
return diag.FromErr(err)
318317
}
@@ -352,16 +351,16 @@ func resourceComputeProfileUpdate(ctx context.Context, d *schema.ResourceData, m
352351
func resourceComputeProfileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
353352
var diags diag.Diagnostics
354353

355-
client := m.(*hcx.Client)
354+
client := m.(*Client)
356355

357-
res, err := hcx.DeleteComputeProfile(client, d.Id())
356+
res, err := DeleteComputeProfile(client, d.Id())
358357
if err != nil {
359358
return diag.FromErr(err)
360359
}
361360

362361
// Wait for task completion
363362
for {
364-
jr, err := hcx.GetTaskResult(client, res.Data.InterconnectTaskID)
363+
jr, err := GetTaskResult(client, res.Data.InterconnectTaskID)
365364
if err != nil {
366365
return diag.FromErr(err)
367366
}

0 commit comments

Comments
 (0)