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

fix validator #43

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")),
Copy link

Choose a reason for hiding this comment

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

do you mind explaining what these functions do and why it was broken before, sorry missing some context here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the parent of this param match an element by the provided name "override_until". Require that param if this param is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MatchRoot doesn't start at the parent but instead at the root of the object so "override_until" could not be found.

},
},
"override_until": resourceSchema.StringAttribute{
Expand Down
Loading