diff --git a/aws/resource_aws_api_gateway_rest_api.go b/aws/resource_aws_api_gateway_rest_api.go index ffd553657ec..8ad41302946 100644 --- a/aws/resource_aws_api_gateway_rest_api.go +++ b/aws/resource_aws_api_gateway_rest_api.go @@ -65,6 +65,12 @@ func resourceAwsApiGatewayRestApi() *schema.Resource { Optional: true, }, + "parameters": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "minimum_compression_size": { Type: schema.TypeInt, Optional: true, @@ -177,11 +183,19 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{} if body, ok := d.GetOk("body"); ok { log.Printf("[DEBUG] Initializing API Gateway from OpenAPI spec %s", d.Id()) - _, err := conn.PutRestApi(&apigateway.PutRestApiInput{ + + input := &apigateway.PutRestApiInput{ RestApiId: gateway.Id, Mode: aws.String(apigateway.PutModeOverwrite), Body: []byte(body.(string)), - }) + } + + if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { + input.Parameters = stringMapToPointers(v.(map[string]interface{})) + } + + _, err := conn.PutRestApi(input) + if err != nil { return fmt.Errorf("error creating API Gateway specification: %s", err) } @@ -410,14 +424,22 @@ func resourceAwsApiGatewayRestApiUpdate(d *schema.ResourceData, meta interface{} } } - if d.HasChange("body") { + if d.HasChanges("body", "parameters") { if body, ok := d.GetOk("body"); ok { log.Printf("[DEBUG] Updating API Gateway from OpenAPI spec: %s", d.Id()) - _, err := conn.PutRestApi(&apigateway.PutRestApiInput{ + + input := &apigateway.PutRestApiInput{ RestApiId: aws.String(d.Id()), Mode: aws.String(apigateway.PutModeOverwrite), Body: []byte(body.(string)), - }) + } + + if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { + input.Parameters = stringMapToPointers(v.(map[string]interface{})) + } + + _, err := conn.PutRestApi(input) + 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 7555fe1d856..73cc2135a3d 100644 --- a/aws/resource_aws_api_gateway_rest_api_test.go +++ b/aws/resource_aws_api_gateway_rest_api_test.go @@ -513,6 +513,40 @@ func TestAccAWSAPIGatewayRestApi_openapi(t *testing.T) { }) } +func TestAccAWSAPIGatewayRestApi_Parameters(t *testing.T) { + var conf apigateway.RestApi + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_rest_api.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccAPIGatewayTypeEDGEPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayRestAPIConfigParameters1(rName, "basepath", "prepend"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists(resourceName, &conf), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/foo", "/foo/bar", "/foo/bar/baz", "/foo/bar/baz/test"}), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"body", "parameters"}, + }, + { + Config: testAccAWSAPIGatewayRestAPIConfigParameters1(rName, "basepath", "ignore"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayRestAPIExists(resourceName, &conf), + testAccCheckAWSAPIGatewayRestAPIRoutes(&conf, []string{"/", "/test"}), + ), + }, + }, + }) +} + func testAccCheckAWSAPIGatewayRestAPINameAttribute(conf *apigateway.RestApi, name string) resource.TestCheckFunc { return func(s *terraform.State) error { if *conf.Name != name { @@ -949,7 +983,7 @@ resource "aws_api_gateway_rest_api" "test" { "info": { "title": "%s", "version": "2017-04-20T04:08:08Z" - }, + }, "schemes": [ "https" ], @@ -1020,3 +1054,49 @@ EOF } `, rName, rName) } + +func testAccAWSAPIGatewayRestAPIConfigParameters1(rName string, parameterKey1 string, parameterValue1 string) string { + return fmt.Sprintf(` +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q + body = <