Skip to content

Commit

Permalink
feat(aws): add support for AWS API GatewayV2 HTTP & WebSocket API (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
robh007 committed Nov 9, 2020
1 parent 7603a49 commit bfedbea
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 6 deletions.
55 changes: 55 additions & 0 deletions docs/data-sources/aws_apigatewayv2_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# infracost_aws_apigatewayv2_api

Provides estimated usage data for an AWS API Gateway v2 API. This resource supports the HTTP & Websockets protocol.

## Example Usage

```hcl
resource "aws_apigatewayv2_api" "http" {
name = "my-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_api" "websocket" {
name = "my-websocket-api"
protocol_type = "WEBSOCKET"
}
data "infracost_aws_api_gateway_rest_api" "http_requests" {
resources = list(aws_apigatewayv2_api.http.id)
monthly_requests {
value = 100000000
}
request_size {
value = 512
}
}
data "infracost_aws_api_gateway_rest_api" "websocket_messages" {
resources = list(aws_apigatewayv2_api.websocket.id)
monthly_messages {
value = 100000000
}
average_message_size {
value = 32
}
}
```

## Argument Reference

* `resources` - (Required) The ID of the Rest API.
* `monthly_requests` - (Optional) The estimated monthly requests to the HTTP API Gateway.
* `average_request_size` - (Optional) The estimated average request size in (KB) sent to the HTTP API Gateway. Requests are metered in 512KB increments, maximum size is 10MB.
* `monthly_messages` - (Optional) The number of messages sent to the Websocket API Gateway.
* `average_message_size` - (Optional) The average size of the messages (KB) sent to the Websocket API Gateway. Messages are metered in 32 KB increments, maximum size is 128KB.

### Usage values

Each of the usage value blocks currently supports the following attributes:
* `value` - (Optional) The estimated value.
18 changes: 18 additions & 0 deletions infracost/data_source_aws_apigatewayv2_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package infracost

import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceAwsApiGatewayV2Api() *schema.Resource {
return &schema.Resource{
Read: dataSourceRead,
Schema: map[string]*schema.Schema{
"resources": resourcesSchema(),
"average_message_size": usageSchema(),
"monthly_requests": usageSchema(),
"monthly_messages": usageSchema(),
"request_size": usageSchema(),
},
}
}
58 changes: 58 additions & 0 deletions infracost/data_source_aws_apigatewayv2_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package infracost

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAwsApiGatewayV2Api(t *testing.T) {
http := "data.infracost_aws_apigatewayv2_api.http_requests"
websocket := "data.infracost_aws_apigatewayv2_api.websocket_messages"

resource.Test(t, resource.TestCase{
PreCheck: func() {},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAwsApiGatewayV2Config(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(http, "resources.#", "2"),
testCheckResourceAttrValue(http, "monthly_requests", 1000000),
testCheckResourceAttrValue(http, "request_size", 512),
resource.TestCheckResourceAttr(websocket, "resources.#", "2"),
testCheckResourceAttrValue(websocket, "monthly_messages", 1000000),
testCheckResourceAttrValue(websocket, "average_message_size", 32),
),
},
},
})
}

func testAwsApiGatewayV2Config() string {
return `
data "infracost_aws_apigatewayv2_api" "http_requests" {
resources = list("http_api_1", "http_api_2")
monthly_requests {
value = 1000000
}
request_size {
value = 512
}
}
data "infracost_aws_apigatewayv2_api" "websocket_messages" {
resources = list("my_rest_api_1", "my_rest_api_2")
monthly_messages {
value = 1000000
}
average_message_size {
value = 32
}
}
`
}
13 changes: 7 additions & 6 deletions infracost/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
func Provider() terraform.ResourceProvider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"infracost_aws_api_gateway_rest_api": dataSourceAwsApiGatewayRestApi(),
"infracost_aws_codebuild_project": dataSourceAwsCodebuildProject(),
"infracost_aws_dynamodb_table": dataSourceAwsDynamoDBTable(),
"infracost_aws_lambda_function": dataSourceAwsLambdaFunction(),
"infracost_aws_nat_gateway": dataSourceAwsNatGateway(),
"infracost_aws_sqs_queue": dataSourceAwsSQSQueue(),
"infracost_aws_api_gateway_rest_api": dataSourceAwsApiGatewayRestApi(),
"infracost_aws_apigatewayv2_api": dataSourceAwsApiGatewayV2Api(),
"infracost_aws_codebuild_project": dataSourceAwsCodebuildProject(),
"infracost_aws_dynamodb_table": dataSourceAwsDynamoDBTable(),
"infracost_aws_lambda_function": dataSourceAwsLambdaFunction(),
"infracost_aws_nat_gateway": dataSourceAwsNatGateway(),
"infracost_aws_sqs_queue": dataSourceAwsSQSQueue(),
},
}
}

0 comments on commit bfedbea

Please sign in to comment.