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

Allow scaling spec to be set dynamically #171

Merged
merged 2 commits into from
Nov 15, 2024
Merged

Conversation

vandyliu
Copy link
Collaborator

@vandyliu vandyliu commented Nov 15, 2024

Description

User wants to determine scaling_spec via variable and using tertiary operator like the following

scaling_spec = var.environment_name != "prod" ? {
    hibernation_spec = {
      override = null
      schedules = [{
        is_enabled       = true
        hibernate_at_cron = "0 22 * * *"  
        wake_at_cron     = "0 14 * * *"  
      }]
    }
  } : null

However, it does not work with the current validation.
I had to move the validation to runtime instead, which seemed to fix it. Added some integration tests as well.

🧪 Functional Testing

Added some integration tests.
Did some manual testing with the following with

  1. var.environment_name == "prod"
  2. var.environment_name == "dev"
  3. scaling_spec.hibernation_spec.override and scaling_spec.hibernation_spec.schedule, which passes terraform plan but fails terraform apply (expected new behavior)
resource "astro_deployment" "team_1_dev_deployment" {
  name                    = "team-1-dev-deployment"
  description             = "Team 1 Dev Deployment"
  type                    = "STANDARD"
  cloud_provider          = "AWS"
  region                  = "us-east-1"
  contact_emails          = []
  default_task_pod_cpu    = "0.25"
  default_task_pod_memory = "0.5Gi"
  executor                = "CELERY"
  is_cicd_enforced        = true
  is_dag_deploy_enabled   = true
  is_development_mode     = true
  is_high_availability    = false
  resource_quota_cpu      = "10"
  resource_quota_memory   = "20Gi"
  scheduler_size          = "SMALL"
  workspace_id            = astro_workspace.team_1_workspace.id
  environment_variables   = []
  worker_queues = [{
    name               = "default"
    is_default         = true
    astro_machine      = "A5"
    max_worker_count   = 10
    min_worker_count   = 0
    worker_concurrency = 1
  }]
  scaling_spec = var.environment_name != "prd" ? {
    hibernation_spec = {
      schedules = [{
        is_enabled       = true
        hibernate_at_cron = "0 22 * * *"
        wake_at_cron     = "0 14 * * *"
      }]
    }
  } : null
}


variable "environment_name" {
  type    = string
  default = "prod"
}

📋 Checklist

  • Added/updated applicable tests
  • Added/updated examples in the examples/ directory
  • Updated any related documentation

@@ -902,13 +902,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() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only worked with static scaling_spec definition

@vandyliu vandyliu marked this pull request as ready for review November 15, 2024 17:40
@vandyliu vandyliu requested a review from a team as a code owner November 15, 2024 17:40
@vandyliu vandyliu merged commit 5396de3 into main Nov 15, 2024
9 checks passed
@vandyliu vandyliu deleted the fix-dynamic-scaling-spec branch November 15, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants