forked from infracost/infracost
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for code engine, in progress (#227)
* Add support for code engine, in progress * Fixed tests * Add support for code engine build * add usage variable example to infracost example * add indent to registry --------- Co-authored-by: eugene-koo <[email protected]>
- Loading branch information
Showing
26 changed files
with
1,166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
internal/providers/terraform/ibm/code_engine_build_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
internal/providers/terraform/ibm/code_engine_function_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
internal/providers/terraform/ibm/testdata/code_engine_app_test/code_engine_app_test.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
53 changes: 53 additions & 0 deletions
53
internal/providers/terraform/ibm/testdata/code_engine_app_test/code_engine_app_test.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
14 changes: 14 additions & 0 deletions
14
...rnal/providers/terraform/ibm/testdata/code_engine_app_test/code_engine_app_test.usage.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
30 changes: 30 additions & 0 deletions
30
...nal/providers/terraform/ibm/testdata/code_engine_build_test/code_engine_build_test.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.