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

r/aws_appmesh_route: Add support for retry policies #11660

Merged
merged 6 commits into from
Sep 29, 2020
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
128 changes: 57 additions & 71 deletions aws/resource_aws_appmesh_route.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws

import (
"bytes"
"fmt"
"log"
"regexp"
Expand All @@ -12,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/hashcode"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

Expand Down Expand Up @@ -98,7 +96,6 @@ func resourceAwsAppmeshRoute() *schema.Resource {
},
},
},
Set: appmeshWeightedTargetHash,
},
},
},
Expand Down Expand Up @@ -185,23 +182,12 @@ func resourceAwsAppmeshRoute() *schema.Resource {
},
},
},
Set: appmeshHttpRouteHeaderHash,
},

"method": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
appmesh.HttpMethodConnect,
appmesh.HttpMethodDelete,
appmesh.HttpMethodGet,
appmesh.HttpMethodHead,
appmesh.HttpMethodOptions,
appmesh.HttpMethodPatch,
appmesh.HttpMethodPost,
appmesh.HttpMethodPut,
appmesh.HttpMethodTrace,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(appmesh.HttpMethod_Values(), false),
},

"prefix": {
Expand All @@ -211,12 +197,61 @@ func resourceAwsAppmeshRoute() *schema.Resource {
},

"scheme": {
Type: schema.TypeString,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(appmesh.HttpScheme_Values(), false),
},
},
},
},

"retry_policy": {
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"http_retry_events": {
Type: schema.TypeSet,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
appmesh.HttpSchemeHttp,
appmesh.HttpSchemeHttps,
}, false),
MinItems: 0,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"max_retries": {
Type: schema.TypeInt,
Required: true,
},

"per_retry_timeout": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"unit": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(appmesh.DurationUnit_Values(), false),
},

"value": {
Type: schema.TypeInt,
Required: true,
},
},
},
},

"tcp_retry_events": {
Type: schema.TypeSet,
Optional: true,
MinItems: 0,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
},
Expand Down Expand Up @@ -266,7 +301,6 @@ func resourceAwsAppmeshRoute() *schema.Resource {
},
},
},
Set: appmeshWeightedTargetHash,
},
},
},
Expand Down Expand Up @@ -465,51 +499,3 @@ func resourceAwsAppmeshRouteImport(d *schema.ResourceData, meta interface{}) ([]

return []*schema.ResourceData{d}, nil
}

func appmeshHttpRouteHeaderHash(vHttpRouteHeader interface{}) int {
var buf bytes.Buffer
mHttpRouteHeader := vHttpRouteHeader.(map[string]interface{})
if v, ok := mHttpRouteHeader["invert"].(bool); ok {
buf.WriteString(fmt.Sprintf("%t-", v))
}
if vMatch, ok := mHttpRouteHeader["match"].([]interface{}); ok && len(vMatch) > 0 && vMatch[0] != nil {
mMatch := vMatch[0].(map[string]interface{})
if v, ok := mMatch["exact"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
if v, ok := mMatch["prefix"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
if vRange, ok := mMatch["range"].([]interface{}); ok && len(vRange) > 0 && vRange[0] != nil {
mRange := vRange[0].(map[string]interface{})
if v, ok := mRange["end"].(int); ok {
buf.WriteString(fmt.Sprintf("%d-", v))
}
if v, ok := mRange["start"].(int); ok {
buf.WriteString(fmt.Sprintf("%d-", v))
}
}
if v, ok := mMatch["regex"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
if v, ok := mMatch["suffix"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
}
if v, ok := mHttpRouteHeader["name"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
return hashcode.String(buf.String())
}

func appmeshWeightedTargetHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
if v, ok := m["virtual_node"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
if v, ok := m["weight"].(int); ok {
buf.WriteString(fmt.Sprintf("%d-", v))
}
return hashcode.String(buf.String())
}
Loading