Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datatype from int to int64 for instance #270

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.14
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.15-0.20241107103327-b0deabd3fd01
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 @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.14 h1:G3i8N70LBGo1tEFXCCBx5fd+cERBvnBCviFheVLlj80=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.14/go.mod h1:tsKOAAbEQnpXAzqjcZUGzRiVp9QfRViKoTOdIltIMFI=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.15-0.20241107103327-b0deabd3fd01 h1:Ih+LknaNiYFLYUn4D5DZ+yPvy3S1rPdXlXtN+YT5D9o=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.15-0.20241107103327-b0deabd3fd01/go.mod h1:tsKOAAbEQnpXAzqjcZUGzRiVp9QfRViKoTOdIltIMFI=
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccDataSourceInstanceStorageController(t *testing.T) {
Cfg: cfg,
}

return iClient.GetStorageControllerMount(getAccContext(), toInt(attr["instance_id"]), attr["controller_type"], toInt(attr["bus_number"]), toInt(attr["interface_number"]))
return iClient.GetStorageControllerMount(getAccContext(), toInt64(attr["instance_id"]), attr["controller_type"], toInt(attr["bus_number"]), toInt(attr["interface_number"]))
},
}

Expand Down
6 changes: 6 additions & 0 deletions internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func toInt(s string) int {
return i
}

func toInt64(s string) int64 {
i, _ := strconv.ParseInt(s, 10, 64)

return i
}

func getAccContext() context.Context {
return context.Background()
}
2 changes: 1 addition & 1 deletion internal/acceptance_test/resource_instances_clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccResourceInstanceCloneCreate(t *testing.T) {
Client: cl,
Cfg: cfg,
}
id := toInt(attr["id"])
id := toInt64(attr["id"])

return iClient.GetASpecificInstance(getAccContext(), id)
},
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance_test/resource_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccResourceInstanceCreate(t *testing.T) {
Client: cl,
Cfg: cfg,
}
id := toInt(attr["id"])
id := toInt64(attr["id"])

return iClient.GetASpecificInstance(getAccContext(), id)
},
Expand All @@ -50,7 +50,7 @@ func TestAccResourceInstanceCreate_templateErr(t *testing.T) {
Client: cl,
Cfg: cfg,
}
id := toInt(attr["id"])
id := toInt64(attr["id"])

return iClient.GetASpecificInstance(getAccContext(), id)
},
Expand Down
8 changes: 4 additions & 4 deletions internal/cmp/instance_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (i *instanceClone) Create(ctx context.Context, d *utils.Data, meta interfac
}

