-
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
Add a body property to API Gateway RestAPI for Swagger import support #1197
Conversation
@radeksimko Please let me know if there's any questions on concerns on this that I can help address. |
The body property allows supplying an Swagger/OpenAPI spec to a RestAPI to create the API definition using the routes and integrations defined in the spec.
b5793e1
to
4203007
Compare
Updated tests to create valid REST API definitions and add test results to summary. cc @radeksimko @Ninir @betabandido @apparentlymart for feedback. |
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.
Hey @lukehoban
This looks good at first sight :)
Just left a few comments to be addressed, more for styling & debugging :)
Thanks!
Body: []byte(body.(string)), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error putting API Gateway specification: %s", 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.
Could you use errwrap.Wrapf("Error creating API Gateway specification: {{err}}", err)
there please? (notice the creating word, to make it clear we are putting by creating)
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.
It does no harm, but I think the wrapper here isn't necessary as the only place the error will escalate to is the UI, where all that matters is string-based error message user will read, not the original error type.
if body, ok := d.GetOk("body"); ok { | ||
_, err := conn.PutRestApi(&apigateway.PutRestApiInput{ | ||
RestApiId: gateway.Id, | ||
Mode: aws.String("overwrite"), |
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.
Can you use the apigateway.PutModeOverwrite
constant here and line 178?
} | ||
} | ||
EOF | ||
} |
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.
Can you fix the space indentation here please? 😄 (mostly at the beginning of the JSON structure)
Body: []byte(body.(string)), | ||
}) | ||
if err != nil { | ||
return 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.
I would go for the same as line 91 here: errwrap.Wrapf("Error updating API Gateway specification: {{err}}", err)
. Thoughts?
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.
It does no harm, but I think the wrapper here isn't necessary as the only place the error will escalate to is the UI, where all that matters is string-based error message user will read, not the original error type.
@@ -76,6 +81,17 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{} | |||
|
|||
d.SetId(*gateway.Id) | |||
|
|||
if body, ok := d.GetOk("body"); ok { | |||
_, err := conn.PutRestApi(&apigateway.PutRestApiInput{ |
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.
Could you log in the logs that we are setting the specification?
Just for verbosity & debugging :D
Same for the update would be highly appreciated!
Thanks @Ninir for the review and @lukehoban for sending the PR - other than what you mentioned we should also document clearly which resources collide with this field/approach, I believe these are:
i.e. it should be clear to the user that they cannot use both Swagger and these resources together for the same API. |
Thanks @Ninir and @radeksimko! Updated PR to address feedback. Please take a look at the doc updates in particular. |
@@ -26,6 +26,18 @@ The following arguments are supported: | |||
* `name` - (Required) The name of the REST API | |||
* `description` - (Optional) The description of the REST API | |||
* `binary_media_types` - (Optional) The list of binary media types supported by the RestApi. By default, the RestApi supports only UTF-8-encoded text payloads. | |||
* `body` - (Optional) An OpenAPI specification that defines the set of routes and integrations to create as part of the REST API. | |||
|
|||
__Note__: If the `body` argument is provided, the OpenAPI specification will be used to configure the resources, methods and integrations for the Rest API. If this argument is provided, the following resources should not be configured manually for the same REST API, as updates may cause manual resource updates to be overwritten: |
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.
the following resources should not be configured manually
I'd rather say should not be managed as separate ones as that's more in-line with the language used in the rest of our docs.
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 now LGTM except one nitpick comment, but I'll defer the final decision & push of the merge button to @Ninir as he started the review originally.
hey @lukehoban ! Just pushed the documentation update following @radeksimko 's recommandation. Now merging, cheers! |
Hi All - When will this feature be available. I have v0.10.5 on my mac. resource "aws_api_gateway_rest_api" "MyDemoAPI" { when I run terraform plan , I get
Am I missing some thing here. Please let me know |
Same with v0.10.6: body argument not recognized. |
I built the terraform-provider-aws using the instructions from README. Now when I run terraform plan, the body tag is recognized. But when I apply, I get the following error. I used the same swagger with AWS SDK/CLI and it worked fine. Can you please help $ terraform apply 1 error(s) occurred:
|
Hi all, Thanks for this great work. Thanks |
Add a body property to API Gateway RestAPI for Swagger import support
@kirangangineni : after reviewing the pull request itself i realized that the provider does not expect the Hence i managed having this work with the following:
This should be added in the docs here : https://www.terraform.io/docs/providers/aws/r/api_gateway_rest_api.html#body thanks @lukehoban for bringing this feature ! |
Hi folks, the AWS provider (this repository) is release independently from the core one (https://github.com/hashicorp/terraform). the body property was added in the 1.0.0 release: to ensure you get it right, remove the Thus being said, @ebarault is right: the body property expects the body of the file, not the path to the file. As in: using data templateresource "aws_api_gateway_rest_api" "api" {
...
body = "${data.template_file.swagger_api.rendered}"
} using a fileresource "aws_api_gateway_rest_api" "api" {
...
body = "${file("myfile.json"}"
} using inline stringsresource "aws_api_gateway_rest_api" "api" {
...
body = <<YAML
myfile
YAML
} Tell us how it goes! :) |
@Ninir
I believe it should be ${file("...")} |
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
The
body
property allows supplying a Swagger/OpenAPI spec to a RestAPI to create the API definition using the routes and integrations defined in the spec.Related to hashicorp/terraform#11034 and the work done in hashicorp/terraform#6175.
Provides similar behaviour to what's available in CloudFormation with: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body.
Tests