-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from HewlettPackard/add-ds-storageType
Add DS storage_type for instance
- Loading branch information
Showing
18 changed files
with
209 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,8 @@ acc: | |
network { | ||
id = 156 | ||
} | ||
volume { | ||
name = "root_vol" | ||
datastore_id = "auto" | ||
size = 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,8 @@ acc: | |
network { | ||
id = 119 | ||
} | ||
volume { | ||
name = "root_vol" | ||
datastore_id = "auto" | ||
size = 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,9 @@ acc: | |
network { | ||
id = 84 | ||
interface_id = 4 | ||
} | ||
volume { | ||
name = "root_vol" | ||
datastore_id = "auto" | ||
size = 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
acc: | ||
- config: | | ||
name = "thin" | ||
cloud_id = 1 | ||
layout_id = 376 | ||
validations: | ||
tf.id: 133 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,9 @@ acc: | |
network { | ||
id = 97 | ||
interface_id = 4 | ||
} | ||
volume { | ||
name = "root_vol" | ||
datastore_id = "auto" | ||
size = 6 | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/data-sources/hpegl_vmaas_instance_disk_type/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
internal/acceptance_test/data_source_instance_storage_type_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
|
||
package acceptancetest | ||
|
||
import ( | ||
"testing" | ||
|
||
api_client "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client" | ||
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/pkg/atf" | ||
) | ||
|
||
func TestAccDataSourceInstanceStorageType(t *testing.T) { | ||
acc := &atf.Acc{ | ||
PreCheck: testAccPreCheck, | ||
Providers: testAccProviders, | ||
ResourceName: "hpegl_vmaas_instance_disk_type", | ||
GetAPI: func(attr map[string]string) (interface{}, error) { | ||
cl, cfg := getAPIClient() | ||
iClient := api_client.InstancesAPIService{ | ||
Client: cl, | ||
Cfg: cfg, | ||
} | ||
|
||
return iClient.GetStorageVolTypeID(getAccContext(), attr["cloud_id"], attr["layout_id"]) | ||
}, | ||
} | ||
|
||
acc.RunDataSourceTests(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
|
||
package cmp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client" | ||
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/internal/utils" | ||
"github.com/tshihad/tftags" | ||
) | ||
|
||
type instanceStorageType struct { | ||
iClient *client.InstancesAPIService | ||
} | ||
|
||
func newInstanceStorageType(instanceClient *client.InstancesAPIService) *instanceStorageType { | ||
return &instanceStorageType{iClient: instanceClient} | ||
} | ||
|
||
func (i *instanceStorageType) Read(ctx context.Context, d *utils.Data, meta interface{}) error { | ||
setMeta(meta, i.iClient.Client) | ||
log.Printf("[DEBUG] Get Instance Storage Volume Type") | ||
name := d.GetString("name") | ||
name = strings.ToLower(name) | ||
name = strings.TrimSpace(name) | ||
cloudID := d.GetString("cloud_id") | ||
layoutID := d.GetString("layout_id") | ||
|
||
// Pre check | ||
if err := d.Error(); err != nil { | ||
return err | ||
} | ||
|
||
storageType, err := i.iClient.GetStorageVolTypeID(ctx, cloudID, layoutID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, n := range storageType.Plans[0].StorageTypes { | ||
volType := strings.ToLower(n.Name) | ||
volType = strings.TrimSpace(volType) | ||
if volType == name { | ||
log.Print("[DEBUG] Storage type ID ", n.ID) | ||
|
||
return tftags.Set(d, n) | ||
} | ||
} | ||
|
||
return fmt.Errorf(errExactMatch, "Instance Storage Type") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
|
||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/internal/utils" | ||
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/pkg/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func ReadInstanceStorageType() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: f(generalNamedesc, "disk type", "disk type"), | ||
}, | ||
"cloud_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: f(generalDDesc, "cloud"), | ||
}, | ||
"layout_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: f(generalDDesc, "layout"), | ||
}, | ||
}, | ||
ReadContext: readInstanceStorageTypeContext, | ||
Description: `The ` + DSInstanceStorageType + ` data source can be used to discover the ID of a disk type. | ||
This can then be used with resources or data sources that require a ` + DSInstanceStorageType + `, | ||
such as the ` + ResInstance + ` resource.`, | ||
SchemaVersion: 0, | ||
StateUpgraders: nil, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
} | ||
} | ||
|
||
func readInstanceStorageTypeContext(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c, err := client.GetClientFromMetaMap(meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
data := utils.NewData(d) | ||
err = c.CmpClient.InstanceStorageType.Read(ctx, data, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters