-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Added API Gateway Gateway response resource #1168
Conversation
d2a0d15
to
a6e1113
Compare
a6e1113
to
7daeb71
Compare
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.
This looks overall ok, acceptance tests passing.
I pointed out a few small things. Just ping me when it's ready for another round.
|
||
# aws\_api\_gateway\_gateway\_response | ||
|
||
Provides an API Gateway Gateway Response for a REST API Gateway. |
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.
... Gateway Gateway ... Gateway 😂 🤷♂️
RestApiId: aws.String(d.Get("rest_api_id").(string)), | ||
ResponseType: aws.String(d.Get("response_type").(string)), | ||
ResponseTemplates: aws.StringMap(templates), | ||
ResponseParameters: aws.StringMap(parameters), |
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 think if the two fields (response_templates
& response_parameters
) are optional and user didn't define those we shouldn't be sending them to the API here.
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.
As discussed via Slack, this doesn't matter and we need it for updates, so 👍
} | ||
|
||
d.SetId(fmt.Sprintf("aggr-%s-%s", d.Get("rest_api_id").(string), d.Get("response_type").(string))) | ||
log.Printf("[DEBUG] API Gateway Gateway Response ID: %s", d.Id()) |
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.
Perhaps a nitpick, but more informative log message here would be for example
[DEBUG] API Gateway Gateway Response created (%q)
I think it's more obvious that the unique string is ID, but less obvious that this ID comes from creation (not update or deletion).
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NotFoundException" { | ||
log.Printf("[WARN] API Gateway Gateway Response (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil |
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.
👌 👍
log.Printf("[DEBUG] Reading API Gateway Gateway Response %s", d.Id()) | ||
gatewayResponse, err := conn.GetGatewayResponse(&apigateway.GetGatewayResponseInput{ | ||
RestApiId: aws.String(d.Get("rest_api_id").(string)), | ||
ResponseType: aws.String(d.Get("response_type").(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.
Since the combination of both rest_api_id
and response_type
is treated as "identifier" for the purpose of the lookup here shouldn't response_type
also be ForceNew
?
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.
Yup, don't see any counter argument :)
return resource.NonRetryableError(err) | ||
} | ||
|
||
if apigatewayErr.Code() == "TooManyRequestsException" { |
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.
This code is handled (and retried on) already in the AWS SDK: https://github.com/aws/aws-sdk-go/blob/master/aws/request/retryer.go#L41
If you think we don't retry enough times we should pass that feedback back to AWS SDK and deal with it there.
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.
Didn't even know that :O Big win on that, thanks!
|
||
if !ok { | ||
return resource.NonRetryableError(err) | ||
} |
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.
You can omit these three lines if you add ok &&
to the condition handling NotFoundException
- it will just fall through to the last return
. 😉
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.
Good catch!
), | ||
}, | ||
|
||
resource.TestStep{ |
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.
As in any slice/array of structs in Go this "annotation" is optional and we tend to omit it (less characters to read 😃 ) - like you did in the schema map.
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No API Gateway Method ID is set") |
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.
👀
_, err := conn.GetGatewayResponse(req) | ||
|
||
if err == nil { | ||
return fmt.Errorf("API Gateway Method still exists") |
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.
👀
7daeb71
to
c613df6
Compare
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 left you two (last) comments, otherwise this is looking good. Thanks for fixing all the previous things.
conn := meta.(*AWSClient).apigateway | ||
|
||
templates := make(map[string]string) | ||
for k, v := range d.Get("response_templates").(map[string]interface{}) { |
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.
Shouldn't this be also wrapped in GetOk()
like the other optional field, as it's optional? Otherwise I think we might crash here when casting nil
to a map.
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.
Guhuhu, indeed it should have been set...!
RestApiId: aws.String(d.Get("rest_api_id").(string)), | ||
ResponseType: aws.String(d.Get("response_type").(string)), | ||
ResponseTemplates: aws.StringMap(templates), | ||
ResponseParameters: aws.StringMap(parameters), |
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.
As discussed via Slack, this doesn't matter and we need it for updates, so 👍
|
||
d.Set("response_type", gatewayResponse.ResponseType) | ||
d.Set("status_code", gatewayResponse.StatusCode) | ||
d.Set("response_templates", gatewayResponse.ResponseTemplates) |
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.
This comes back as map[string]*string
, so shouldn't we also convert it to flat map via aws.StringValueMap
like the other field below?
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.
Good catch >_<"
c613df6
to
86cd267
Compare
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.
LGTM 🎉
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Description
This adds the API Gateway Gateway response, which allows to configure.
This is a required step to complete the basic-auth protected HTTPs endpoint test to end #861.
Using this resource, we are now able to specify headers & response templates on a https status code basis, so per 401, 403, 500 errors.
Documentation: https://docs.aws.amazon.com/apigateway/api-reference/link-relation/gatewayresponse-update/
Tests
TODOs