Skip to content

Commit

Permalink
Fix rebalancing schedules and phase 1 clusters (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanstankovcast authored Nov 14, 2023
1 parent 290a4d9 commit dd616bc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,55 @@ package castai

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"testing"
)

func TestAccResourceRebalancingJob_basic(t *testing.T) {
func TestAccResourceRebalancingJob_eks(t *testing.T) {
rName := fmt.Sprintf("%v-rebalancing-job-%v", ResourcePrefix, acctest.RandString(8))
clusterName := "core-tf-acc"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },

ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: makeInitialRebalancingJobConfig(),
Config: makeInitialRebalancingJobConfig(rName, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("castai_rebalancing_job.test", "enabled", "true"),
),
},
{
ResourceName: "castai_rebalancing_job.test",
ImportStateIdFunc: func(s *terraform.State) (string, error) {
clusterID := s.RootModule().Resources["castai_eks_clusterid.test"].Primary.ID
rebalancingScheduleName := "test"
return fmt.Sprintf("%v/%v", clusterID, rebalancingScheduleName), nil
clusterID := s.RootModule().Resources["castai_eks_cluster.test"].Primary.ID
return fmt.Sprintf("%v/%v", clusterID, rName), nil
},
ImportState: true,
ImportStateVerify: true,
},
{
Config: makeUpdatedRebalancingJobConfig(),
Config: makeUpdatedRebalancingJobConfig(rName, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("castai_rebalancing_job.test", "enabled", "false"),
),
},
},
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "~> 4.0",
},
},
})
}

func makeRebalancingJobConfig(config string) string {
func makeRebalancingJobConfig(rName, config string) string {
template := `
resource "castai_eks_clusterid" "test" {
account_id = "fake"
region = "eu-central-1"
cluster_name = "fake"
}
resource "castai_rebalancing_schedule" "test" {
name = "test"
name = %[1]q
schedule {
cron = "5 4 * * *"
}
Expand All @@ -64,17 +66,18 @@ resource "castai_rebalancing_schedule" "test" {
}
resource "castai_rebalancing_job" "test" {
cluster_id = castai_eks_clusterid.test.id
cluster_id = castai_eks_cluster.test.id
rebalancing_schedule_id = castai_rebalancing_schedule.test.id
%s
%[2]s
}
`
return fmt.Sprintf(template, config)
return fmt.Sprintf(template, rName, config)
}

func makeInitialRebalancingJobConfig() string {
return makeRebalancingJobConfig("")
func makeInitialRebalancingJobConfig(rName, clusterName string) string {
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), makeRebalancingJobConfig(rName, ""))
}
func makeUpdatedRebalancingJobConfig() string {
return makeRebalancingJobConfig("enabled=false")

func makeUpdatedRebalancingJobConfig(rName, clusterName string) string {
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), makeRebalancingJobConfig(rName, "enabled=false"))
}
19 changes: 15 additions & 4 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd616bc

Please sign in to comment.