Skip to content

Commit

Permalink
Fix is_instance pricing and relevant tests (#199)
Browse files Browse the repository at this point in the history
* Fix is_instance pricing + tests

* Update Terraform tests for local run

* Add support for boot volumes + improved testing

---------

Co-authored-by: Hilton Lem <[email protected]>
  • Loading branch information
luisarojas and hiltol authored Oct 10, 2024
1 parent 0d635a9 commit 357217b
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 510 deletions.
35 changes: 15 additions & 20 deletions internal/providers/terraform/ibm/is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func getIsInstanceRegistryItem() *schema.RegistryItem {
// valid profile values https://cloud.ibm.com/docs/vpc?topic=vpc-profiles&interface=ui
// profile names in Global Catalog contain dots instead of dashes
func newIsInstance(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {

region := d.Get("region").String()
profile := d.Get("profile").String()
zone := d.Get("zone").String()
Expand All @@ -25,26 +26,17 @@ func newIsInstance(d *schema.ResourceData, u *schema.UsageData) *schema.Resource
isDedicated := !((dedicatedHost == "") && (dedicatedHostGroup == ""))
name := d.Get("name").String()

boot_volume := make([]struct {
Name string
Size int64
}, 0)
// Defaults
bootVolumeName := "Unnamed boot volume"
var bootVolumeSize int64 = 100

boot_volume_parse := d.Get("boot_volume").Array()
if len(boot_volume_parse) > 0 {
for _, volume := range boot_volume_parse {
name := volume.Get("name").String()
if name == "" {
name = "Unnamed boot volume"
}
size := volume.Get("size").Int()
if size == 0 {
size = 100
}
boot_volume = append(boot_volume, struct {
Name string
Size int64
}{Name: name, Size: size})
bv := d.Get("boot_volume").Array()
if len(bv) > 0 {
if bv[0].Get("name").String() != "" {
bootVolumeName = bv[0].Get("name").String()
}
if bv[0].Get("size").Int() != 0 {
bootVolumeSize = bv[0].Get("size").Int()
}
}

Expand All @@ -54,7 +46,10 @@ func newIsInstance(d *schema.ResourceData, u *schema.UsageData) *schema.Resource
Profile: profile,
Zone: zone,
IsDedicated: isDedicated,
BootVolume: boot_volume,
BootVolume: struct {
Name string
Size int64
}{Name: bootVolumeName, Size: bootVolumeSize},
}

r.PopulateUsage(u)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@

Name Monthly Qty Unit Monthly Cost

ibm_is_instance.testBalancedInstance
├─ CPU hours (32 CPUs, us-east-1) (first 1 CPU hours) 1 CPU hours $0.31
├─ CPU hours (32 CPUs, us-east-1) (over 0 CPU hours) 1 CPU hours $0.02
├─ Memory hours (128 GB, us-east-1) (first 1 Memory hours) 1 Memory hours $0.57
├─ Memory hours (128 GB, us-east-1) (over 0 Memory hours) 1 Memory hours $0.01
└─ Storage GB hours (600 GB * 2, us-east-1) 876,000 Storage GB hours $23,652.00

ibm_is_instance.testBalancedInstanceWithBootVolume
├─ CPU hours (8 CPUs, us-east-1) (first 1 CPU hours) 1 CPU hours $0.31
├─ CPU hours (8 CPUs, us-east-1) (over 0 CPU hours) 1 CPU hours $0.02
├─ Memory hours (32 GB, us-east-1) (first 1 Memory hours) 1 Memory hours $0.57
├─ Memory hours (32 GB, us-east-1) (over 0 Memory hours) 1 Memory hours $0.01
└─ Boot volume (boot-volume-label, 150 GB) 109,500 GB Hours $12.59

ibm_is_instance.testComputeInstance
├─ CPU hours (2 CPUs, us-east-1) (first 1 CPU hours) 1 CPU hours $0.31
├─ CPU hours (2 CPUs, us-east-1) (over 0 CPU hours) 1 CPU hours $0.02
└─ Memory hours (4 GB, us-east-1) (first 1 Memory hours) 1 Memory hours $0.84
└─ Memory hours (4 GB, us-east-1) (over 0 Memory hours) 1 Memory hours $0.01

ibm_is_instance.testGpuInstance
├─ CPU hours (16 CPUs, us-east-1) (first 1 CPU hours) 1 CPU hours $0.33
├─ CPU hours (16 CPUs, us-east-1) (over 0 CPU hours) 1 CPU hours $0.03
├─ Memory hours (128 GB, us-east-1) (first 1 Memory hours) 1 Memory hours $0.45
├─ Memory hours (128 GB, us-east-1) (over 0 Memory hours) 1 Memory hours $0.00
└─ Gpu hours (2 GPUs, Tesla V100, us-east-1) 1,460 Gpu hours $3,051.40

ibm_is_instance.testIbmZInstance
├─ CPU hours (16 CPUs, us-east-1) (first 1 CPU hours) 1 CPU hours $0.39
├─ CPU hours (16 CPUs, us-east-1) (over 0 CPU hours) 1 CPU hours $0.05
└─ Memory hours (64 GB, us-east-1) (first 1 Memory hours) 1 Memory hours $0.56
└─ Memory hours (64 GB, us-east-1) (over 0 Memory hours) 1 Memory hours $0.01

ibm_is_instance.testInstanceWithoutUsage
├─ CPU hours (2 CPUs, us-east-1) (first 1 CPU hours) Monthly cost depends on usage: $0.31 per CPU hours
├─ CPU hours (2 CPUs, us-east-1) (over 0 CPU hours) Monthly cost depends on usage: $0.0249876337 per CPU hours
└─ Memory hours (4 GB, us-east-1) (first 1 Memory hours) Monthly cost depends on usage: $0.84 per Memory hours
└─ Memory hours (4 GB, us-east-1) (over 0 Memory hours) Monthly cost depends on usage: $0.0075416569 per Memory hours

ibm_is_vpc.testVpc
├─ VPC instance 1 Instance $0.00
├─ VPC egress free allowance (first 5GB) Monthly cost depends on usage: $0.00 per GB
└─ VPC egress us-east (first 9995 GB) Monthly cost depends on usage: $0.090915 per GB
└─ VPC egress us-east (next 40000 GB) Monthly cost depends on usage: $0.086735 per GB
└─ VPC egress us-east (next 100000 GB) Monthly cost depends on usage: $0.07315 per GB
└─ VPC egress us-east (over 149995 GB) Monthly cost depends on usage: $0.05225 per GB

OVERALL TOTAL $26,720.80
Name Monthly Qty Unit Monthly Cost

ibm_is_instance.vsi
├─ Instance Hours (cx2-2x4) 730 Hours $64.97
└─ Boot volume (Unnamed boot volume, 100 GB) 73,000 Hours $8.39

ibm_is_instance.vsi_boot_volume
├─ Instance Hours (cx2-2x4) 730 Hours $64.97
└─ Boot volume (boot-volume-label, 250 GB) 182,500 Hours $20.98

ibm_is_instance.vsi_dedicated_host
├─ Instance Hours (cx2-2x4) 730 Hours $64.97
└─ Boot volume (Unnamed boot volume, 100 GB) 73,000 Hours $8.39

ibm_is_vpc.vpc
├─ VPC instance 1 Instance $0.00
├─ VPC egress free allowance (first 5GB) Monthly cost depends on usage: $0.00 per GB
└─ VPC egress us-south (first 9995 GB) Monthly cost depends on usage: $0.090915 per GB
└─ VPC egress us-south (next 40000 GB) Monthly cost depends on usage: $0.086735 per GB
└─ VPC egress us-south (next 100000 GB) Monthly cost depends on usage: $0.07315 per GB
└─ VPC egress us-south (over 149995 GB) Monthly cost depends on usage: $0.05225 per GB

OVERALL TOTAL $232.67
──────────────────────────────────
9 cloud resources were detected:
7 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
2 were free:
4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
3 were free:
∙ 1 x ibm_is_ssh_key
∙ 1 x ibm_is_subnet
∙ 1 x ibm_is_subnet
∙ 1 x ibm_resource_group
∙ 2 are not supported yet, see https://infracost.io/requested-resources:
∙ 1 x ibm_is_dedicated_host
∙ 1 x ibm_is_dedicated_host_group
Loading

0 comments on commit 357217b

Please sign in to comment.