func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigateway input := apigateway.PutMethodInput{ AuthorizationType: aws.String(d.Get("authorization").(string)), 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)), ApiKeyRequired: aws.Bool(d.Get("api_key_required").(bool)), } models := make(map[string]string) for k, v := range d.Get("request_models").(map[string]interface{}) { models[k] = v.(string) } if len(models) > 0 { input.RequestModels = aws.StringMap(models) } parameters := make(map[string]bool) if kv, ok := d.GetOk("request_parameters"); ok { for k, v := range kv.(map[string]interface{}) { parameters[k], ok = v.(bool) if !ok { value, _ := strconv.ParseBool(v.(string)) parameters[k] = value } } input.RequestParameters = aws.BoolMap(parameters) } 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) } input.RequestParameters = aws.BoolMap(parameters) } if v, ok := d.GetOk("authorizer_id"); ok { input.AuthorizerId = aws.String(v.(string)) } _, err := conn.PutMethod(&input) if err != nil { return fmt.Errorf("Error creating API Gateway Method: %s", err) } d.SetId(fmt.Sprintf("agm-%s-%s-%s", d.Get("rest_api_id").(string), d.Get("resource_id").(string), d.Get("http_method").(string))) log.Printf("[DEBUG] API Gateway Method ID: %s", d.Id()) return nil }
func resourceAwsApiGatewayMethodResponseCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigateway models := make(map[string]string) for k, v := range d.Get("response_models").(map[string]interface{}) { models[k] = v.(string) } parameters := make(map[string]bool) 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) } } _, err := conn.PutMethodResponse(&apigateway.PutMethodResponseInput{ 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)), ResponseModels: aws.StringMap(models), // TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented ResponseParameters: aws.BoolMap(parameters), }) if err != nil { return fmt.Errorf("Error creating API Gateway Method Response: %s", err) } d.SetId(fmt.Sprintf("agmr-%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))) log.Printf("[DEBUG] API Gateway Method ID: %s", d.Id()) return nil }
func TestBoolMap(t *testing.T) { for idx, in := range testCasesBoolMap { if in == nil { continue } out := aws.BoolMap(in) assert.Len(t, out, len(in), "Unexpected len at idx %d", idx) for i := range out { assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx) } out2 := aws.BoolValueMap(out) assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx) assert.Equal(t, in, out2, "Unexpected value at idx %d", idx) } }
func resourceAwsApiGatewayMethodResponseCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigateway models := make(map[string]string) for k, v := range d.Get("response_models").(map[string]interface{}) { models[k] = v.(string) } parameters := make(map[string]bool) if kv, ok := d.GetOk("response_parameters"); ok { for k, v := range kv.(map[string]interface{}) { parameters[k], ok = v.(bool) if !ok { value, _ := strconv.ParseBool(v.(string)) parameters[k] = value } } } 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) } } _, err := conn.PutMethodResponse(&apigateway.PutMethodResponseInput{ 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)), ResponseModels: aws.StringMap(models), ResponseParameters: aws.BoolMap(parameters), }) if err != nil { return fmt.Errorf("Error creating API Gateway Method Response: %s", err) } d.SetId(fmt.Sprintf("agmr-%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))) log.Printf("[DEBUG] API Gateway Method ID: %s", d.Id()) return nil }