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 b394291e9..588ef84b9 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go @@ -1,6 +1,7 @@ package aws import ( + "encoding/json" "fmt" "log" "time" @@ -54,6 +55,11 @@ func resourceAwsApiGatewayIntegrationResponse() *schema.Resource { Optional: true, Elem: schema.TypeString, }, + + "response_parameters_in_json": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, } } @@ -66,14 +72,21 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta templates[k] = v.(string) } + 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) + } + } + input := apigateway.PutIntegrationResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), StatusCode: aws.String(d.Get("status_code").(string)), ResponseTemplates: aws.StringMap(templates), - // TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented - ResponseParameters: nil, + // TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented + ResponseParameters: aws.StringMap(parameters), } if v, ok := d.GetOk("selection_pattern"); ok { input.SelectionPattern = aws.String(v.(string)) @@ -106,12 +119,13 @@ func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta i } return err } + log.Printf("[DEBUG] Received API Gateway Integration Response: %s", integrationResponse) d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", d.Get("rest_api_id").(string), d.Get("resource_id").(string), d.Get("http_method").(string), d.Get("status_code").(string))) d.Set("response_templates", integrationResponse.ResponseTemplates) d.Set("selection_pattern", integrationResponse.SelectionPattern) - + d.Set("response_parameters_in_json", aws.StringValueMap(integrationResponse.ResponseParameters)) return nil } diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go b/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go index 3809408db..7220bef17 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go @@ -30,6 +30,18 @@ func TestAccAWSAPIGatewayIntegrationResponse_basic(t *testing.T) { "aws_api_gateway_integration_response.test", "response_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"), ), }, + + resource.TestStep{ + Config: testAccAWSAPIGatewayIntegrationResponseConfigUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayIntegrationResponseExists("aws_api_gateway_integration_response.test", &conf), + testAccCheckAWSAPIGatewayIntegrationResponseAttributesUpdate(&conf), + resource.TestCheckResourceAttr( + "aws_api_gateway_integration_response.test", "response_templates.application/json", "$input.path('$')"), + resource.TestCheckResourceAttr( + "aws_api_gateway_integration_response.test", "response_templates.application/xml", ""), + ), + }, }, }) } @@ -48,6 +60,31 @@ func testAccCheckAWSAPIGatewayIntegrationResponseAttributes(conf *apigateway.Int if conf.SelectionPattern == nil || *conf.SelectionPattern != ".*" { return fmt.Errorf("wrong SelectionPattern (expected .*)") } + if *conf.ResponseParameters["method.response.header.Content-Type"] != "integration.response.body.type" { + return fmt.Errorf("wrong ResponseParameters for header.Content-Type") + } + return nil + } +} + +func testAccCheckAWSAPIGatewayIntegrationResponseAttributesUpdate(conf *apigateway.IntegrationResponse) resource.TestCheckFunc { + return func(s *terraform.State) error { + if *conf.StatusCode != "400" { + return fmt.Errorf("wrong StatusCode: %q", *conf.StatusCode) + } + if *conf.ResponseTemplates["application/json"] != "$input.path('$')" { + return fmt.Errorf("wrong ResponseTemplate for application/json") + } + if conf.ResponseTemplates["application/xml"] != nil { + return fmt.Errorf("wrong ResponseTemplate for application/xml") + } + if conf.SelectionPattern != nil { + return fmt.Errorf("wrong SelectionPattern (expected nil)") + } + if conf.ResponseParameters["method.response.header.Content-Type"] != nil { + return fmt.Errorf("ResponseParameters for header.Content-Type shouldnt exist") + } + return nil } } @@ -147,6 +184,12 @@ resource "aws_api_gateway_method_response" "error" { response_models = { "application/json" = "Error" } + + response_parameters_in_json = <