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 cpu burst factory attribute to Tsuru app resource #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions internal/provider/resource_tsuru_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func resourceTsuruApplication() *schema.Resource {
Description: "Plan",
Required: true,
},
"burst_factory": {
Copy link
Member

@wpjunior wpjunior Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aristidesneto could you rename to custom_cpu_burst or custom_cpu_burst_factor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wpjunior renamed to custom_cpu_burst.

Type: schema.TypeFloat,
Description: "CPU burst factory override",
Optional: true,
},
"team_owner": {
Type: schema.TypeString,
Description: "Application owner",
Expand Down Expand Up @@ -283,6 +288,11 @@ func resourceTsuruApplicationUpdate(ctx context.Context, d *schema.ResourceData,
Tags: tags,
}

if cpu_burst, ok := d.GetOk("burst_factory"); ok {
cpuBurstValue := cpu_burst.(float64)
app.Planoverride.CpuBurst = &cpuBurstValue
}

if d.HasChange("metadata") {
old, new := d.GetChange("metadata")
oldMetadata := metadataFromResourceData(old)
Expand Down Expand Up @@ -371,6 +381,10 @@ func resourceTsuruApplicationRead(ctx context.Context, d *schema.ResourceData, m
d.Set("team_owner", app.TeamOwner)
d.Set("cluster", app.Cluster)

if app.Plan.Override.CpuBurst != nil {
d.Set("burst_factory", app.Plan.Override.CpuBurst)
}

if app.Description != "" {
d.Set("description", app.Description)
}
Expand Down
10 changes: 9 additions & 1 deletion internal/provider/resource_tsuru_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ func TestAccResourceTsuruApp(t *testing.T) {
}

if iterationCount == 1 {
cpuBurstValue := 1.5
app := &tsuru.App{
Name: name,
Description: "my app description",
TeamOwner: "my-team",
Platform: "python",
Plan: tsuru.Plan{Name: "c2m4"},
Plan: tsuru.Plan{
Name: "c2m4",
Override: tsuru.PlanOverride{
CpuBurst: &cpuBurstValue,
},
},
Cluster: "my-cluster-01",
Pool: "prod",
Provisioner: "kubernetes",
Expand Down Expand Up @@ -241,6 +247,7 @@ func TestAccResourceTsuruApp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "description", "my app description"),
resource.TestCheckResourceAttr(resourceName, "platform", "python"),
resource.TestCheckResourceAttr(resourceName, "plan", "c2m4"),
resource.TestCheckResourceAttr(resourceName, "burst_factory", "1.5"),
resource.TestCheckResourceAttr(resourceName, "team_owner", "my-team"),
resource.TestCheckResourceAttr(resourceName, "pool", "prod"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tagA"),
Expand Down Expand Up @@ -277,6 +284,7 @@ func testAccResourceTsuruApp_basic() string {
description = "my app description"
platform = "python"
plan = "c2m4"
burst_factory = "1.5"
team_owner = "my-team"
pool = "prod"
tags = ["tagA", "tagB"]
Expand Down