-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: Respect 'selection_pattern' in api_gateway_integration_response #5893
provider/aws: Respect 'selection_pattern' in api_gateway_integration_response #5893
Conversation
@@ -72,6 +72,7 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta | |||
RestApiId: aws.String(d.Get("rest_api_id").(string)), | |||
StatusCode: aws.String(d.Get("status_code").(string)), | |||
ResponseTemplates: aws.StringMap(templates), | |||
SelectionPattern: aws.String(d.Get("selection_pattern").(string)), |
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.
@radeksimko, this is an optional parameter. What happens if we don't set anything for this? Shouldn't this be wrapped in an if v, ok := d.GetOk(
style code block?
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.
Ha, very good point. Thanks for spotting it. I will add d.GetOk
.
1 question on this, but the tests pass as expected:
|
I've tried testing with this branch, but can't seem to get it to work.
gives me,
Currently, I have to manually call the API afterwards as a workaround.
|
+1 Would love to have the selection pattern option available for use. |
Bump. Any changes made in the last 20 days? |
I was not able to reproduce this - can you provide more context - i.e. more Terraform configs (specifically for I was testing I had three configs with different
Side note: Whether it's causing issues or not I think we should probably be using |
@radeksimko how are we getting on with this PR? Nearly in a state for a review again? 👍 |
👍 |
@radeksimko @stack72 sorry for the late reply, but here is the whole Same error.
provider "aws" {
region = "ap-northeast-1"
allowed_account_ids = ["${var.names.account_id}"]
}
variable "names" {
default = {
account_id = "$ACCOUNT_ID"
}
}
# REST API
resource "aws_api_gateway_rest_api" "EB" {
name = "EB"
description = "get EB info"
}
# Resources
resource "aws_api_gateway_resource" "eb" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
parent_id = "${aws_api_gateway_rest_api.EB.root_resource_id}"
path_part = "eb"
}
resource "aws_api_gateway_resource" "env_name" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
parent_id = "${aws_api_gateway_resource.eb.id}"
path_part = "{env_name}"
}
resource "aws_api_gateway_resource" "ip" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
parent_id = "${aws_api_gateway_resource.env_name.id}"
path_part = "ip"
}
# Methods
resource "aws_api_gateway_method" "ip_get" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "GET"
authorization = "NONE"
}
# Integrations
resource "aws_api_gateway_integration" "ip_get" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "${aws_api_gateway_method.ip_get.http_method}"
integration_http_method = "POST"
type = "AWS"
uri = "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:${var.names.account_id}:function:eb_ip/invocations"
request_templates = {
"application/json" = "{ \"env_name\": \"$input.params('env_name')\" }"
}
depends_on = ["aws_api_gateway_method.ip_get"]
}
# Method responses
resource "aws_api_gateway_method_response" "ip_200" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "${aws_api_gateway_method.ip_get.http_method}"
status_code = "200"
}
resource "aws_api_gateway_method_response" "ip_400" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "${aws_api_gateway_method.ip_get.http_method}"
status_code = "400"
}
# Integration responses
resource "aws_api_gateway_integration_response" "ip_get_200" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "${aws_api_gateway_method.ip_get.http_method}"
status_code = "${aws_api_gateway_method_response.ip_200.status_code}"
response_templates = {
"application/json" = "$input.path('$')"
}
}
resource "aws_api_gateway_integration_response" "ip_get_400" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
resource_id = "${aws_api_gateway_resource.ip.id}"
http_method = "${aws_api_gateway_method.ip_get.http_method}"
status_code = "${aws_api_gateway_method_response.ip_400.status_code}"
selection_pattern = "[^0-9](.|\n)*"
response_templates = {
"application/json" = "$input.path('$').errorMessage"
}
depends_on = ["aws_api_gateway_integration_response.ip_get_200"]
}
# Wait for https://github.com/hashicorp/terraform/pull/5893
# until then, use
# aws apigateway get-rest-apis --output table
# aws apigateway get-resources --rest-api-id `aws apigateway get-rest-apis | jq .items[].id -r` --output table
# aws apigateway put-integration-response --rest-api-id somgjn6eha --resource-id g901ec --http-method GET --status-code 400 --response-templates '{"application/json": "$input.path('$').errorMessage"}' --selection-pattern "[^0-9](.|\n)*"
resource "aws_api_gateway_deployment" "eb_deployment" {
rest_api_id = "${aws_api_gateway_rest_api.EB.id}"
depends_on = ["aws_api_gateway_integration.ip_get"]
stage_name = "prod"
}
## Permissions
#resource "aws_lambda_permission" "apigw_ip" {
# statement_id = "apigw_for_ip"
# action = "lambda:InvokeFunction"
# function_name = "eb_ip"
# principal = "apigateway.amazonaws.com"
# source_arn = "arn:aws:execute-api:ap-northeast-1:${var.names.account_id}:${aws_api_gateway_rest_api.EB.id}/*/GET/eb/*/${aws_api_gateway_resource.ip.path_part}"
#}
# Replace Sometimes I was getting a |
@ijin Reproduced w/ unmodified
Just looking into it. |
If I compile a patched version from this PR and use it to I will check if there's any automated migration we can do for you and potentially other users that are already using |
70b07f1
to
15cb664
Compare
15cb664
to
a9dc481
Compare
I was able to do the upgrade smoothly without having to @ijin Can you confirm the patched version is working for you? |
@radeksimko ok, I got it working with commit Thanks! On a side note, I had to add another |
Right, that's believable, I think that's a separate issue though which can be fixed separately via PR to docs. Terraform is always trying to run many operations in parallel to CRUD resources quickly, but some need to be created first, even though they may not contain any references between each other, so the dependency is not obvious for Terraform, hence it doesn't know that certain operations cannot run in parallel hence the explicit |
@radeksimko this LGTM! Merge at will :) |
👍 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #5891