From 9d2c028d9f77c33fe937c3af47c2b4377f001038 Mon Sep 17 00:00:00 2001 From: "Sascha (Oleksandr) Fedorenko" Date: Tue, 29 Jan 2019 13:43:21 +0100 Subject: [PATCH 1/4] remark on existing local cache for README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 28dfaee8682..6907217328e 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ Using the provider ---------------------- If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it. Documentation about the provider specific configuration options can be found on the [provider's website](https://www.terraform.io/docs/providers/aws/index.html). +*Note:* You will need to remove the previously downloaded and cached version of the plugin from the `./terraform/plugins/` if you previouslt used the standard version of plugin on your project. + Developing the Provider --------------------------- From 5c2c90ea9ab494092444d9eef76720b56898d3f3 Mon Sep 17 00:00:00 2001 From: "Sascha (Oleksandr) Fedorenko" Date: Tue, 29 Jan 2019 13:49:43 +0100 Subject: [PATCH 2/4] openAPI body's basePath import options --- aws/resource_aws_api_gateway_rest_api.go | 20 + aws/resource_aws_api_gateway_rest_api_test.go | 344 +++++++++++++++++- 2 files changed, 363 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_api_gateway_rest_api.go b/aws/resource_aws_api_gateway_rest_api.go index 7f304c8d7ff..d5d74e5c463 100644 --- a/aws/resource_aws_api_gateway_rest_api.go +++ b/aws/resource_aws_api_gateway_rest_api.go @@ -60,6 +60,13 @@ func resourceAwsApiGatewayRestApi() *schema.Resource { Optional: true, }, + "body_base_path": { + Type: schema.TypeString, + Default: "ignore", + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"ignore", "prepend", "split"}, true), + }, + "minimum_compression_size": { Type: schema.TypeInt, Optional: true, @@ -153,12 +160,20 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{} d.SetId(*gateway.Id) + bodyBasePathMode := d.Get("body_base_path").(string) + if body, ok := d.GetOk("body"); ok { log.Printf("[DEBUG] Initializing API Gateway from OpenAPI spec %s", d.Id()) _, err := conn.PutRestApi(&apigateway.PutRestApiInput{ RestApiId: gateway.Id, Mode: aws.String(apigateway.PutModeOverwrite), Body: []byte(body.(string)), + Parameters: map[string]*string{ + // See https://docs.aws.amazon.com/cli/latest/reference/apigateway/import-rest-api.html + // At the moment of writing, according to aws support, the docs are incorrect + // and the parameter should be called 'basepath' and not 'basePath' + "basepath": &bodyBasePathMode, + }, }) if err != nil { return fmt.Errorf("error creating API Gateway specification: %s", err) @@ -344,12 +359,17 @@ func resourceAwsApiGatewayRestApiUpdate(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Updating API Gateway %s", d.Id()) if d.HasChange("body") { + bodyBasePathMode := d.Get("body_base_path").(string) + if body, ok := d.GetOk("body"); ok { log.Printf("[DEBUG] Updating API Gateway from OpenAPI spec: %s", d.Id()) _, err := conn.PutRestApi(&apigateway.PutRestApiInput{ RestApiId: aws.String(d.Id()), Mode: aws.String(apigateway.PutModeOverwrite), Body: []byte(body.(string)), + Parameters: map[string]*string{ + "basepath": &bodyBasePathMode, + }, }) if err != nil { return fmt.Errorf("error updating API Gateway specification: %s", err) diff --git a/aws/resource_aws_api_gateway_rest_api_test.go b/aws/resource_aws_api_gateway_rest_api_test.go index e169a3b4023..1af758fdf7a 100644 --- a/aws/resource_aws_api_gateway_rest_api_test.go +++ b/aws/resource_aws_api_gateway_rest_api_test.go @@ -379,6 +379,105 @@ func TestAccAWSAPIGatewayRestApi_openapi(t *testing.T) { }) } +func TestAccAWSAPIGatewayRestApi_openapi_body_base_path_ignore(t *testing.T) { + var conf apigateway.RestApi + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayRestAPIConfigOpenAPIBasePathIgnore, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/test"}), + ), + }, + { + ResourceName: "aws_api_gateway_rest_api.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"body"}, + }, + { + Config: testAccAWSAPIGatewayRestAPIUpdateConfigOpenAPIBasePathIgnore, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPINameAttribute(&conf, "test"), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/update"}), + ), + }, + }, + }) +} + +func TestAccAWSAPIGatewayRestApi_openapi_body_base_path_prepend(t *testing.T) { + var conf apigateway.RestApi + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayRestAPIConfigOpenAPIBasePathPrepend, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/foo/bar/baz/test"}), + ), + }, + { + ResourceName: "aws_api_gateway_rest_api.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"body"}, + }, + { + Config: testAccAWSAPIGatewayRestAPIUpdateConfigOpenAPIBasePathPrepend, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPINameAttribute(&conf, "test"), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/foo/bar/baz/update"}), + ), + }, + }, + }) +} + +func TestAccAWSAPIGatewayRestApi_openapi_body_base_path_split(t *testing.T) { + var conf apigateway.RestApi + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayRestAPIConfigOpenAPIBasePathSplit, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/bar/baz/test"}), + ), + }, + { + ResourceName: "aws_api_gateway_rest_api.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"body"}, + }, + { + Config: testAccAWSAPIGatewayRestAPIUpdateConfigOpenAPIBasePathSplit, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), + testAccCheckAWSAPIGatewayRestAPINameAttribute(&conf, "test"), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/bar/baz/update"}), + ), + }, + }, + }) +} + func testAccCheckAWSAPIGatewayRestAPINameAttribute(conf *apigateway.RestApi, name string) resource.TestCheckFunc { return func(s *terraform.State) error { if *conf.Name != name { @@ -624,7 +723,7 @@ resource "aws_api_gateway_rest_api" "test" { "info": { "title": "test", "version": "2017-04-20T04:08:08Z" - }, + }, "schemes": [ "https" ], @@ -692,3 +791,246 @@ resource "aws_api_gateway_rest_api" "test" { EOF } ` + +const testAccAWSAPIGatewayRestAPIConfigOpenAPIBasePathIgnore = ` +resource "aws_api_gateway_rest_api" "test" { + name = "test" + body_base_path = "ignore" + body = < Date: Tue, 29 Jan 2019 14:01:30 +0100 Subject: [PATCH 3/4] docs --- website/docs/r/api_gateway_rest_api.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/docs/r/api_gateway_rest_api.html.markdown b/website/docs/r/api_gateway_rest_api.html.markdown index 03ea9701669..66a935cda73 100644 --- a/website/docs/r/api_gateway_rest_api.html.markdown +++ b/website/docs/r/api_gateway_rest_api.html.markdown @@ -43,6 +43,7 @@ The following arguments are supported: * `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. * `minimum_compression_size` - (Optional) Minimum response size to compress for the REST API. Integer between -1 and 10485760 (10MB). Setting a value greater than -1 will enable compression, -1 disables compression (default). * `body` - (Optional) An OpenAPI specification that defines the set of routes and integrations to create as part of the REST API. +* `body_base_path` - (Optional) Together with OpenAPI specification in `body`, instructs how to interpret the `basePath` field. Defined below. * `policy` - (Optional) JSON formatted policy document that controls access to the API Gateway. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](/docs/providers/aws/guides/iam-policy-documents.html) * `api_key_source` - (Optional) The source of the API key for requests. Valid values are HEADER (default) and AUTHORIZER. @@ -61,6 +62,10 @@ __Note__: If the `body` argument is provided, the OpenAPI specification will be * `types` - (Required) A list of endpoint types. This resource currently only supports managing a single value. Valid values: `EDGE`, `REGIONAL` or `PRIVATE`. If unspecified, defaults to `EDGE`. Must be declared as `REGIONAL` in non-Commercial partitions. Refer to the [documentation](https://docs.aws.amazon.com/apigateway/latest/developerguide/create-regional-api.html) for more information on the difference between edge-optimized and regional APIs. +### body_base_path + +* `types` - (Required) One of `ignore` (default), `prepend` or `split`. Refer to the [documentation](https://docs.aws.amazon.com/cli/latest/reference/apigateway/import-rest-api.html) + ## Attributes Reference In addition to all arguments above, the following attributes are exported: From 31319f18cc3e55ed1a5a6b8b2ba174ec0d11e842 Mon Sep 17 00:00:00 2001 From: "Sascha (Oleksandr) Fedorenko" Date: Mon, 20 Jan 2020 14:47:34 +0100 Subject: [PATCH 4/4] fixing merge problem --- website/docs/r/api_gateway_rest_api.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_gateway_rest_api.html.markdown b/website/docs/r/api_gateway_rest_api.html.markdown index b82602fb22a..ae5180d32ab 100644 --- a/website/docs/r/api_gateway_rest_api.html.markdown +++ b/website/docs/r/api_gateway_rest_api.html.markdown @@ -44,7 +44,7 @@ The following arguments are supported: * `minimum_compression_size` - (Optional) Minimum response size to compress for the REST API. Integer between -1 and 10485760 (10MB). Setting a value greater than -1 will enable compression, -1 disables compression (default). * `body` - (Optional) An OpenAPI specification that defines the set of routes and integrations to create as part of the REST API. * `body_base_path` - (Optional) Together with OpenAPI specification in `body`, instructs how to interpret the `basePath` field. Defined below. -* `policy` - (Optional) JSON formatted policy document that controls access to the API Gateway. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](/docs/providers/aws/guides/iam-policy-documents.html) +* `policy` - (Optional) JSON formatted policy document that controls access to the API Gateway. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](https://learn.hashicorp.com/terraform/aws/iam-policy) * `api_key_source` - (Optional) The source of the API key for requests. Valid values are HEADER (default) and AUTHORIZER. * `tags` - (Optional) Key-value mapping of resource tags