// Get source instance
sourceID := d.GetInt("source_instance_id")
sourceID := d.GetInt64("source_instance_id")
err := copyInstanceAttribsToClone(ctx, i, &req, d.GetListMap("volume"), sourceID)
if err != nil {
return err
Expand Down Expand Up @@ -165,7 +165,7 @@ func (i *instanceClone) Read(ctx context.Context, d *utils.Data, meta interface{
return readInstance(ctx, i.instanceSharedClient, d, meta, true)
}

func checkInstanceCloneHistory(ctx context.Context, i *instanceClone, meta interface{}, instanceID int) error {
func checkInstanceCloneHistory(ctx context.Context, i *instanceClone, meta interface{}, instanceID int64) error {
errCount := 0
historyRetry := utils.CustomRetry{
InitialDelay: time.Second * 15,
Expand Down Expand Up @@ -211,7 +211,7 @@ func cloneInstance(
i *instanceClone,
meta interface{},
req models.CreateInstanceCloneBody,
sourceID int,
sourceID int64,
) error {
cloneRetry := &utils.CustomRetry{
Cond: func(response interface{}, ResponseErr error) (bool, error) {
Expand Down Expand Up @@ -243,7 +243,7 @@ func copyInstanceAttribsToClone(
i *instanceClone,
req *models.CreateInstanceCloneBody,
volumes []map[string]interface{},
sourceID int,
sourceID int64,
) error {
sourceInstance, err := i.iClient.GetASpecificInstance(ctx, sourceID)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions internal/cmp/instance_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type instanceSharedClient struct {
}

func readInstance(ctx context.Context, sharedClient instanceSharedClient, d *utils.Data, meta interface{}, isClone bool) error {
id := d.GetID()
id := d.GetID64()

log.Printf("[INFO] Get instance with ID %d", id)
// Precheck
Expand Down Expand Up @@ -98,7 +98,7 @@ func readInstance(ctx context.Context, sharedClient instanceSharedClient, d *uti
func updateInstance(ctx context.Context, sharedClient instanceSharedClient, d *utils.Data) error {
log.Printf("[DEBUG] Updating the instance")

id := d.GetID()
id := d.GetID64()
if d.HasChanged("name") || d.HasChanged("group_id") || d.HasChanged("tags") ||
d.HasChanged("labels") || d.HasChanged("environment_code") ||
d.HasChanged("power_schedule_id") {
Expand Down Expand Up @@ -168,7 +168,7 @@ func updateInstance(ctx context.Context, sharedClient instanceSharedClient, d *u

// Delete instance and set ID as ""
func deleteInstance(ctx context.Context, sharedClient instanceSharedClient, d *utils.Data, meta interface{}) error {
id := d.GetID()
id := d.GetID64()
log.Printf("[DEBUG] Deleting instance with ID : %d", id)

// Precheck
Expand Down Expand Up @@ -378,7 +378,7 @@ func instanceCompareVolumes(org, new []map[string]interface{}) ([]map[string]int
func instanceDoPowerTask(
ctx context.Context,
sharedClient instanceSharedClient,
instanceID int,
instanceID int64,
newOp string) error {
var err error

Expand Down Expand Up @@ -422,7 +422,7 @@ func instanceCloneCompareVolume(
func createInstanceSnapshot(
ctx context.Context,
sharedClient instanceSharedClient,
instanceID int,
instanceID int64,
snapshot models.SnapshotBody,
) error {
instanceModel, err := sharedClient.iClient.SnapshotAnInstance(ctx, instanceID, &snapshot)
Expand Down Expand Up @@ -468,7 +468,7 @@ func instanceCheckSnaphotByName(name string, snapshotResp interface{}) int {
return -1
}

func instanceWaitUntilCreated(ctx context.Context, sharedClient instanceSharedClient, meta interface{}, instanceID int) error {
func instanceWaitUntilCreated(ctx context.Context, sharedClient instanceSharedClient, meta interface{}, instanceID int64) error {
errCount := 0
cRetry := utils.CustomRetry{
Timeout: maxTimeout,
Expand Down Expand Up @@ -584,7 +584,7 @@ func instanceUpdateNetworkVolumePlan(
ctx context.Context,
sharedClient instanceSharedClient,
d *utils.Data,
instanceID int,
instanceID int64,
) error {
var resizeReq models.ResizeInstanceBody
if d.HasChanged("volume") {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmp/instance_storage_controller_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newInstanceStorageController(instanceClient *client.InstancesAPIService) *i
func (i *instanceStorageController) Read(ctx context.Context, d *utils.Data, meta interface{}) error {
setMeta(meta, i.iClient.Client)
log.Printf("[DEBUG] Get Instance Storage Controller")
instanceID := d.GetInt("instance_id")
instanceID := d.GetInt64("instance_id")
if instanceID == 0 {
return nil
}
Expand Down
37 changes: 37 additions & 0 deletions internal/utils/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ func (d *Data) GetID() int {

return int(id)
}
func (d *Data) GetID64() int64 {
id, err := ParseInt(d.d.Id())
if err != nil {
d.err("id", ErrInvalidType)

return NAN
}

return int64(id)
}

// GetIDString returns ID as string
func (d *Data) GetIDString() string {
Expand Down Expand Up @@ -205,6 +215,33 @@ func (d *Data) GetInt(key string, ignore ...bool) int {
return valInt
}

func (d *Data) GetInt64(key string, ignore ...bool) int64 {
valInter, ok := d.getOk(key, ignore)
if !ok {
return NAN
}
valInt, ok := valInter.(int64)
var err error
if !ok {
valString, ok := valInter.(string)
if ok {
valInt, err = ParseInt(valString)
if err != nil {
d.err(key, ErrInvalidType+valString)

return NAN
}

return valInt
}
d.err(key, ErrInvalidType)

return NAN
}

return valInt
}

func (d *Data) getOk(key string, ignore []bool) (interface{}, bool) {
val, ok := d.d.GetOk(key)
if len(ignore) != 0 && !ignore[0] {
Expand Down
Loading