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

Fix ibm_is_instance pricing and relevant tests #199

Merged
merged 5 commits into from
Oct 10, 2024
Merged
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
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
Loading