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

[Bug]: is_development_mode and scaling_spec parametrized not working #168

Closed
HongVietLE opened this issue Nov 8, 2024 · 3 comments
Closed

Comments

@HongVietLE
Copy link

Description

I'm trying to create 2 astro deployments (dev and prod) using a variable

The behavior is the same when using a for_each loop on a set of string

Steps To Reproduce

Working ✅

terraform init
terraform plan
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.113.0"
    }
    astro = {
      source  = "astronomer/astro"
      version = "1.0.0"
    }
  }
  required_version = "1.9.4"

}

provider "azurerm" {
  # Configuration options
  features {}
}

provider "astro" {
  organization_id = "xxx"
  token           = "xxx"
}


locals {
  is_development_mode_by_env = {
    dev  = true
    prod = false
  }
  development_mode_scaling_spec = {
    hibernation_spec = {
      schedules = [
        {
          wake_at_cron      = "0 7 * * 1"
          is_enabled        = true
          hibernate_at_cron = "0 17 * * 5"
        },
        {
          wake_at_cron      = "0 7 * * 2-5"
          is_enabled        = true
          hibernate_at_cron = "0 17 * * 1-4"
        }
      ]
    }
  }
}

resource "astro_deployment" "main" {

  is_development_mode = local.is_development_mode_by_env["dev"]
  scaling_spec        = local.is_development_mode_by_env["dev"] ? local.development_mode_scaling_spec : null
  workspace_id            = "xxxxxxxxxxxxxxxxxxxxxxxxx"

  name                    = "deploiement"
  description             = "description"
  type                    = "STANDARD"
  region                  = "westeurope"
  cloud_provider          = "AZURE"
  contact_emails          = ["[email protected]"]
  default_task_pod_cpu    = 1
  default_task_pod_memory = 2
  executor                = "CELERY"
  is_cicd_enforced        = false
  is_dag_deploy_enabled   = true
  is_high_availability    = false
  resource_quota_cpu      = 10
  resource_quota_memory   = "20Gi"
  scheduler_size          = "SMALL"
  environment_variables   = []
  worker_queues = [{
    name               = "default"
    is_default         = true
    astro_machine      = "A5"
    max_worker_count   = 10
    min_worker_count   = 0
    worker_concurrency = 4
  }]
}

Not working ❌

terraform init
terraform plan
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.113.0"
    }
    astro = {
      source  = "astronomer/astro"
      version = "1.0.0"
    }
  }
  required_version = "1.9.4"

}

provider "azurerm" {
  # Configuration options
  features {}
}

provider "astro" {
  organization_id = "xxx"
  token           = "xxx"
}

variable "env" {
  type    = string
  default = "dev"
}

locals {
  is_development_mode_by_env = {
    dev  = true
    prod = false
  }
  development_mode_scaling_spec = {
    hibernation_spec = {
      schedules = [
        {
          wake_at_cron      = "0 7 * * 1"
          is_enabled        = true
          hibernate_at_cron = "0 17 * * 5"
        },
        {
          wake_at_cron      = "0 7 * * 2-5"
          is_enabled        = true
          hibernate_at_cron = "0 17 * * 1-4"
        }
      ]
    }
  }
}

resource "astro_deployment" "main" {


  is_development_mode = local.is_development_mode_by_env[var.env]
  scaling_spec        = local.is_development_mode_by_env[var.env] ? local.development_mode_scaling_spec : null
  workspace_id            = "xxxxxxxxxxxxxxxxxxxxxxxxx"

  name                    = "deploiement"
  description             = "description"
  type                    = "STANDARD"
  region                  = "westeurope"
  cloud_provider          = "AZURE"
  contact_emails          = ["[email protected]"]
  default_task_pod_cpu    = 1
  default_task_pod_memory = 2
  executor                = "CELERY"
  is_cicd_enforced        = false
  is_dag_deploy_enabled   = true
  is_high_availability    = false
  resource_quota_cpu      = 10
  resource_quota_memory   = "20Gi"
  scheduler_size          = "SMALL"
  environment_variables   = []
  worker_queues = [{
    name               = "default"
    is_default         = true
    astro_machine      = "A5"
    max_worker_count   = 10
    min_worker_count   = 0
    worker_concurrency = 4
  }]
}

Output

╷
│ Error: scaling_spec (hibernation) is only supported for is_development_mode set to true
│ 
│   with astro_deployment.main,
│   on main_astro.tf line 29, in resource "astro_deployment" "main":
│   29: resource "astro_deployment" "main" {
│ 
│ Either set is_development_mode to true or remove scaling_spec
╵

Acceptance Criteria

No response

Anything else?

No response

@blaivs
Copy link

blaivs commented Nov 12, 2024

Hi, I'm facing the same problem. I did debug it quickly and looks like when validation is first called, both IsDevelopmentMode and ScalingSpec values are unknown. Probably adding a check for skipping validation if ScalingSpec is unknown would suffice, as subsequent validations will eventually have the value set.

Just adding !data.ScalingSpec.IsUnknown() check on

if !data.IsDevelopmentMode.ValueBool() && !data.ScalingSpec.IsNull() {

and

@vandyliu
Copy link
Collaborator

vandyliu commented Dec 2, 2024

this should be fixed in the new version v1.0.2
#173
#171

@vandyliu vandyliu closed this as completed Dec 2, 2024
@blaivs
Copy link

blaivs commented Dec 3, 2024

@vandyliu working perfectly now 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants