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

use catalogRegion instead of region for filters #161

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
└─ VPC egress us-south (over 149995 GB) 0 GB $0.00

mycluster
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 2,190 hours $608.59
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 2,190 hours $608.59
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 2,190 hours $682.31
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 2,190 hours $682.31

mycluster-without-usage
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 3 hours $0.83
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 3 hours $0.83
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 3 hours $0.93
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 3 hours $0.93

mycluster-without-usage
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 2,190 hours $983.08
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 2,190 hours $983.08
myrokscluster-with-usage
├─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 2,190 hours $1,056.80
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-2) x(3) workers 2,190 hours $1,056.80

OVERALL TOTAL $7,570.40
OVERALL TOTAL $7,865.51
──────────────────────────────────
6 cloud resources were detected:
∙ 4 were estimated, 1 of which usage-based costs, see https://infracost.io/usage-file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@

Name Monthly Qty Unit Monthly Cost
ibm_container_vpc_worker_pool.cluster_pool
└─ VPC Container Work Zone flavor: (bx2.2x8) region: (us-south) name: (us-south-2) x(3) workers 2,190 hours $293.67
ibm_container_vpc_worker_pool.cluster_pool_without_usage
└─ VPC Container Work Zone flavor: (bx2.2x8) region: (us-south) name: (us-south-2) x(3) workers 3 hours $0.40
ibm_is_vpc.vpc1
├─ VPC instance 1 Instance $0.00
├─ VPC egress free allowance (first 5GB) 5 GB $0.00
└─ VPC egress us-south (first 9995 GB) 9,995 GB $908.70
└─ VPC egress us-south (next 40000 GB) 40,000 GB $3,469.40
└─ VPC egress us-south (next 100000 GB) 100 GB $7.32
└─ VPC egress us-south (over 149995 GB) 0 GB $0.00
mycluster
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (us-south) name: (us-south-1) x(3) workers 2,190 hours $608.59
OVERALL TOTAL $5,288.07
Name Monthly Qty Unit Monthly Cost

ibm_container_vpc_worker_pool.cluster_pool
└─ VPC Container Work Zone flavor: (bx2.2x8) region: (eu-de) name: (eu-de-2) x(3) workers 2,190 hours $318.84

ibm_container_vpc_worker_pool.cluster_pool_without_usage
└─ VPC Container Work Zone flavor: (bx2.2x8) region: (eu-de) name: (eu-de-2) x(3) workers 3 hours $0.44

ibm_is_vpc.vpc1
├─ VPC instance 1 Instance $0.00
├─ VPC egress free allowance (first 5GB) 5 GB $0.00
└─ VPC egress eu-de (first 9995 GB) 9,995 GB $1,002.70
└─ VPC egress eu-de (next 40000 GB) 40,000 GB $3,803.80
└─ VPC egress eu-de (next 100000 GB) 100 GB $8.05
└─ VPC egress eu-de (over 149995 GB) 0 GB $0.00

mycluster
└─ VPC Container Work Zone flavor: (bx2.4x16) region: (eu-de) name: (eu-de-1) x(3) workers 2,190 hours $682.31

OVERALL TOTAL $5,816.13
──────────────────────────────────
6 cloud resources were detected:
∙ 4 were estimated, 3 of which include usage-based costs, see https://infracost.io/usage-file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ terraform {

provider "ibm" {
generation = 2
region = "us-south"
region = "eu-de"
}

