Skip to content

Commit

Permalink
change: added ValidateFunc for sigsci_corp_cloudwaf_instance (#148)
Browse files Browse the repository at this point in the history
* fix: added ValidateFunc to corp_cloudwaf_instance

* fix: show input value

* Update provider/lib.go

Co-authored-by: Shawn Smith <[email protected]>

* Update provider/resource_corp_cloudwaf_instance.go

Co-authored-by: Shawn Smith <[email protected]>

---------

Co-authored-by: Shawn Smith <[email protected]>
  • Loading branch information
ponkio-o and shawnps authored Mar 27, 2023
1 parent 9754dfe commit d7f8e0f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
29 changes: 29 additions & 0 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,32 @@ func validateActionResponseCode(val interface{}, key string) ([]string, []error)
rangeError := fmt.Errorf("received action responseCode '%d'. should be in 400-499 range", code)
return nil, []error{rangeError}
}

func validateRegion(val interface{}, key string) ([]string, []error) {
// https://docs.fastly.com/signalsciences/api/#_corps__corpName__cloudwafInstances_post
regionList := []string{
"us-east-1",
"us-west-1",
"af-south-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-north-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"sa-east-1",
"us-east-2",
"us-west-2",
}

if existsInString(val.(string), regionList...) {
return nil, nil
}

return nil, []error{fmt.Errorf("received region name %q is invalid. should be in (%s)", val.(string), strings.Join(regionList, ", "))}
}
17 changes: 14 additions & 3 deletions provider/resource_corp_cloudwaf_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func resourceCorpCloudWAFInstance() *schema.Resource {
Required: true,
},
"region": {
Type: schema.TypeString,
Description: `Region the CloudWAF Instance is being deployed to. (Supported region: "us-east-1", "us-west-1", "af-south-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-2", "us-west-2").`,
Required: true,
Type: schema.TypeString,
Description: `Region the CloudWAF Instance is being deployed to. (Supported region: "us-east-1", "us-west-1", "af-south-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-2", "us-west-2").`,
Required: true,
ValidateFunc: validateRegion,
},
"tls_min_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -69,6 +70,15 @@ func resourceCorpCloudWAFInstance() *schema.Resource {
Type: schema.TypeString,
Description: `Set instance location to "direct" or "advanced".`,
Required: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
if val == nil {
return nil, nil
}
if existsInString(val.(string), "direct", "advanced") {
return nil, nil
}
return nil, []error{fmt.Errorf(`received instance_location %q is invalid. should be "direct" or "advanced"`, val.(string))}
},
},
"client_ip_header": {
Type: schema.TypeString,
Expand Down Expand Up @@ -110,6 +120,7 @@ func resourceCorpCloudWAFInstance() *schema.Resource {
Description: "List of domain or request URIs, up to 100 entries.",
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
MaxItems: 100,
},
"origin": {
Type: schema.TypeString,
Expand Down
10 changes: 5 additions & 5 deletions provider/resource_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ func resourceSite() *schema.Resource {
Type: schema.TypeMap,
Description: "The sites primary Agent key",
Computed: true,
Sensitive: true,
Sensitive: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"secret_key": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
},
"access_key": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
},
},
},
Expand Down

0 comments on commit d7f8e0f

Please sign in to comment.