From ebfc7012658ed086066def144e674200f082e245 Mon Sep 17 00:00:00 2001 From: Greg Thole Date: Thu, 5 May 2016 16:14:51 -0400 Subject: [PATCH] provider/aws: AWS API Gateway request parameters json (#6501) * Update docs with new parameters * Add request parameters as JSON * Update function name and error statements --- .../resource_aws_api_gateway_integration.go | 18 ++++- ...ce_aws_api_gateway_integration_response.go | 2 +- ...source_aws_api_gateway_integration_test.go | 18 +++++ .../aws/resource_aws_api_gateway_method.go | 26 ++++-- ...esource_aws_api_gateway_method_response.go | 2 +- ...ce_aws_api_gateway_method_response_test.go | 20 ++--- .../resource_aws_api_gateway_method_test.go | 80 +++++++++++++++++++ builtin/providers/aws/structure.go | 6 +- .../r/api_gateway_integration.html.markdown | 3 + .../aws/r/api_gateway_method.html.markdown | 2 + 10 files changed, 154 insertions(+), 23 deletions(-) diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration.go b/builtin/providers/aws/resource_aws_api_gateway_integration.go index c1dedd8777..68f9c50bf9 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration.go @@ -1,6 +1,7 @@ package aws import ( + "encoding/json" "fmt" "log" "time" @@ -73,6 +74,11 @@ func resourceAwsApiGatewayIntegration() *schema.Resource { Optional: true, Elem: schema.TypeString, }, + + "request_parameters_in_json": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, } } @@ -93,6 +99,13 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa templates[k] = v.(string) } + parameters := make(map[string]string) + if v, ok := d.GetOk("request_parameters_in_json"); ok { + if err := json.Unmarshal([]byte(v.(string)), ¶meters); err != nil { + return fmt.Errorf("Error unmarshaling request_parameters_in_json: %s", err) + } + } + var credentials *string if val, ok := d.GetOk("credentials"); ok { credentials = aws.String(val.(string)) @@ -105,8 +118,8 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa Type: aws.String(d.Get("type").(string)), IntegrationHttpMethod: integrationHttpMethod, Uri: uri, - // TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented - RequestParameters: nil, + // TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented + RequestParameters: aws.StringMap(parameters), RequestTemplates: aws.StringMap(templates), Credentials: credentials, CacheNamespace: nil, @@ -149,6 +162,7 @@ func resourceAwsApiGatewayIntegrationRead(d *schema.ResourceData, meta interface d.Set("credentials", integration.Credentials) d.Set("type", integration.Type) d.Set("uri", integration.Uri) + d.Set("request_parameters_in_json", aws.StringValueMap(integration.RequestParameters)) return nil } diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go index 588ef84b9b..e5f17abd78 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go @@ -75,7 +75,7 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta parameters := make(map[string]string) if v, ok := d.GetOk("response_parameters_in_json"); ok { if err := json.Unmarshal([]byte(v.(string)), ¶meters); err != nil { - return fmt.Errorf("Error unmarshaling request_parameters_in_json: %s", err) + return fmt.Errorf("Error unmarshaling response_parameters_in_json: %s", err) } } diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration_test.go b/builtin/providers/aws/resource_aws_api_gateway_integration_test.go index 74f87bb6c6..090bcf0a94 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_test.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_test.go @@ -59,6 +59,9 @@ func testAccCheckAWSAPIGatewayMockIntegrationAttributes(conf *apigateway.Integra if *conf.Type != "MOCK" { return fmt.Errorf("Wrong Type: %q", *conf.Type) } + if *conf.RequestParameters["integration.request.header.X-Authorization"] != "'updated'" { + return fmt.Errorf("wrong updated RequestParameters for header.X-Authorization") + } return nil } } @@ -80,6 +83,9 @@ func testAccCheckAWSAPIGatewayIntegrationAttributes(conf *apigateway.Integration if *conf.RequestTemplates["application/xml"] != "#set($inputRoot = $input.path('$'))\n{ }" { return fmt.Errorf("wrong RequestTemplate for application/xml") } + if *conf.RequestParameters["integration.request.header.X-Authorization"] != "'static'" { + return fmt.Errorf("wrong RequestParameters for header.X-Authorization") + } return nil } } @@ -178,6 +184,12 @@ resource "aws_api_gateway_integration" "test" { "application/xml" = "#set($inputRoot = $input.path('$'))\n{ }" } + request_parameters_in_json = <