Skip to content

Commit

Permalink
Merge pull request #2076 from Ninir/b-usageplan-ratelimit
Browse files Browse the repository at this point in the history
resource/aws_api_gateway_usag_plan: Fixed setting of rate_limit
  • Loading branch information
Ninir authored Oct 27, 2017
2 parents 35fe15d + dca0899 commit b66f6b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions aws/resource_aws_api_gateway_usage_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func resourceAwsApiGatewayUsagePlan() *schema.Resource {
},

"rate_limit": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Default: 0,
Optional: true,
},
Expand Down Expand Up @@ -188,7 +188,7 @@ func resourceAwsApiGatewayUsagePlanCreate(d *schema.ResourceData, meta interface
}

if sv, ok := q["rate_limit"].(float64); ok {
ts.RateLimit = aws.Float64(float64(sv))
ts.RateLimit = aws.Float64(sv)
}

params.Throttle = ts
Expand Down Expand Up @@ -355,7 +355,7 @@ func resourceAwsApiGatewayUsagePlanUpdate(d *schema.ResourceData, meta interface
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/throttle/rateLimit"),
Value: aws.String(strconv.Itoa(d["rate_limit"].(int))),
Value: aws.String(strconv.FormatFloat(d["rate_limit"].(float64), 'f', -1, 64)),
})
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Expand All @@ -369,7 +369,7 @@ func resourceAwsApiGatewayUsagePlanUpdate(d *schema.ResourceData, meta interface
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("add"),
Path: aws.String("/throttle/rateLimit"),
Value: aws.String(strconv.Itoa(d["rate_limit"].(int))),
Value: aws.String(strconv.FormatFloat(d["rate_limit"].(float64), 'f', -1, 64)),
})
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("add"),
Expand Down
21 changes: 21 additions & 0 deletions aws/resource_aws_api_gateway_usage_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ func TestAccAWSAPIGatewayUsagePlan_throttling(t *testing.T) {
})
}

// https://github.com/terraform-providers/terraform-provider-aws/issues/2057
func TestAccAWSAPIGatewayUsagePlan_throttlingInitialRateLimit(t *testing.T) {
var conf apigateway.UsagePlan
name := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSApiGatewayUsagePlanThrottlingConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings.4173790118.rate_limit", "5"),
),
},
},
})
}

func TestAccAWSAPIGatewayUsagePlan_quota(t *testing.T) {
var conf apigateway.UsagePlan
name := acctest.RandString(10)
Expand Down

0 comments on commit b66f6b6

Please sign in to comment.