resource "ibm_is_vpc" "vpc1" {
Expand All @@ -19,14 +19,14 @@ resource "ibm_is_vpc" "vpc1" {
resource "ibm_is_subnet" "subnet1" {
name = "mysubnet1"
vpc = ibm_is_vpc.vpc1.id
zone = "us-south-1"
zone = "eu-de-1"
total_ipv4_address_count = 256
}

resource "ibm_is_subnet" "subnet2" {
name = "mysubnet2"
vpc = ibm_is_vpc.vpc1.id
zone = "us-south-2"
zone = "eu-de-2"
total_ipv4_address_count = 256
}

Expand All @@ -38,7 +38,7 @@ resource "ibm_container_vpc_cluster" "cluster" {
kube_version = "1.17.5"
zones {
subnet_id = ibm_is_subnet.subnet1.id
name = "us-south-1"
name = "eu-de-1"
}
}

Expand All @@ -49,7 +49,7 @@ resource "ibm_container_vpc_worker_pool" "cluster_pool" {
vpc_id = ibm_is_vpc.vpc1.id
worker_count = 3
zones {
name = "us-south-2"
name = "eu-de-2"
subnet_id = ibm_is_subnet.subnet2.id
}
}
Expand All @@ -61,7 +61,7 @@ resource "ibm_container_vpc_worker_pool" "cluster_pool_without_usage" {
vpc_id = ibm_is_vpc.vpc1.id
worker_count = 3
zones {
name = "us-south-2"
name = "eu-de-2"
subnet_id = ibm_is_subnet.subnet2.id
}
}
4 changes: 3 additions & 1 deletion internal/resources/ibm/container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ func (r *ContainerVpcCluster) BuildResource() *schema.Resource {
useOcpPrices = true
}
}
// filter on the catalogRegion in the product attribute instead of the region column because
// some regions (like eu-de) are recorded under eu-central instead, which isn't used in provisioning
var attributeFilters = []*schema.AttributeFilter{
{Key: "provider", Value: strPtr("vpc-gen2")},
{Key: "flavor", Value: strPtr(r.Flavor)},
{Key: "serverType", Value: strPtr("virtual")},
{Key: "isolation", Value: strPtr("public")},
{Key: "operatingSystem", ValueRegex: strPtr(fmt.Sprintf("/%s/i", operatingSystem))},
{Key: "catalogRegion", ValueRegex: strPtr(r.Region)},
}
if useOcpPrices {
attributeFilters = append(attributeFilters, &schema.AttributeFilter{
Expand Down Expand Up @@ -98,7 +101,6 @@ func (r *ContainerVpcCluster) BuildResource() *schema.Resource {
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("ibm"),
Service: strPtr("containers-kubernetes"),
Region: strPtr(r.Region),
AttributeFilters: attributeFilters,
},
}
Expand Down
14 changes: 7 additions & 7 deletions internal/resources/ibm/container_vpc_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ func (r *ContainerVpcWorkerPool) PopulateUsage(u *schema.UsageData) {
func (r *ContainerVpcWorkerPool) BuildResource() *schema.Resource {
isOpenshift := strings.HasSuffix(strings.ToLower(r.KubeVersion), "openshift")
operatingSystem := "UBUNTU"
useOcpPrices := false
if isOpenshift {
operatingSystem = "RHEL"
// if an entitlement is specified, then ocp licensing is already covered. use pricing that
// does not include ocp charges.
if !r.Entitlement {
useOcpPrices = true
}
}
var attributeFilters = []*schema.AttributeFilter{
{Key: "provider", Value: strPtr("vpc-gen2")},
Expand All @@ -60,14 +66,10 @@ func (r *ContainerVpcWorkerPool) BuildResource() *schema.Resource {
{Key: "catalogRegion", Value: strPtr(r.Region)},
{Key: "operatingSystem", ValueRegex: strPtr(fmt.Sprintf("/%s/i", operatingSystem))},
}
if r.Entitlement {
if useOcpPrices {
attributeFilters = append(attributeFilters, &schema.AttributeFilter{
Key: "ocpIncluded", Value: strPtr("true"),
})
} else {
attributeFilters = append(attributeFilters, &schema.AttributeFilter{
Key: "ocpIncluded", Value: strPtr(""),
})
}
WorkerCount := decimalPtr(decimal.NewFromInt(1))
if r.WorkerCount != 0 {
Expand All @@ -82,7 +84,6 @@ func (r *ContainerVpcWorkerPool) BuildResource() *schema.Resource {
quantity := WorkerCount.Mul(*instanceHours)

costComponents := []*schema.CostComponent{}

for _, zone := range r.Zones {
zoneCostComponent := &schema.CostComponent{
Name: fmt.Sprintf("VPC Container Work Zone flavor: (%s) region: (%s) name: (%s) x(%d) workers", r.Flavor, r.Region, zone.Name, r.WorkerCount),
Expand All @@ -91,7 +92,6 @@ func (r *ContainerVpcWorkerPool) BuildResource() *schema.Resource {
MonthlyQuantity: decimalPtr(quantity),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("ibm"),
Region: strPtr("us-south"),
Service: strPtr("containers-kubernetes"),
AttributeFilters: attributeFilters,
},
Expand Down
Loading