Skip to content

Commit

Permalink
Add component type validation to CustomizeDiff and update parameter t…
Browse files Browse the repository at this point in the history
…ype in validateServiceConnector
  • Loading branch information
htahir1 committed Oct 28, 2024
1 parent ceb5c74 commit d84a9ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion internal/provider/resource_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package provider

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"context"
"fmt"
"strings"
)

func resourceStack() *schema.Resource {
Expand Down Expand Up @@ -34,8 +37,30 @@ func resourceStack() *schema.Resource {
},
},

CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
// Validate component types
if v, ok := d.GetOk("components"); ok {
components := v.(map[string]interface{})
for compType := range components {
valid := false
for _, validType := range validComponentTypes {
if compType == validType {
valid = true
break
}
}
if !valid {
return fmt.Errorf(
"invalid component type %q. Valid types are: %s",
compType, strings.Join(validComponentTypes, ", "))
}
}
}
return nil
},

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
StateContext: schema.ImportStatePassthroughContext,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var (
}
)

func validateServiceConnector(d *schema.ResourceData) error {
func validateServiceConnector(d *schema.ResourceDiff) error {
connectorType := d.Get("type").(string)

// Validate connector type first
Expand Down
Binary file modified terraform-provider-zenml
Binary file not shown.

0 comments on commit d84a9ae

Please sign in to comment.