Skip to content

Commit

Permalink
fix validator (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliotta authored Apr 25, 2024
1 parent bbc624e commit 97a5dcc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/provider/models/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"context"
"time"

"github.com/astronomer/terraform-provider-astro/internal/clients/platform"
"github.com/astronomer/terraform-provider-astro/internal/provider/schemas"
Expand Down Expand Up @@ -324,7 +325,7 @@ func ScalingSpecTypesObject(
IsActive: types.BoolPointerValue(scalingSpec.HibernationSpec.Override.IsActive),
}
if scalingSpec.HibernationSpec.Override.OverrideUntil != nil {
obj.HibernationSpec.Override.OverrideUntil = types.StringValue(scalingSpec.HibernationSpec.Override.OverrideUntil.String())
obj.HibernationSpec.Override.OverrideUntil = types.StringValue(scalingSpec.HibernationSpec.Override.OverrideUntil.Format(time.RFC3339))
}
}
if scalingSpec.HibernationSpec.Schedules != nil {
Expand Down
22 changes: 20 additions & 2 deletions internal/provider/resources/resource_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ resource "astro_deployment" "%v" {
%v
%v
%v
}
}
`,
input.Name, input.Name, utils.TestResourceDescription, input.Name, input.Name, input.Description, input.ClusterId, input.Executor, input.SchedulerAu, input.Name,
envVarsStr(input.IncludeEnvironmentVariables), wqStr, taskPodNodePoolIdStr)
Expand All @@ -468,6 +468,23 @@ func standardDeployment(input standardDeploymentInput) string {
if input.Executor == string(platform.DeploymentExecutorCELERY) {
wqStr = workerQueuesStr("")
}
var scalingSpecStr string

if input.IsDevelopmentMode == true {
scalingSpecStr = `scaling_spec = {
hibernation_spec = {
schedules = [{
hibernate_at_cron = "1 * * * *"
is_enabled = true
wake_at_cron = "59 * * * *"
}]
override = {
is_hibernating = true
override_until = "2025-04-25T12:58:00+05:30"
}
}
}`
}
return fmt.Sprintf(`
resource "astro_workspace" "%v_workspace" {
name = "%s"
Expand Down Expand Up @@ -495,10 +512,11 @@ resource "astro_deployment" "%v" {
workspace_id = astro_workspace.%v_workspace.id
%v
%v
%v
}
`,
input.Name, input.Name, utils.TestResourceDescription, input.Name, input.Name, input.Description, input.Region, input.CloudProvider, input.Executor, input.IsDevelopmentMode, input.SchedulerSize, input.Name,
envVarsStr(input.IncludeEnvironmentVariables), wqStr)
envVarsStr(input.IncludeEnvironmentVariables), wqStr, scalingSpecStr)
}

func standardDeploymentWithVariableName(input standardDeploymentInput) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/schemas/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func HibernationOverrideResourceSchemaAttributes() map[string]resourceSchema.Att
"is_hibernating": resourceSchema.BoolAttribute{
Optional: true,
Validators: []validator.Bool{
boolvalidator.AlsoRequires(path.MatchRoot("override_until")),
boolvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("override_until")),
},
},
"override_until": resourceSchema.StringAttribute{
Expand Down

0 comments on commit 97a5dcc

Please sign in to comment.