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

provider/aws: Add support for api_gateway_method_settings #13542

Merged
merged 1 commit into from
Apr 12, 2017

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Apr 11, 2017

Closes #6972
Closes #6612

Test plan

make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSAPIGatewayMethodSettings_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/04/11 17:21:59 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSAPIGatewayMethodSettings_ -timeout 120m
=== RUN   TestAccAWSAPIGatewayMethodSettings_basic
--- PASS: TestAccAWSAPIGatewayMethodSettings_basic (108.34s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	108.374s

Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, few minor questions


func resourceAwsApiGatewayMethodSettings() *schema.Resource {
return &schema.Resource{
Create: resourceAwsApiGatewayMethodSettingsUpdate,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no difference between Create and Update?

Copy link
Member Author

@radeksimko radeksimko Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no create API method, because the method settings is part of the stage which we're updating. The aws_api_gateway_stage resource in turn has no notion of method settings so they shouldn't clash in any way.

return nil
}

d.Set("settings.0.metrics_enabled", settings.MetricsEnabled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think they'll/we'll ever allow more than one settings object at a time? If so, might be worth it to go ahead and write a flatten function here. If not, ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it given the nature of these settings (e.g. on/off logging or monitoring) and even if they do so I think we should keep it as is because the ability to use count on top level resources allows the user to do all kinds of things they wouldn't be able to do if they worked with "subresources" (multiple settings blocks nested inside the resource).

ops = append(ops, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String(prefix + "metrics/enabled"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.metrics_enabled").(bool))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking that Value needs to be a string here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It surprised me too when I saw that for the first time, but I guess it makes sense if they want to support patching of whole objects (marshalled JSON which is just string), not just primitive data types.

TL;DR: https://github.com/aws/aws-sdk-go/blob/master/service/apigateway/api.go#L17073-L17077

@apparentlymart
Copy link
Contributor

apparentlymart commented Apr 11, 2017

This sort of resource that updates something that already exists rather than creating a new thing can be confusing. I assume there's a reason not to just add these settings into the api_gateway_method resource itself?

EDIT: oh, I see. It is for a particular method on a particular stage.

resource "aws_api_gateway_method_settings" "s" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "${aws_api_gateway_stage.test.stage_name}"
method_path = "${aws_api_gateway_resource.test.path_part}/${aws_api_gateway_method.test.http_method}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it seems like this is just being used to construct a prefix for a longer path anyway (and thus method_path is not a first-class concept in the underlying API?), perhaps it would be better to leave these things separated and combine them in code, thus avoiding the need to explain it below as just "concatenate two things together".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for questioning this - I was actually playing with that idea too! 😄

I'm not completely opposed to 2 fields (e.g. path_part & method).

The API allows you to define things like */* or */GET and I'm just little bit worried that they might later introduce (or even already support) some kind of special magic syntax which doesn't involve / and we'd prevent the user from specifying such paths. 🤔

Copy link

@Porkbutts Porkbutts Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource.path_part won't work if the resource has a non-root parent though, right? E.g. /a/b/c with method on node c. I tried using resource.path instead, which contains the fully qualified path, but the leading slash returned in the path was causing the settings to not be applied properly. My solution for the time being looks like:

"${substr("${aws_api_gateway_resource.test.path}/${aws_api_gateway_method.test.http_method}", 1, -1)}"

@radeksimko radeksimko merged commit 4606090 into master Apr 12, 2017
@radeksimko radeksimko deleted the f-aws-api-gateway-method-settings branch April 12, 2017 15:13
@ghost
Copy link

ghost commented Mar 30, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants