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: Handle zero max_retries #23035

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions internal/service/appmesh/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func expandGRPCRoute(vGrpcRoute []interface{}) *appmesh.GrpcRoute {

mGrpcRetryPolicy := vGrpcRetryPolicy[0].(map[string]interface{})

if vMaxRetries, ok := mGrpcRetryPolicy["max_retries"].(int); ok && vMaxRetries > 0 {
if vMaxRetries, ok := mGrpcRetryPolicy["max_retries"].(int); ok {
grpcRetryPolicy.MaxRetries = aws.Int64(int64(vMaxRetries))
}

Expand Down Expand Up @@ -437,7 +437,7 @@ func expandHTTPRoute(vHttpRoute []interface{}) *appmesh.HttpRoute {

mHttpRetryPolicy := vHttpRetryPolicy[0].(map[string]interface{})

if vMaxRetries, ok := mHttpRetryPolicy["max_retries"].(int); ok && vMaxRetries > 0 {
if vMaxRetries, ok := mHttpRetryPolicy["max_retries"].(int); ok {
httpRetryPolicy.MaxRetries = aws.Int64(int64(vMaxRetries))
}

Expand Down
161 changes: 161 additions & 0 deletions internal/service/appmesh/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@ func testAccRoute_grpcRoute(t *testing.T) {
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
{
Config: testAccRouteConfig_grpcRouteWithMaxRetriesZero(meshName, vrName, vn1Name, vn2Name, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
acctest.CheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.action.0.weighted_target.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.match.0.metadata.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.grpc_route.0.match.0.metadata.*", map[string]string{
"invert": "false",
"match.#": "0",
"name": "X-Testing1",
}),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.match.0.method_name", ""),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.match.0.service_name", ""),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.grpc_retry_events.#", "2"),
resource.TestCheckTypeSetElemAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.grpc_retry_events.*", "deadline-exceeded"),
resource.TestCheckTypeSetElemAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.grpc_retry_events.*", "resource-exhausted"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.http_retry_events.#", "1"),
resource.TestCheckTypeSetElemAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.http_retry_events.*", "server-error"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.max_retries", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.per_retry_timeout.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.per_retry_timeout.0.unit", "s"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.per_retry_timeout.0.value", "15"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.retry_policy.0.tcp_retry_events.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.0.timeout.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http2_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
acctest.CheckResourceAttrAccountID(resourceName, "resource_owner"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccRouteImportStateIdFunc(resourceName),
Expand Down Expand Up @@ -1219,6 +1262,41 @@ func testAccRoute_httpRetryPolicy(t *testing.T) {
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
{
Config: testAccRouteConfig_httpMaxRetriesZero(meshName, vrName, vn1Name, vn2Name, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
acctest.CheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.grpc_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http2_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.action.0.weighted_target.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.match.0.header.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.match.0.method", ""),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.match.0.prefix", "/"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.match.0.scheme", ""),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.http_retry_events.#", "1"),
resource.TestCheckTypeSetElemAttr(resourceName, "spec.0.http_route.0.retry_policy.0.http_retry_events.*", "server-error"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.max_retries", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.per_retry_timeout.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.per_retry_timeout.0.unit", "s"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.per_retry_timeout.0.value", "15"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.0.retry_policy.0.tcp_retry_events.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
acctest.CheckResourceAttrAccountID(resourceName, "resource_owner"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
{
Config: testAccRouteConfig_httpRetryPolicyUpdated(meshName, vrName, vn1Name, vn2Name, rName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -1646,6 +1724,51 @@ resource "aws_appmesh_route" "test" {
`, rName))
}

func testAccRouteConfig_grpcRouteWithMaxRetriesZero(meshName, vrName, vn1Name, vn2Name, rName string) string {
return acctest.ConfigCompose(testAccAppmeshRouteConfigBase(meshName, vrName, "grpc", vn1Name, vn2Name), fmt.Sprintf(`
resource "aws_appmesh_route" "test" {
name = %[1]q
mesh_name = aws_appmesh_mesh.test.id
virtual_router_name = aws_appmesh_virtual_router.test.name

spec {
grpc_route {
match {
metadata {
name = "X-Testing1"
}
}

retry_policy {
grpc_retry_events = [
"deadline-exceeded",
"resource-exhausted",
]

http_retry_events = [
"server-error",
]

max_retries = 0

per_retry_timeout {
unit = "s"
value = 15
}
}

action {
weighted_target {
virtual_node = aws_appmesh_virtual_node.foo.name
weight = 100
}
}
}
}
}
`, rName))
}

func testAccRouteConfig_http2Route(meshName, vrName, vn1Name, vn2Name, rName string) string {
return acctest.ConfigCompose(testAccAppmeshRouteConfigBase(meshName, vrName, "http2", vn1Name, vn2Name), fmt.Sprintf(`
resource "aws_appmesh_route" "test" {
Expand Down Expand Up @@ -2284,6 +2407,44 @@ resource "aws_appmesh_route" "test" {
`, rName))
}

func testAccRouteConfig_httpMaxRetriesZero(meshName, vrName, vn1Name, vn2Name, rName string) string {
return acctest.ConfigCompose(testAccAppmeshRouteConfigBase(meshName, vrName, "http", vn1Name, vn2Name), fmt.Sprintf(`
resource "aws_appmesh_route" "test" {
name = %[1]q
mesh_name = aws_appmesh_mesh.test.id
virtual_router_name = aws_appmesh_virtual_router.test.name

spec {
http_route {
match {
prefix = "/"
}

retry_policy {
http_retry_events = [
"server-error",
]

max_retries = 0

per_retry_timeout {
unit = "s"
value = 15
}
}

action {
weighted_target {
virtual_node = aws_appmesh_virtual_node.foo.name
weight = 100
}
}
}
}
}
`, rName))
}

func testAccRouteConfig_httpRetryPolicyUpdated(meshName, vrName, vn1Name, vn2Name, rName string) string {
return acctest.ConfigCompose(testAccAppmeshRouteConfigBase(meshName, vrName, "http", vn1Name, vn2Name), fmt.Sprintf(`
resource "aws_appmesh_route" "test" {
Expand Down