You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ngrok's API requests get throttled at 120 req/minute rate
every single CIDR block has to be individually added to given IP policy (there's no batch option)
each addition (or even check if given entry exists) issues an API request
Terraform codebase with 2 IP policies (50 entries in each) followed by terraform plan generates 100+ requests which results in terraform apply failure (see .tf code snippet below)
Context
Quite often I find myself in a situation that forces me to use ngrok's endpoint as CDN's origin to see what exactly is being exchanged between the edge server and my app. To make it as close to production setup as possible I'd like to protect my ngrok endpoint with some IP policy and/or additional rules.
CDN (and many other service providers) usually come with wide range of public CIDRs (from a few dozen to thousands). Here's a few examples:
At first the problem seem trivial - a combination of data sources from aforementioned providers (i.e. aws_ip_ranges) and ngrok_ip_policy / ngrok_ip_policy_rule should do the trick. Unfortunately, the longer the list the harder it gets. In fact, a few slightly longer IP policies kicks off a vicious cycle you cannot break out of.
Steps to reproduce
The following code snippet would be the best way to explain the situation:
Run AWS_PROFILE="foo" AWS_REGION="eu-central-1" NGROK_API_KEY="bar" terraform plan
Run AWS_PROFILE="foo" AWS_REGION="eu-central-1" NGROK_API_KEY="bar" terraform apply
Current state
The very first plan triggers 0 requests to ngrok API (expected, there's no TF state yet)
apply resulted in 247 API requests and never-ending stream of Error: HTTP 429: Your account is rate limited to 120 API requests per minute. [ERR_NGROK_226] messages
Subsequent plan initiates even more API requests and vicious cycle begins - some resources have just been created, therefore Terraform needs to check if they're correctly configured (in this particular case Terraform triggered 62 GET calls to ngrok API)
Obviously the next apply (if you apply it right after the plan) has just 120-62 requests available. Eventually that results in a "blocked" plan because Terraform cannot even compare its state data to the actual situation (with 120+ rules the plan alone exhausts the 120 req/min limit)
Expected state
Expose batch IP policy update (according to API reference there's no such a thing at all) in order to reduce the overall number of API calls
It'd be nice to see some clever rate limiting handling (i.e. expose available/remaining limits via HTTP headers in 429 responses + retry with exponential backoff based on that data) (see Retry 429 errors with exponential backoff #36)
Noteworthy facts
Higher request/minute limit doesn't solve the problem in the long run (that'd go to 1000s to support larger IP policies and I'm quite sure you don't want to increase it that much)
IP policy can store up to 50 rules
Here's how AWS does it - there's just 1 AWS API request per security group (the entire cidr_blocks list gets transformed into API request payload)
jwadolowski
changed the title
Deployment of many IP policy rules seem infeasible with Terraform
Deployment of many IP policy rules seems infeasible with Terraform
Sep 30, 2024
TLDR
terraform plan
generates 100+ requests which results interraform apply
failure (see.tf
code snippet below)Context
Quite often I find myself in a situation that forces me to use ngrok's endpoint as CDN's origin to see what exactly is being exchanged between the edge server and my app. To make it as close to production setup as possible I'd like to protect my ngrok endpoint with some IP policy and/or additional rules.
CDN (and many other service providers) usually come with wide range of public CIDRs (from a few dozen to thousands). Here's a few examples:
At first the problem seem trivial - a combination of data sources from aforementioned providers (i.e. aws_ip_ranges) and
ngrok_ip_policy
/ngrok_ip_policy_rule
should do the trick. Unfortunately, the longer the list the harder it gets. In fact, a few slightly longer IP policies kicks off a vicious cycle you cannot break out of.Steps to reproduce
The following code snippet would be the best way to explain the situation:
ngrok.tf
file from the snippet aboveAWS_PROFILE="foo" AWS_REGION="eu-central-1" NGROK_API_KEY="bar" terraform plan
AWS_PROFILE="foo" AWS_REGION="eu-central-1" NGROK_API_KEY="bar" terraform apply
Current state
plan
triggers 0 requests to ngrok API (expected, there's no TF state yet)apply
resulted in 247 API requests and never-ending stream ofError: HTTP 429: Your account is rate limited to 120 API requests per minute. [ERR_NGROK_226]
messagesplan
initiates even more API requests and vicious cycle begins - some resources have just been created, therefore Terraform needs to check if they're correctly configured (in this particular case Terraform triggered 62GET
calls to ngrok API)apply
(if you apply it right after theplan
) has just 120-62 requests available. Eventually that results in a "blocked"plan
because Terraform cannot even compare its state data to the actual situation (with 120+ rules theplan
alone exhausts the 120 req/min limit)Expected state
Noteworthy facts
cidr_blocks
list gets transformed into API request payload)The text was updated successfully, but these errors were encountered: