-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws): add support for AWS API GatewayV2 HTTP & WebSocket API (#12)
- Loading branch information
Showing
4 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters