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

Add support for Code Engine #227

Merged
merged 6 commits into from
Nov 14, 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
15 changes: 15 additions & 0 deletions infracost-usage-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,21 @@ resource_usage:
monthly_data_retrieval: 1000 # Amount of data retrieved in GB
public_standard_egress: 1000 # Amount of data downloaded in GB

ibm_code_engine_app.ce_app:
http_request_calls: 1000
instance_hours: 1

ibm_code_engine_build.ce_build:
instance_hours: 1

ibm_code_engine_function.ce_function:
http_request_calls: 100
instance_hours: 1

ibm_code_engine_job.ce_job:
scaled_instances: 1
instance_hours: 1

ibm_container_vpc_cluster.cluster:
monthly_instance_hours: 730 # Monthly number of hours an instance runs

Expand Down
38 changes: 38 additions & 0 deletions internal/providers/terraform/ibm/code_engine_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ibm

import (
"github.com/infracost/infracost/internal/resources/ibm"
"github.com/infracost/infracost/internal/schema"
)

func getCodeEngineAppRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "ibm_code_engine_app",
RFunc: newCodeEngineApp,
}
}

func newCodeEngineApp(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
region := d.Get("region").String()
cpu := d.Get("scale_cpu_limit").String()
memory := d.Get("scale_memory_limit").String()
scaleinitialinstances := d.Get("scale_initial_instances").Int()
r := &ibm.CodeEngineApp{
Address: d.Address,
Region: region,
CPU: cpu,
Memory: memory,
ScaleInitialInstances: scaleinitialinstances,
}
r.PopulateUsage(u)

configuration := make(map[string]any)
configuration["region"] = region
configuration["cpu"] = cpu
configuration["memory"] = memory
configuration["scaleinitialinstances"] = scaleinitialinstances

SetCatalogMetadata(d, d.Type, configuration)

return r.BuildResource()
}
16 changes: 16 additions & 0 deletions internal/providers/terraform/ibm/code_engine_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ibm_test

import (
"testing"

"github.com/infracost/infracost/internal/providers/terraform/tftest"
)

func TestCodeEngineApp(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}

tftest.GoldenFileResourceTests(t, "code_engine_app_test")
}
32 changes: 32 additions & 0 deletions internal/providers/terraform/ibm/code_engine_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ibm

import (
"github.com/infracost/infracost/internal/resources/ibm"
"github.com/infracost/infracost/internal/schema"
)

func getCodeEngineBuildRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "ibm_code_engine_build",
RFunc: newCodeEngineBuild,
}
}

func newCodeEngineBuild(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
region := d.Get("region").String()
strategysize := d.Get("strategy_size").String()
r := &ibm.CodeEngineBuild{
Address: d.Address,
Region: region,
StrategySize: strategysize,
}
r.PopulateUsage(u)

configuration := make(map[string]any)
configuration["region"] = region
configuration["strategysize"] = strategysize

SetCatalogMetadata(d, d.Type, configuration)

return r.BuildResource()
}
16 changes: 16 additions & 0 deletions internal/providers/terraform/ibm/code_engine_build_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ibm_test

import (
"testing"

"github.com/infracost/infracost/internal/providers/terraform/tftest"
)

func TestCodeEngineBuild(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}

tftest.GoldenFileResourceTests(t, "code_engine_build_test")
}
35 changes: 35 additions & 0 deletions internal/providers/terraform/ibm/code_engine_function.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ibm

import (
"github.com/infracost/infracost/internal/resources/ibm"
"github.com/infracost/infracost/internal/schema"
)

func getCodeEngineFunctionRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "ibm_code_engine_function",
RFunc: newCodeEngineFunction,
}
}

func newCodeEngineFunction(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
region := d.Get("region").String()
cpu := d.Get("scale_cpu_limit").String()
memory := d.Get("scale_memory_limit").String()
r := &ibm.CodeEngineFunction{
Address: d.Address,
Region: region,
CPU: cpu,
Memory: memory,
}
r.PopulateUsage(u)

configuration := make(map[string]any)
configuration["region"] = region
configuration["cpu"] = cpu
configuration["memory"] = memory

SetCatalogMetadata(d, d.Type, configuration)

return r.BuildResource()
}
16 changes: 16 additions & 0 deletions internal/providers/terraform/ibm/code_engine_function_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ibm_test

import (
"testing"

"github.com/infracost/infracost/internal/providers/terraform/tftest"
)

func TestCodeEngineFunction(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}

tftest.GoldenFileResourceTests(t, "code_engine_function_test")
}
35 changes: 35 additions & 0 deletions internal/providers/terraform/ibm/code_engine_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ibm

import (
"github.com/infracost/infracost/internal/resources/ibm"
"github.com/infracost/infracost/internal/schema"
)

func getCodeEngineJobRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "ibm_code_engine_job",
RFunc: newCodeEngineJob,
}
}

func newCodeEngineJob(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
region := d.Get("region").String()
cpu := d.Get("scale_cpu_limit").String()
memory := d.Get("scale_memory_limit").String()
r := &ibm.CodeEngineJob{
Address: d.Address,
Region: region,
CPU: cpu,
Memory: memory,
}
r.PopulateUsage(u)

configuration := make(map[string]any)
configuration["region"] = region
configuration["cpu"] = cpu
configuration["memory"] = memory

SetCatalogMetadata(d, d.Type, configuration)

return r.BuildResource()
}
16 changes: 16 additions & 0 deletions internal/providers/terraform/ibm/code_engine_job_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ibm_test

import (
"testing"

"github.com/infracost/infracost/internal/providers/terraform/tftest"
)

func TestCodeEngineJob(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}

tftest.GoldenFileResourceTests(t, "code_engine_job_test")
}
9 changes: 9 additions & 0 deletions internal/providers/terraform/ibm/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ var ResourceRegistry []*schema.RegistryItem = []*schema.RegistryItem{
getPiInstanceRegistryItem(),
getIsLbRegistryItem(),
getIbmPiVolumeRegistryItem(),
getCodeEngineAppRegistryItem(),
getCodeEngineBuildRegistryItem(),
getCodeEngineFunctionRegistryItem(),
getCodeEngineJobRegistryItem(),
getDatabaseRegistryItem(),
getIsShareRegistryItem(),
getIsVpnServerRegistryItem(),
Expand Down Expand Up @@ -81,6 +85,11 @@ var FreeResources = []string{
"ibm_cd_toolchain_tool_sonarqube",
"ibm_cloud_shell_account_settings",
"ibm_cloudant_database",
"ibm_code_engine_binding",
"ibm_code_engine_config_map",
"ibm_code_engine_domain_mapping",
"ibm_code_engine_project",
"ibm_code_engine_secret",
"ibm_container_addons",
"ibm_cos_bucket_object_lock_configuration",
"ibm_dns_custom_resolver",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Name Monthly Qty Unit Monthly Cost

ibm_code_engine_app.ce_app
├─ Virtual Processor Cores (1 initial instances) 1 vCPU Hours $0.12
├─ RAM (1 initial instances) 2 GB Hours $0.03
└─ Million HTTP calls 0.001 Million HTTP calls $0.00

ibm_code_engine_app.ce_app2
├─ Virtual Processor Cores (1 initial instances) 1 vCPU Hours $0.12
├─ RAM (1 initial instances) 4 GB Hours $0.05
└─ Million HTTP calls 0.001 Million HTTP calls $0.00

ibm_code_engine_app.ce_app3
├─ Virtual Processor Cores (2 initial instances) 2 vCPU Hours $0.25
├─ RAM (2 initial instances) 4 GB Hours $0.05
└─ Million HTTP calls 100 Million HTTP calls $53.80

ibm_code_engine_app.ce_app4
├─ Virtual Processor Cores (3 initial instances) 3 vCPU Hours $0.37
├─ RAM (3 initial instances) 12 GB Hours $0.15
└─ Million HTTP calls 20 Million HTTP calls $10.76

OVERALL TOTAL $65.71
──────────────────────────────────
6 cloud resources were detected:
∙ 4 were estimated
∙ 2 were free:
∙ 1 x ibm_code_engine_project
∙ 1 x ibm_resource_group
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
}
}
}

provider "ibm" {
region = "us-south"
}

resource "ibm_resource_group" "test_group" {
name = "test-resource-group"
}

resource "ibm_code_engine_project" "ce_project" {
name = "ce_project"
resource_group_id = ibm_resource_group.test_group.id
}

resource "ibm_code_engine_app" "ce_app" {
project_id = ibm_code_engine_project.ce_project.id
name = "ce-app"
image_reference = "icr.io/codeengine/helloworld"
scale_initial_instances = 1
scale_memory_limit = "2G"
scale_cpu_limit = "1"
}

resource "ibm_code_engine_app" "ce_app2" {
project_id = ibm_code_engine_project.ce_project.id
name = "ce-app2"
image_reference = "icr.io/codeengine/helloworld"
}

resource "ibm_code_engine_app" "ce_app3" {
project_id = ibm_code_engine_project.ce_project.id
name = "ce-app3"
image_reference = "icr.io/codeengine/helloworld"
scale_initial_instances = 2
scale_memory_limit = "2G"
scale_cpu_limit = "1"
}

resource "ibm_code_engine_app" "ce_app4" {
project_id = ibm_code_engine_project.ce_project.id
name = "ce-app4"
image_reference = "icr.io/codeengine/helloworld"
scale_initial_instances = 3
scale_memory_limit = "2000M"
scale_cpu_limit = "0.5"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0.1
resource_usage:
ibm_code_engine_app.ce_app:
http_request_calls: 1000
instance_hours: 1
ibm_code_engine_app.ce_app2:
http_request_calls: 1000
instance_hours: 1
ibm_code_engine_app.ce_app3:
http_request_calls: 100000000
instance_hours: 1
ibm_code_engine_app.ce_app4:
http_request_calls: 20000000
instance_hours: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Name Monthly Qty Unit Monthly Cost

ibm_code_engine_build.ce_build
├─ Virtual Processor Cores (small build) 0.5 vCPU Hours $0.06
└─ RAM (small build) 2 GB Hours $0.03

ibm_code_engine_build.ce_build2
├─ Virtual Processor Cores (medium build) 1 vCPU Hours $0.12
└─ RAM (medium build) 4 GB Hours $0.05

ibm_code_engine_build.ce_build3
├─ Virtual Processor Cores (large build) 2 vCPU Hours $0.25
└─ RAM (large build) 8 GB Hours $0.10

ibm_code_engine_build.ce_build4
├─ Virtual Processor Cores (xlarge build) 4 vCPU Hours $0.49
└─ RAM (xlarge build) 16 GB Hours $0.20

ibm_code_engine_build.ce_build5
├─ Virtual Processor Cores (xxlarge build) 12 vCPU Hours $1.48
└─ RAM (xxlarge build) 48 GB Hours $0.61

OVERALL TOTAL $3.41
──────────────────────────────────
7 cloud resources were detected:
∙ 5 were estimated
∙ 2 were free:
∙ 1 x ibm_code_engine_project
∙ 1 x ibm_resource_group
Loading
Loading