-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add support for specifying cache key parameters in API Gateway. #893
Changes from 2 commits
9831362
0c0d089
ee82eec
f817e97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,28 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) { | |
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"), | ||
), | ||
}, | ||
|
||
{ | ||
Config: testAccAWSAPIGatewayIntegrationConfigCacheKeyParameters, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of expanding this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean adding a new function named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSAPIGatewayIntegrationExists("aws_api_gateway_integration.test", &conf), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "type", "HTTP"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "integration_http_method", "GET"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "uri", "https://www.google.de"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "passthrough_behavior", "WHEN_NO_MATCH"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "content_handling", "CONVERT_TO_TEXT"), | ||
resource.TestCheckNoResourceAttr("aws_api_gateway_integration.test", "credentials"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.%", "3"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.integration.request.header.X-Authorization", "'static'"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.integration.request.header.X-Foo", "'Bar'"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.integration.request.path.param", "method.request.path.param"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "cache_key_parameters.#", "1"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "cache_key_parameters.550492954", "method.request.path.param"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.%", "2"), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.application/json", ""), | ||
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
@@ -279,3 +301,55 @@ resource "aws_api_gateway_integration" "test" { | |
content_handling = "CONVERT_TO_TEXT" | ||
} | ||
` | ||
|
||
const testAccAWSAPIGatewayIntegrationConfigCacheKeyParameters = ` | ||
resource "aws_api_gateway_rest_api" "test" { | ||
name = "test" | ||
} | ||
|
||
resource "aws_api_gateway_resource" "test" { | ||
rest_api_id = "${aws_api_gateway_rest_api.test.id}" | ||
parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}" | ||
path_part = "{param}" | ||
} | ||
|
||
resource "aws_api_gateway_method" "test" { | ||
rest_api_id = "${aws_api_gateway_rest_api.test.id}" | ||
resource_id = "${aws_api_gateway_resource.test.id}" | ||
http_method = "GET" | ||
authorization = "NONE" | ||
|
||
request_models = { | ||
"application/json" = "Error" | ||
} | ||
|
||
request_parameters = { | ||
"method.request.path.param" = true | ||
} | ||
} | ||
|
||
resource "aws_api_gateway_integration" "test" { | ||
rest_api_id = "${aws_api_gateway_rest_api.test.id}" | ||
resource_id = "${aws_api_gateway_resource.test.id}" | ||
http_method = "${aws_api_gateway_method.test.http_method}" | ||
|
||
request_templates = { | ||
"application/json" = "" | ||
"application/xml" = "#set($inputRoot = $input.path('$'))\n{ }" | ||
} | ||
|
||
request_parameters = { | ||
"integration.request.header.X-Authorization" = "'static'" | ||
"integration.request.header.X-Foo" = "'Bar'" | ||
"integration.request.path.param" = "method.request.path.param" | ||
} | ||
|
||
cache_key_parameters = ["method.request.path.param"] | ||
|
||
type = "HTTP" | ||
uri = "https://www.google.de" | ||
integration_http_method = "GET" | ||
passthrough_behavior = "WHEN_NO_MATCH" | ||
content_handling = "CONVERT_TO_TEXT" | ||
} | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason the cache namespace should always be resource ID?
I had a peek 👀 into the official API docs and couldn't find any suggestions around that: https://docs.aws.amazon.com/apigateway/api-reference/link-relation/integration-put/#cacheNamespace
If there isn't a reason I think we should let the user specify their own namespace.
Also I'm not sure what kind of data it contains and how these are structured, so it's hard to tell (for me at least) whether
resource_id
is the best namespace key - e.g. does it automatically assign the cache distribution to a given API ID so that we don't need to put API ID to the namespace? Same questions about other fields. If it's not clear from the docs it would be worth asking the AWS support - I'm happy to ask for you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think we should leave this as
nil
in case the user didn't specify any caching.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I observed that when caching was manually enabled the namespace set by AWS matched the resource id. But, as you well say it might not be a requirement. I will conduct a test using a custom namespace. If it works, users should indeed be able to specify it.
In the meanwhile, if you can please ask AWS support that would be great. Hopefully we can then have a clear understanding of the usage (and the potential restrictions) of a cache namespace.
Setting the default to
nil
sounds good to me. I will do that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just updated the pull request with your feedback. I did some testing and using a user-defined cache namespace works too. So, I added a field named
cache_namespace
.