Skip to content

Commit

Permalink
add validations (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored May 20, 2021
1 parent 971aa57 commit 0b5587d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions kubernetes/resource_kubernetes_validating_webhook_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -56,13 +57,21 @@ func resourceKubernetesValidatingWebhookConfiguration() *schema.Resource {
Type: schema.TypeString,
Description: webhookDoc["failurePolicy"],
Optional: true,
Default: "Fail",
Default: string(admissionregistrationv1.Fail),
ValidateFunc: validation.StringInSlice([]string{
string(admissionregistrationv1.Fail),
string(admissionregistrationv1.Ignore),
}, false),
},
"match_policy": {
Type: schema.TypeString,
Description: webhookDoc["matchPolicy"],
Optional: true,
Default: "Equivalent",
Default: string(admissionregistrationv1.Equivalent),
ValidateFunc: validation.StringInSlice([]string{
string(admissionregistrationv1.Equivalent),
string(admissionregistrationv1.Exact),
}, false),
},
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -100,12 +109,19 @@ func resourceKubernetesValidatingWebhookConfiguration() *schema.Resource {
Type: schema.TypeString,
Description: webhookDoc["sideEffects"],
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(admissionregistrationv1.SideEffectClassUnknown),
string(admissionregistrationv1.SideEffectClassNone),
string(admissionregistrationv1.SideEffectClassSome),
string(admissionregistrationv1.SideEffectClassNoneOnDryRun),
}, false),
},
"timeout_seconds": {
Type: schema.TypeInt,
Description: webhookDoc["timeoutSeconds"],
Default: 10,
Optional: true,
Type: schema.TypeInt,
Description: webhookDoc["timeoutSeconds"],
Default: 10,
Optional: true,
ValidateFunc: validation.IntBetween(1, 30),
},
},
},
Expand Down

0 comments on commit 0b5587d

Please sign in to comment.