Skip to content

Commit

Permalink
Merge branch 'main' into avi-update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekbhakat authored Dec 3, 2024
2 parents 1fe0bc3 + 36f4aaf commit 72d6434
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
19 changes: 2 additions & 17 deletions internal/provider/resources/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,14 +872,6 @@ func validateHostedConfig(ctx context.Context, data *models.DeploymentResource)
)
}

// Need to check that scaling_spec is only for is_development_mode set to true
if !data.IsDevelopmentMode.ValueBool() && !data.ScalingSpec.IsNull() {
diags.AddError(
"scaling_spec (hibernation) is only supported for is_development_mode set to true",
"Either set is_development_mode to true or remove scaling_spec",
)
}

// Need to check that scaling_spec has either override or schedules
if !data.ScalingSpec.IsNull() {
var scalingSpec models.DeploymentScalingSpec
Expand All @@ -902,13 +894,6 @@ func validateHostedConfig(ctx context.Context, data *models.DeploymentResource)
tflog.Error(ctx, "failed to convert hibernation spec", map[string]interface{}{"error": diags})
return diags
}
if hibernationSpec.Override.IsNull() && hibernationSpec.Schedules.IsNull() {
diags.AddError(
"scaling_spec (hibernation) must have either override or schedules",
"Please provide either override or schedules in 'scaling_spec.hibernation_spec'",
)
return diags
}
}

// Need to check worker_queues for hosted deployments have `astro_machine` and do not have `node_pool_id`
Expand Down Expand Up @@ -1006,8 +991,8 @@ func RequestScalingSpec(ctx context.Context, scalingSpecObj types.Object) (*plat
platformScalingSpec.HibernationSpec = &platform.DeploymentHibernationSpecRequest{}

if hibernationSpec.Override.IsNull() && hibernationSpec.Schedules.IsNull() {
// If the hibernation spec is set but both override and schedules are not set, return an empty hibernation spec for the request
return platformScalingSpec, nil
// If the hibernation spec is set but both override and schedules are not set, return an error
return platformScalingSpec, diag.Diagnostics{diag.NewErrorDiagnostic("scaling_spec.hibernation_spec must have either override or schedules", "Please provide either override or schedules in 'scaling_spec.hibernation_spec")}
}
if !hibernationSpec.Override.IsNull() {
var override models.HibernationSpecOverride
Expand Down
61 changes: 54 additions & 7 deletions internal/provider/resources/resource_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,6 @@ func TestAcc_ResourceDeploymentStandardScalingSpec(t *testing.T) {
),
ExpectError: regexp.MustCompile(`Inappropriate value for attribute "scaling_spec"`),
},
{
Config: astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
`scaling_spec = {
hibernation_spec = {}
}`),
ExpectError: regexp.MustCompile(`scaling_spec \(hibernation\) must have either override or schedules`),
},
{
Config: astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
`
Expand Down Expand Up @@ -496,6 +489,60 @@ func TestAcc_ResourceDeploymentStandardScalingSpec(t *testing.T) {
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.hibernation_spec.schedules.0.wake_at_cron", "59 * * * *"),
),
},
// Dynamically creating scaling spec depending on variable: setting it to null
{
Config: astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
` `),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.%", "0"),
),
},
{
Config: `variable "environment_name" {
type = string
default = "dev"
}` +
astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
`scaling_spec = var.environment_name != "prd" ? {
hibernation_spec = {
schedules = [{
is_enabled = true
hibernate_at_cron = "0 22 * * *"
wake_at_cron = "0 14 * * *"
}]
}
} : null`),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.hibernation_spec.schedules.0.is_enabled", "true"),
),
},
// Dynamically creating scaling spec depending on variable: setting it to null
{
Config: astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
` `),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.%", "0"),
),
},
{
Config: `variable "environment_name" {
type = string
default = "prd"
}` +
astronomerprovider.ProviderConfig(t, astronomerprovider.HOSTED) + developmentDeployment(scalingSpecDeploymentName,
`scaling_spec = var.environment_name != "prd" ? {
hibernation_spec = {
schedules = [{
is_enabled = true
hibernate_at_cron = "0 22 * * *"
wake_at_cron = "0 14 * * *"
}]
}
} : null`),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.%", "0"), // scaling spec should be null
),
},
// Import existing deployment and check it is correctly imported - https://stackoverflow.com/questions/68824711/how-can-i-test-terraform-import-in-acceptance-tests
{
ResourceName: scalingSpecResourceVar,
Expand Down

0 comments on commit 72d6434

Please sign in to comment.