From 66a14cb3b732bfd2f41d1672a01758f19dfba9a9 Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Thu, 11 Aug 2016 12:49:59 +0200 Subject: [PATCH] provider/aws: Re-implement api gateway parameter handling (#7794) * provider/aws: Re-implement api gateway parameter handling this PR cleans up some left overs from PR #4295, namely the parameter handling. now that GH-2143 is finally closed this PR does away with the ugly `request_parameters_in_json` and `response_parameters_in_json` hack. * Add deprecation message and conflictsWith settings following @radeksimko s advice, keeping the old code around with a deprecation warning. this should be cleaned up in a few releases * provider/aws: fix missing append operation * provider/aws: mark old parameters clearly as deprecated * provider/aws work around #8104 following @radeksimko s lead * provider/aws fix cnp error --- .../resource_aws_api_gateway_integration.go | 23 ++++++-- ...ce_aws_api_gateway_integration_response.go | 30 +++++++--- ...s_api_gateway_integration_response_test.go | 18 ++---- ...source_aws_api_gateway_integration_test.go | 12 ++-- .../aws/resource_aws_api_gateway_method.go | 44 +++++++++++++-- ...esource_aws_api_gateway_method_response.go | 45 ++++++++++++--- ...ce_aws_api_gateway_method_response_test.go | 13 ++--- .../resource_aws_api_gateway_method_test.go | 14 ++--- builtin/providers/aws/structure.go | 56 ++++++++++++++++++- .../r/api_gateway_integration.html.markdown | 7 +-- ...gateway_integration_response.html.markdown | 6 +- .../aws/r/api_gateway_method.html.markdown | 6 +- .../api_gateway_method_response.html.markdown | 5 +- 13 files changed, 201 insertions(+), 78 deletions(-) diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration.go b/builtin/providers/aws/resource_aws_api_gateway_integration.go index 2cb0c9818c..c745ef3b6d 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration.go @@ -75,9 +75,18 @@ func resourceAwsApiGatewayIntegration() *schema.Resource { Elem: schema.TypeString, }, + "request_parameters": &schema.Schema{ + Type: schema.TypeMap, + Elem: schema.TypeString, + Optional: true, + ConflictsWith: []string{"request_parameters_in_json"}, + }, + "request_parameters_in_json": &schema.Schema{ - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"request_parameters"}, + Deprecated: "Use field request_parameters instead", }, "passthrough_behavior": &schema.Schema{ @@ -107,6 +116,12 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa } parameters := make(map[string]string) + if kv, ok := d.GetOk("request_parameters"); ok { + for k, v := range kv.(map[string]interface{}) { + parameters[k] = v.(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) @@ -129,8 +144,7 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa RestApiId: aws.String(d.Get("rest_api_id").(string)), Type: aws.String(d.Get("type").(string)), IntegrationHttpMethod: integrationHttpMethod, - Uri: uri, - // TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented + Uri: uri, RequestParameters: aws.StringMap(parameters), RequestTemplates: aws.StringMap(templates), Credentials: credentials, @@ -175,6 +189,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", aws.StringValueMap(integration.RequestParameters)) d.Set("request_parameters_in_json", aws.StringValueMap(integration.RequestParameters)) d.Set("passthrough_behavior", integration.PassthroughBehavior) 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 e5f17abd78..c507b3473f 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go @@ -56,9 +56,18 @@ func resourceAwsApiGatewayIntegrationResponse() *schema.Resource { Elem: schema.TypeString, }, + "response_parameters": &schema.Schema{ + Type: schema.TypeMap, + Elem: schema.TypeString, + Optional: true, + ConflictsWith: []string{"response_parameters_in_json"}, + }, + "response_parameters_in_json": &schema.Schema{ - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"response_parameters"}, + Deprecated: "Use field response_parameters instead", }, }, } @@ -73,6 +82,11 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta } parameters := make(map[string]string) + if kv, ok := d.GetOk("response_parameters"); ok { + for k, v := range kv.(map[string]interface{}) { + parameters[k] = v.(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 response_parameters_in_json: %s", err) @@ -80,12 +94,11 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta } 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 reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented + 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), ResponseParameters: aws.StringMap(parameters), } if v, ok := d.GetOk("selection_pattern"); ok { @@ -125,6 +138,7 @@ func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta i 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", aws.StringValueMap(integrationResponse.ResponseParameters)) 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 7220bef178..aba2467309 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 @@ -185,11 +185,9 @@ resource "aws_api_gateway_method_response" "error" { "application/json" = "Error" } - response_parameters_in_json = <