Skip to content

Commit

Permalink
Update examples and fix instance clone, make volume as required
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Sep 12, 2024
1 parent d6140b2 commit 551c038
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# (C) Copyright 2024 Hewlett Packard Enterprise Development LP

data "hpegl_vmaas_instance_disk_type" "vmaas_cloud_vmware_thin_lazy" {
name = "thick (lazy zero)"
cloud_id = data.hpegl_vmaas_cloud.cloud.id
layout_id = data.hpegl_vmaas_layout.vmware.id
}
8 changes: 4 additions & 4 deletions examples/data-sources/hpegl_vmaas_layout/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

data "hpegl_vmaas_layout" "vmware_centos" {
name = "VMware VM with vanilla CentOS"
instance_type_code = "glhc-vanilla-centos"
data "hpegl_vmaas_layout" "vmware" {
name = "Vmware VM"
instance_type_code = "vmware"
}
4 changes: 3 additions & 1 deletion examples/resources/hpegl_vmaas_instance/all_options.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

# create instance with all possible options
resource "hpegl_vmaas_instance" "tf_instance" {
Expand All @@ -19,12 +19,14 @@ resource "hpegl_vmaas_instance" "tf_instance" {
name = "root_vol"
size = 5
datastore_id = data.hpegl_vmaas_datastore.c_3par.id
storage_type = data.hpegl_vmaas_instance_disk_type.vmaas_cloud_vmware_thin_lazy.id
}

volume {
name = "local_vol"
size = 5
datastore_id = data.hpegl_vmaas_datastore.c_3par.id
storage_type = data.hpegl_vmaas_instance_disk_type.vmware_thin.id
}

labels = ["test_label"]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/HewlettPackard/hpegl-vmaas-terraform-resources
go 1.21

require (
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240910105957-f3f6f72246f7
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240911094737-0affabbd1c72
github.com/golang/mock v1.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.10 h1:RLRtdCjl12eunpAxSNrl
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.10/go.mod h1:UzXizYR6sUVsvDRMcLC2E4eabJsPH/3nM8rlKL2BLSc=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240910105957-f3f6f72246f7 h1:Aw+QRmQD7A1YPydzX4R1+Y+aQdtMVMfBQoWXkBYOgM0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240910105957-f3f6f72246f7/go.mod h1:UzXizYR6sUVsvDRMcLC2E4eabJsPH/3nM8rlKL2BLSc=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240911094737-0affabbd1c72 h1:6JonchRsW6qhkkO5TVMzRz8SyhV2Ln3+R5VjNjbchaU=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.11-0.20240911094737-0affabbd1c72/go.mod h1:UzXizYR6sUVsvDRMcLC2E4eabJsPH/3nM8rlKL2BLSc=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand Down
29 changes: 5 additions & 24 deletions internal/cmp/instance_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,16 @@ func instanceCloneCompareVolume(
newVolumes := make([]models.CreateInstanceBodyVolumes, 0, len(vSchemas))

// convert schema volume to model
for i := range newVolumes {
for _, vol := range vSchemas {
newVolumes = append(newVolumes, models.CreateInstanceBodyVolumes{
ID: -1,
Size: vSchemas[i]["size"].(int),
DatastoreID: vSchemas[i]["datastore_id"],
StorageType: vSchemas[i]["storage_type"].(int),
Size: vol["size"].(int),
Name: vol["name"].(string),
DatastoreID: vol["datastore_id"],
StorageType: vol["storage_type"].(int),
})
}

// check parent instance have same volume name, if so use same id
for _, VModel := range vModels {
volumeExist := false
for i, v := range newVolumes {
if VModel.Name == v.Name {
newVolumes[i].ID = VModel.ID
volumeExist = true
}
}
// if parent instance volume not exist in schema add it in request
if !volumeExist {
newVolumes = append(newVolumes, models.CreateInstanceBodyVolumes{
ID: VModel.ID,
Size: VModel.Size,
DatastoreID: VModel.DatastoreID,
Name: VModel.Name,
StorageType: VModel.StorageType,
})
}
}
newVolumes[0].RootVolume = true

return newVolumes
Expand Down
3 changes: 1 addition & 2 deletions internal/resources/resource_instances_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ func getInstanceDefaultSchema(isClone bool) *schema.Resource {
},
"volume": {
Type: schema.TypeList,
Optional: isClone,
Required: !isClone,
Required: true,
MinItems: 1,
Description: `A list of volumes to be created inside a provisioned instance.
It can have a root volume and other secondary volumes.`,
Expand Down

0 comments on commit 551c038

Please sign in to comment.