From e1c07a366c658f1fd43136afeeac797840703973 Mon Sep 17 00:00:00 2001 From: "hlem@ca.ibm.com" Date: Mon, 15 Apr 2024 11:54:30 -0400 Subject: [PATCH] use catalogRegion instead of region for filters --- .../container_vpc_cluster_test.golden | 16 ++++---- .../container_vpc_worker_pool_test.golden | 40 +++++++++---------- .../container_vpc_worker_pool_test.tf | 12 +++--- .../resources/ibm/container_vpc_cluster.go | 4 +- .../ibm/container_vpc_worker_pool.go | 14 +++---- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/internal/providers/terraform/ibm/testdata/container_vpc_cluster_test/container_vpc_cluster_test.golden b/internal/providers/terraform/ibm/testdata/container_vpc_cluster_test/container_vpc_cluster_test.golden index a518ef7eee0..8ffc142dbc5 100644 --- a/internal/providers/terraform/ibm/testdata/container_vpc_cluster_test/container_vpc_cluster_test.golden +++ b/internal/providers/terraform/ibm/testdata/container_vpc_cluster_test/container_vpc_cluster_test.golden @@ -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 diff --git a/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.golden b/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.golden index 34405c7455f..f445dde4a2a 100644 --- a/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.golden +++ b/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.golden @@ -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 diff --git a/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.tf b/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.tf index 219c3bc4ee0..e78d468913e 100644 --- a/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.tf +++ b/internal/providers/terraform/ibm/testdata/container_vpc_worker_pool_test/container_vpc_worker_pool_test.tf @@ -9,7 +9,7 @@ terraform { provider "ibm" { generation = 2 - region = "us-south" + region = "eu-de" } resource "ibm_is_vpc" "vpc1" { @@ -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 } @@ -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" } } @@ -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 } } @@ -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 } } diff --git a/internal/resources/ibm/container_vpc_cluster.go b/internal/resources/ibm/container_vpc_cluster.go index c60a40b0534..832964138b3 100644 --- a/internal/resources/ibm/container_vpc_cluster.go +++ b/internal/resources/ibm/container_vpc_cluster.go @@ -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{ @@ -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, }, } diff --git a/internal/resources/ibm/container_vpc_worker_pool.go b/internal/resources/ibm/container_vpc_worker_pool.go index 0d66270a7ed..ea4efc0143e 100644 --- a/internal/resources/ibm/container_vpc_worker_pool.go +++ b/internal/resources/ibm/container_vpc_worker_pool.go @@ -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")}, @@ -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 { @@ -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), @@ -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, },