• m

    Moruf Ajibike

    1 week ago
    I get invalid API key error when i curl http://localhost/status. .env file is in the root directory of cloud-pricing-api and is set to contain both the API key I got from infracost auth login and the self generated 32 chars self hosted api key. When I use the API key for thr grahpql endpoint, I get a valid response which indicates the API key is valid. Is there anything I'm missing?
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Hi Moruf, can you paste the curl you are using please?
  • m

    Moruf Ajibike

    1 week ago
  • Returns {"error": "Invalid API key"}
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    I don’t think there is a
    /status
    endpoint. Have you tried
    /health
    . There’s some troubleshooting curls here that might help: https://www.infracost.io/docs/cloud_pricing_api/self_hosted/#troubleshooting
  • m

    Moruf Ajibike

    1 week ago
    My bad. Thank you. Not sure where I saw the status endpoint.
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    No worries 😒imple_smile: is it working okay now?
  • m

    Moruf Ajibike

    1 week ago
    Health and graphl endpoints work. However, when I run infracost breakdown pointing to the selfhosted endpoint, I get invalid API response: 403 forbidden
  • We have been notified of the issue
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    How are you setting the api key for the Infracost CLI?
  • m

    Moruf Ajibike

    1 week ago
    Environment var and
    infracost configure set api_key <api_key>
  • Env var name:
    INFRACOST_API_KEY
  • FYI, infracost is running on one vm and cli on another
  • Also /health from vm with cli returns success
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    does the
    /graphql
    endpoint return okay from the VM with the CLI?
  • m

    Moruf Ajibike

    1 week ago
    One sec
  • Result for /graphql returns 400. Get query missing. I set the api key in the header with
    X-Api-Key: <key>
  • Could be that the cli is not picking up the api key?
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Yeah it could be either an issue with the API key or an issue with the pricing API endpoint. How have you specified the pricing API endpoint for the CLI?
  • m

    Moruf Ajibike

    1 week ago
    One sec. Let me get you the code screenshot
  • Can you spot any misconfiguration?
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    nothing obvious. Do you see anything like
    Getting pricing details from
    in the logs? If so, is that looking at the correct pricing API endpoint?
  • m

    Moruf Ajibike

    1 week ago
    Yes, the correct api endpoint is showing in the cli logs. It seems to hit a 403 for the resource
    azurerm_managed_disk
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Okay, I’m not sure. Happy to pair over zoom if you want and we can debug together.
  • m

    Moruf Ajibike

    1 week ago
    That would be awesome
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    provider "aws" {
      region                      = "us-east-1" # <<<<< Try changing this to eu-west-1 to compare the costs
      skip_credentials_validation = true
      skip_requesting_account_id  = true
      access_key                  = "mock_access_key"
      secret_key                  = "mock_secret_key"
    }
    
    resource "aws_instance" "web_app" {
      ami           = "ami-674cbc1e"
      instance_type = "m5.4xlarge" # <<<<< Try changing this to m5.8xlarge to compare the costs
    
      root_block_device {
        volume_size = 50
      }
    
      ebs_block_device {
        device_name = "my_data"
        volume_type = "io1" # <<<<< Try changing this to gp2 to compare costs
        volume_size = 1000
        iops        = 800
      }
    }
    
    resource "aws_lambda_function" "hello_world" {
      function_name = "hello_world"
      role          = "arn:aws:lambda:us-east-1:account-id:resource-id"
      handler       = "exports.test"
      runtime       = "nodejs12.x"
      memory_size   = 1024 # <<<<< Try changing this to 512 to compare costs
    }
    
    output "aws_instance_type" {
      value = aws_instance.web_app.instance_type
    }
  • Just checking - do you have any
    .env
    or
    .env.local
    files in the directory Infracost is running in?
  • m

    Moruf Ajibike

    1 week ago
    Yes, i created a .env file with both api key values
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    can you try without that .env file?
  • m

    Moruf Ajibike

    1 week ago
    Sure. Let me remove it
  • Same error
  • I'm getting the same error when I use the examples/main.tf file
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    @Moruf Ajibike can you paste me the exact error line again?
  • m

    Moruf Ajibike

    1 week ago
    Sorry I can't copy as it's running on a different machine
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Can you try adding an invalid API key request to your list of test curls:
    curl -i $INFRACOST_PRICING_API_ENDPOINT/graphql -H "X-Api-Key: WRONG_API_KEY"
    I want to see if that returns an “Invalid API key” error or a “403 Forbidden” error
  • m

    Moruf Ajibike

    1 week ago
    Okay one sec
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    And try setting
    INFRACOST_API_KEY
    env variable to WRONG_API_KEY as well to see if it changes the error for the CLI
  • m

    Moruf Ajibike

    1 week ago
    Okay
  • The curls failed with 403 forbidden, invalid api key
  • Infracost breakdown failed with invalid api response 403 forbidden
  • Same error as when a valid api key is used
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Interesting, we would expect
    error="Invalid API key"
    for the CLI, so this makes me think it’s not the Cloud Pricing API returning the error but something else. That would also make sense by the fact we’re not seeing any logs in the Cloud Pricing API for these requests.
  • So now I’m wondering if you have a HTTP proxy set and if that is returning this error?
  • m

    Moruf Ajibike

    1 week ago
    Not entirely sure if there is a proxy on the agent. Is there a way I can disable proxy for the cli command?
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    Is there a way I can disable proxy for the cli command? No, we just pick up whatever is in the environment.
    Can you echo out $http_proxy $https_proxy $HTTP_PROXY and $HTTPS_PROXY. We might be able to tell from that.
  • m

    Moruf Ajibike

    1 week ago
    Okay
  • Yes HTTP_PROXY & HTTPS_PROXY values are set
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    ok interesting. Can you try changing your curl commands to use
    curl --proxy="$HTTP_PROXY" ...
    and we can see if they have the same error
  • m

    Moruf Ajibike

    1 week ago
    Ok
  • I get 403 forbidden
  • The cli command also returns 403 forbidden
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    okay, so it seems it is the HTTP PROXY causing the issue. You could try
    export no_proxy=<vm>:<port>
    with your VM’s IP and port and see if that works.
  • m

    Moruf Ajibike

    1 week ago
    Let me try that
  • It was the bloody proxy. It' working now. THANK YOU VERY MUCH.
  • Alistair (Infracost)

    Alistair (Infracost)

    1 week ago
    BOOOM! 🚀 awesome
  • @Moruf Ajibike I’ve added a note to the Troubleshooting guide (https://www.infracost.io/docs/cloud_pricing_api/self_hosted/#troubleshooting) about this issue. I know there’s more we could do in the CLI to help with this, but wanted to get something in the docs for other people if they come across. Thanks for your help with this.
  • m

    Moruf Ajibike

    1 week ago
    That's great. Happy we managed to resolve the issue.