Giter VIP home page Giter VIP logo

infracost / infracost Goto Github PK

View Code? Open in Web Editor NEW
10.3K 69.0 517.0 13.12 MB

Cloud cost estimates for Terraform in pull requests💰📉 Shift FinOps Left!

Home Page: https://infracost.io

License: Apache License 2.0

Makefile 0.24% Go 98.25% Shell 1.42% Dockerfile 0.08% HCL 0.01%
terraform cost-estimation infrastructure-as-code aws terraform-cost-estimation cloud cost-optimization cost-management gcp azure

infracost's Introduction

Infracost breakdown command

Infracost shows cloud cost estimates and FinOps best practices for Terraform. It lets engineers see a cost breakdown and understand costs before making changes, either in the terminal, VS Code or pull requests.

Docs Docker pulls Community Slack channel tweet

Get started

Follow our quick start guide to get started 🚀

Infracost also has many CI/CD integrations so you can easily post cost estimates in pull requests. This provides your team with a safety net as people can discuss costs as part of the workflow.

Post cost estimates in pull requests

Infracost in GitHub Actions

Output of infracost breakdown

Infracost breakdown command

infracost diff shows diff of monthly costs between current and planned state

Infracost diff command

Infracost Cloud

Infracost Cloud is our SaaS product that builds on top of Infracost open source and works with CI/CD integrations. It enables you to check for best practices such as using latest generation instance types or block storage, e.g. consider switching AWS gp2 volumes to gp3 as they are more performant and cheaper. Team leads, managers and FinOps practitioners can also setup tagging policies and guardrails to help guide the team.

Infracost Cloud

Supported clouds and resources

Infracost supports over 1,100 Terraform resources across AWS, Azure and Google. Other IaC tools, such as Pulumi, AWS CloudFormation/CDK and Azure ARM/Bicep are on our roadmap.

Infracost can also estimate usage-based resources such as AWS S3 or Lambda!

Community and contributing

Join our community Slack channel to learn more about cost estimation, Infracost, and to connect with other users and contributors. Checkout the pinned issues for our next community call or our YouTube for previous calls.

We ❤️ contributions big or small. For development details, see the contributing guide. For major changes, including CLI interface changes, please open an issue first to discuss what you would like to change.

Thanks to all the people who have contributed, including bug reports, code, feedback and suggestions!

License

Apache License 2.0

infracost's People

Contributors

actions-user avatar alikhajeh1 avatar aliscott avatar chenrui333 avatar dependabot[bot] avatar dgcaron avatar ekifel avatar fatihtokus avatar golgeek avatar grixxie avatar hugorut avatar jgrumboe avatar kevinkengne avatar krishnaindani avatar m-yosefpor avatar neverovds avatar patmyron avatar pauluson avatar peterdavehello avatar praveenghuge avatar robh007 avatar sashman avatar sawyerward avatar serverabuse avatar sinabakh avatar theragus avatar tim775 avatar varshneydevansh avatar vdmgolub avatar xeger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

infracost's Issues

How should we allow different options for calculating spot prices?

Currently it shows the current spot price, but only refreshed once per hour.

We might want to allow the user to chose between this, the average over the last 30 days or the maximum spot price.

One option for doing this would be a config file. We also might be able to do it using a custom Terraform provider.

Add initial prices for AWS Lambda

Following on from discussions with @sashman.

We can add the prices for Lambda initially, so at least we can see that this resource does have a price, and what the price is for different memory configurations. We can do this initially with something like this:

  NAME                             QUANTITY  UNIT        PRICE PER UNIT  HOURLY COST      MONTHLY COST

  aws_instance.web_app
  ├─ instance hours (t3.micro)          730  hour                0.0104       0.0104           7.5920
  └─ root_block_device GB                15  GB/month            0.0021       0.0021           1.5000
  Total                                                                       0.0125           9.0920

  aws_lambda_function.test_lambda
  └─ requests                            1K  100ms request       0.0002  coming soon      coming soon
  Total                                                                  coming soon      coming soon

  OVERALL TOTAL                                                               0.0700          51.0670

In the future we can then work out the following to be able to show cost ranges:

  • How we can recognise min/max bounds for monthly requests and execution time.
  • How users can specify their own bounds for these.

Using terragrunt

Hey @aliscott, I can use infracost with terraform binary without any troubles, but using terragrunt as TERRAFORM_BIRANY fails with the following error:

$ infracost --tfplan  /tmp/plan.save --tfdir .

INFO Running command: /Users/hamidreza.josheghani.nl/bin/terragrunt show -json /tmp/plan.save 
ERROR [terragrunt] 2020/07/27 18:20:09 Reading Terragrunt config file at /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins/terragrunt.hcl 
ERROR [terragrunt] 2020/07/27 18:20:09 /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins/terragrunt.hcl:24,10-33: Error in function call; Call to function "find_in_parent_folders" failed: ParentFileNotFound: Could not find a terragrunt.hcl in any of the parent folders of /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins/terragrunt.hcl. Cause: Traversed all the way to the root.., and 1 other diagnostic(s) 
ERROR [terragrunt] 2020/07/27 18:20:09 Unable to determine underlying exit code, so Terragrunt will exit with error code 1 
exit status 1
➜  jenkins git:(65d6dba) ✗ cd ~/Documents/DevOps/bits/in/infrastructure-live/shared-services/us-west-2/mgmt/jenkins                                      
➜  jenkins git:(master) avshrd  infracost --tfplan  /tmp/plan.save --tfdir .                                    
INFO Running command: /Users/hamidreza.josheghani.nl/bin/terragrunt show -json /tmp/plan.save 
ERROR [terragrunt] 2020/07/27 18:20:18 Reading Terragrunt config file at /Users/hamidreza.josheghani.nl/Documents/DevOps/bits/in/infrastructure-live/shared-services/us-west-2/mgmt/jenkins/terragrunt.hcl 
ERROR [terragrunt] [/Users/hamidreza.josheghani.nl/Documents/DevOps/bits/in/infrastructure-live/shared-services/us-west-2/mgmt/jenkins] 2020/07/27 18:20:18 Running command: terraform --version 
ERROR [terragrunt] 2020/07/27 18:20:18 Terraform files in /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins are up to date. Will not download again. 
ERROR [terragrunt] 2020/07/27 18:20:18 Copying files from /Users/hamidreza.josheghani.nl/Documents/DevOps/bits/in/infrastructure-live/shared-services/us-west-2/mgmt/jenkins into /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins 
ERROR [terragrunt] 2020/07/27 18:20:18 Setting working directory to /Users/hamidreza.josheghani.nl/.terragrunt-cache/JUfGA5wi4WTKJQMziGewY--KhGo/s2C_bji1SyqpvI6oza4fKa5ohpw/mgmt/jenkins 
ERROR [terragrunt] 2020/07/27 18:20:20 Running command: terraform show -json /tmp/plan.save 
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 1 [running]:
infracost/pkg/parsers/terraform.parseModule(0x5, 0xc0003e0000, 0x64593, 0x0, 0x0, 0x0, 0x0, 0x5, 0xc00041e5d2, 0xab, ...)
        /Users/ali/code/infracost/pkg/parsers/terraform/terraform.go:156 +0x10af
infracost/pkg/parsers/terraform.parseModule(0x5, 0xc0003e0000, 0x64593, 0x0, 0x0, 0x0, 0x0, 0x5, 0xc00041e5d2, 0xab, ...)
        /Users/ali/code/infracost/pkg/parsers/terraform/terraform.go:176 +0xd01
infracost/pkg/parsers/terraform.parseModule(0x5, 0xc0003e0000, 0x64593, 0x0, 0x0, 0x0, 0x0, 0x5, 0xc00041e5d2, 0xab, ...)
        /Users/ali/code/infracost/pkg/parsers/terraform/terraform.go:176 +0xd01
infracost/pkg/parsers/terraform.ParsePlanJSON(0xc000360000, 0x64593, 0x7fe00, 0xe, 0xc000360000, 0x64593, 0x7fe00, 0x0)
        /Users/ali/code/infracost/pkg/parsers/terraform/terraform.go:145 +0x382
main.main.func2(0xc000154a80, 0xc000128e00, 0xe)
        /Users/ali/code/infracost/cmd/infracost/main.go:123 +0x256
github.com/urfave/cli/v2.(*App).RunContext(0xc000132180, 0x151d4e0, 0xc000134008, 0xc000138000, 0x5, 0x5, 0x0, 0x0)
        /Users/ali/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:315 +0x70b
github.com/urfave/cli/v2.(*App).Run(...)
        /Users/ali/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:215
main.main()
        /Users/ali/code/infracost/cmd/infracost/main.go:153 +0x4fb

Due to the terragrunt being a wrapper around terraform, I expected the same result running infracost with terragrunt binary. I maybe have a wrong assumption, but wanted to ask you about this.

Thanks for this awesome tool :-)

Enable running infracost against a terraform.tfstate file

To get costs of an existing infrastructure setup, we need to run something like:

terraform init
infracost --tfdir .

So infracost does a terraform plan internally, and then uses the output of that to generate a report. Alternatively, we can do the terraform plan manually, and then supply the output to infracost.

Either way is quite slow.

All of the information required to report on existing infrastructure will be in the terraform.tfstate JSON file for the project, so if it were possible to run something like:

infracost --terraform-statefile=/path/to/my/project/terraform.tfstate

This could enable cost reports to be generated much more quickly - I'd guess a few seconds rather than several minutes, since it shouldn't be necessary to run terraform init beforehand either.

For many use-cases, this may not be an issue, but in my particular case, with 200+ terraform projects to analyse, it makes a big difference, and I imagine some others will be in a similar situation.

Error when computing cost

Hi @aliscott - first of all, great project and thanks for sharing it with the community.

We tried using infracost in one of our projects and are getting the following errors. Let us know if there is anything else we can provide to help debug. We could also be using the tool wrongly to be fair :)
The infra we tested it against is not overly complex but it has a fair chunk of modules so it might be more than has been tested - not sure.

Generated plan files as following:

terraform plan --var-file=env/$(ENV)/vars.tfvars --out=plan.save
terraform show --json $(ENV)-plan.save > plan.json

Size of plan files - json plan file is about 13k lines

-rw-r--r--   1 alexouzounis  staff   429K 20 Jul 14:47 plan.json
-rw-r--r--   1 alexouzounis  staff    82K 20 Jul 14:47 plan.save

Commands executed, tried both ways:

╰─ infracost --tfdir=. --tfplan=plan.save
INFO Running command: /usr/local/bin/terraform show -json olaf-plan.save 
ERROR Error while reading from Writer: bufio.Scanner: token too long 
signal: broken pipe

and

╰─ infracost --tfdir=. --tfjson=plan.json
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x136d8c6]
goroutine 1 [running]:
infracost/internal/terraform/aws.(*Ec2AutoscalingGroup).PriceComponents(0xc0002c1400, 0x0, 0x0, 0x18271d8)
        /Users/ali/src/infracost/internal/terraform/aws/ec2_autoscaling_group.go:105 +0x26
infracost/pkg/base.(*GraphQLQueryRunner).batchQueries(0xc0002f5280, 0x1535500, 0xc0002c1400, 0x1, 0xc00021c640, 0x1, 0x1, 0xc0002cc060, 0x0)
        /Users/ali/src/infracost/pkg/base/query.go:91 +0x96
infracost/pkg/base.(*GraphQLQueryRunner).RunQueries(0xc0002f5280, 0x1535500, 0xc0002c1400, 0xc0002e4001, 0x78, 0x0)
        /Users/ali/src/infracost/pkg/base/query.go:124 +0x5a
infracost/pkg/base.GenerateCostBreakdowns(0x152b0c0, 0xc0002f5280, 0xc000038600, 0x6, 0x8, 0xc00002c300, 0x30, 0x0, 0x18, 0xc00000ef00)
        /Users/ali/src/infracost/pkg/base/costs.go:93 +0x636
main.main.func2(0xc000090b00, 0xc00000ef00, 0xe)
        /Users/ali/src/infracost/cmd/infracost/main.go:129 +0x389
github.com/urfave/cli/v2.(*App).RunContext(0xc000001980, 0x1532ea0, 0xc000028080, 0xc0000201b0, 0x3, 0x3, 0x0, 0x0)
        /Users/ali/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:315 +0x6be
github.com/urfave/cli/v2.(*App).Run(...)
        /Users/ali/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:215
main.main()
        /Users/ali/src/infracost/cmd/infracost/main.go:153 +0x5d1

Wrong aws_autoscaling_group calculation for spot instances

I have aws_launch_template which is using spot instances / spot bidding with autoscaling group, however infracost is showing those instances as on-demand:

  aws_autoscaling_group.spot_asg
  ├─ Compute (on-demand, t3a.nano) (aws_launch_template.xxx)          730  hours      0.0053       0.0053        3.8690

ASG in module computed incorrectly

Using an autoscaling module...

module "asg" {
  source  = "terraform-aws-modules/autoscaling/aws"
  version = "~> 3.0"
  
  name = "foobar"

  lc_name = "foobar"

  image_id        = var.ami_id

  instance_type   = "r5a.xlarge"
  security_groups = [aws_security_group.foobar.id]
....

Produces Zero cost.


$ infracost
  NAME                                                            MONTHLY QTY  UNIT  PRICE  HOURLY COST  MONTHLY COST  

  module.prod-foobar.module.asg.aws_autoscaling_group.this[0]                                                       
  Total                                                                                          0.0000        0.0000  
                                                                                                                       
  OVERALL TOTAL                                                                                  0.0000        0.0000  

Happy to contribute but might need a pointer for where to start looking, I'm new to the tool, but a big fan in principle.... I suspect the tool just might not be recursing down to past the first level module?

Enhancing price explorer scripts

Thanks to @alikhajeh1 our simple scripts are way better than before 😃 . There are still some improvements which we can make:

  • Price explorer script 3_find_attribute_keys.sh always outputs 2 different products found.
  • creating tmp files pollute the directory and it's not a clean solution
  • The output for the scripts can be enhanced

Support for ECS and Fargate

Hello,

I was wondering what would be involved in adding support for ECS (specifically Fargate) pricing - I'm not opposed to implementing this myself but a nudge in the right direction would be great.

Cheers!

Show unknown price for unsupported resources

It seems the unsupported resources are not shown in the report.
I think it's more suitable if the report shows such resources with some "Unknown price" flag. This way users can better track their resources in the report.
Here is a rough idea of this feature:

   NAME                             QUANTITY  UNIT        PRICE PER UNIT  HOURLY COST      MONTHLY COST

   unknown_resource                 ?           ?               ?           ?                   ?

    

   OVERALL TOTAL                       0.0000        0.0000

Add pricing support for AWS CloudFormation

AWS Cloud Formation costs: https://aws.amazon.com/cloudformation/pricing/

aws_cloudformation_stack and aws_cloudformation_stack_set are the main resources. For each one, we can use this logic to show the cost components:

  1. If template_body is set AND its "Resources.types" start with AWS::*, Alexa::*, or Custom::* then return IsSkipped: true, NoPrice: true, as it's a free resource.
  2. Else, show both of these:
  • "Handler operations", units "operations". Usage file param monthly_handler_operations: 10000 # Monthly number of non-free handler operations (resources outside of the AWS::*, Alexa::*, and Custom::* namespaces).
  • "Durations above 30s", units "seconds". Usage file param monthly_duration_secs: 0 # Monthly duration of non-free handler operations that go above 30 seconds, in seconds.

As normal, the cost components should show cost-depends-on-usage if the usage file param is not specified.

Free resources:
aws_cloudformation_stack_set_instance
aws_cloudformation_type

Zero cost for an EKS cluster with terraform-aws-modules/eks/aws

Hello,
Using latest infracost, version 0.5.1, I tried running the following to get estimated costs for an EKS cluster created using https://github.com/terraform-aws-modules/terraform-aws-eks (it's just a couple of wrappers on top of official Terraform EKS modules, AFAIK) - but I got an empty table with a cost of 0.

TF_CLI_ARGS_plan="-var-file=variables.tfvars -var cluster_name=${CLUSTER}" infracost --tfdir .
  NAME           MONTHLY QTY  UNIT  PRICE  HOURLY COST  MONTHLY COST  

  OVERALL TOTAL                                 0.0000        0.0000  

Unfortunately, DEBUGor even TRACE logs don't help that much:

TF_CLI_ARGS_plan="-var-file=variables.tfvars -var cluster_name=${CLUSTER}" infracost --log-level=TRACE  --tfdir .
INFO Running command: /usr/bin/terraform init 
  NAME           MONTHLY QTY  UNIT  PRICE  HOURLY COST  MONTHLY COST  

  OVERALL TOTAL                                 0.0000        0.0000  

Here is the state list result on the same Terraform directory:

# terraform state list                                                            
data.aws_eks_cluster.cluster
data.aws_eks_cluster_auth.cluster
data.aws_region.current
kubernetes_cluster_role.cluster_autoscaler
kubernetes_cluster_role_binding.cluster_autoscaler
kubernetes_deployment.cluster_autoscaler
kubernetes_role.cluster_autoscaler
kubernetes_role_binding.cluster_autoscaler
kubernetes_service_account.cluster_autoscaler
module.datasource.data.aws_caller_identity.current
module.datasource.data.aws_region.current
module.datasource.data.aws_security_group.eks-entrypoints
module.datasource.data.aws_subnet_ids.subnets
module.datasource.data.aws_vpc.shared_vpc
module.eks.data.aws_ami.eks_worker
module.eks.data.aws_ami.eks_worker_windows
module.eks.data.aws_caller_identity.current
module.eks.data.aws_iam_policy_document.cluster_assume_role_policy
module.eks.data.aws_iam_policy_document.workers_assume_role_policy
module.eks.data.aws_iam_role.custom_cluster_iam_role[0]
module.eks.data.aws_partition.current
module.eks.data.null_data_source.node_groups[0]
module.eks.aws_eks_cluster.this[0]
module.eks.local_file.kubeconfig[0]
module.eks.module.node_groups.aws_eks_node_group.workers["my-node"]
module.eks.module.node_groups.random_pet.node_groups["my-node"]

Interestingly enough, if I add a t2.micro, I'm gonna get some results:

resource "aws_instance" "example" {
  ami           = "ami-0e7767d1cb89be85d"
  instance_type = "t2.micro"
}
TF_CLI_ARGS_plan="-var-file=variables.tfvars -var cluster_name=${CLUSTER}" infracost --log-level=TRACE  --tfdir .
INFO Running command: /usr/bin/terraform init 
  NAME                              MONTHLY QTY  UNIT       PRICE   HOURLY COST  MONTHLY COST  

  aws_instance.example                                                                         
  ├─ Compute (on-demand, t2.micro)          730  hours      0.0116       0.0116        8.4680  
  └─ Storage (root_block_device)              8  GB-months  0.1000       0.0011        0.8000  
  Total                                                                  0.0127        9.2680  
                                                                                               
  OVERALL TOTAL                                                          0.0127        9.2680  

So all in all, I'm wondering if infracostcan estimate EKS costs ?

Looking at the GraphQL API (https://pricing.infracost.io/graphql) I can see EKS is there though:

query {
  products(
    filter: {
      vendorName: "aws",
      service: "AmazonEKS",
      region: "ca-central-1"
    },
  ) {
    attributes { key, value }
    prices { USD }
  }
}

will return

{
  "data": {
    "products": [
      {
        "attributes": [
          {
            "key": "servicecode",
            "value": "AmazonEKS"
          },
          {
            "key": "location",
            "value": "Canada (Central)"
          },
          {
            "key": "locationType",
            "value": "AWS Region"
          },
          {
            "key": "usagetype",
            "value": "CAN1-AmazonEKS-Hours:perCluster"
          },
          {
            "key": "operation",
            "value": "CreateOperation"
          },
          {
            "key": "servicename",
            "value": "Amazon Elastic Container Service for Kubernetes"
          },
          {
            "key": "tiertype",
            "value": "HAStandard"
          }
        ],
        "prices": [
          {
            "USD": "0.1000000000"
          }
        ]
      }
    ]
  }
}

Thanks for your help!

Allow pass through of tf vars

infracost --tfdir examples/terraform

It's a nice to have for the above command to also accept the variables required for the terraform plan. For example:

infracost --tfdir examples/terraform -var key=value

or

infracost --tfdir examples/terraform --var-file my.tfvars

[Feature Request] Support for S3 storage

Storage prices are dependent on the region (which is available in terraform), the amount of data being stored (which isn't available in terraform) and the storage tier (which is available in terraform)

Can we add a .infracost.config or something to the repository to mention the rough volume of data in different S3 paths (which should help project costs based on different storage tiers) or is there another way you recommend?

I'm asking because I'd like to take a shot at implementing this. It's my first time in golang so any guidelines I should read up before contributing will be quite helpful.

Adding a `version` flag to infracost cli

We shall have a version flag, which outputs both the infracost version, and the current terraform version which infracost uses for that environemnt. That will come in handy and also all most all cli tools have, so people expect it to be there.

Non-linux AWS EC2 AMIs, e.g. Windows and marketplace items

Is there any way to support instances based on marketplace AMIs? These are typically the most expensive ones so it would be nice to see the "subscription" cost along with the EC2 compute itself.

Not sure how feasible is this with the current approach where you seem to be caching the AWS pricelist separately on your website.

Adding diff functionality to JSON output

Current aim

The aim of this ticket is to update the Infracost JSON output so it includes the following fields, which can then be used in the future to build table/HTML outputs that show the diff of what's about to be applied.

existingState:
  resources:
    ...
  totalHourlyCost
  totalMonthlyCost

plannedState:
  resources:
    ...
  totalHourlyCost
  totalMonthlyCost

diff:
  resources:
    ...
  totalHourlyCost
  totalMonthlyCost

timeGenerated
resourceSummary

Original ticket description

Options to support:

  • tfplan
  • tfjson
  • tfdirs
  • tfstate (after #90)

So it would be 4*4=16 possible combinations to invoke it.

User can invoke it like

infracost diff --tfdir first/path --tfdir second/path
infracost diff --tfdir first/path --tfplan second/plan
...

So the flag presence order would be important. What other kind of implementations would work better??

Error parsing terraform locals

I am trying to run infrascost for some of my terraform resources and I am getting below error :

➜ infracost --tfdir terraform/
⠋ Calculating costs… ERROR There are some problems with the configuration, described below.
ERROR
ERROR The Terraform configuration must be valid before initialization so that
ERROR Terraform can determine which modules and providers need to be installed.
ERROR
ERROR Error: Error parsing /karan/Desktop/terraform/data.tf: At 85:25: unexpected token while parsing list: IDENT
ERROR
ERROR
exit status 1
➜

The code in data.tf at line 85 is locals defining some subnet id, etc. shown below:

locals {
  private_subnets    = [data.aws_subnet.private-1a-prod, data.aws_subnet.private-1c-prod, data.aws_subnet.private-1d-prod]
  private_subnet_ids = local.private_subnets.*.id
  private_subnet_azs = local.private_subnets.*.availability_zone
}

I am using terraform version 0.12.16 & aws provider version 2.51.0

Could you please help with this issue?

Support nil cost components

There are cases where combining usage data with actual resources creates conditions that a cost component makes no sense. For instance, a provisioned DynamoDB shall not have read/write request units.
Here is a simple code for the write request units cost component:

func NewDynamoDBTable(d *schema.ResourceData, u *schema.ResourceData) *schema.Resource {
  costComponents := make([]*schema.CostComponent, 0)
  costComponents = append(costComponents, wruCostComponent(d))
}

func wruCostComponent(d *schema.ResourceData) *schema.CostComponent {
  costComponent := &schema.CostComponent{}
  if billingMode == "PROVISIONED" {
    log.Warnf("Skipping write request units usage data for %s. Provisioned mode does not support write request units.", d.Address)
    return costComponent
  }
  ...
  return costComponent
}

This way, the core produces a warning for the empty cost component and the output shows an empty line.

The other way around is to return nil and check the result of the function and skip it if it's nil but it makes the code filled with the same conditions.

I propose we add support for nil cost components in the core.

Panic using tfjson file

Hello!
Using the latest 0.5.1 version, I got the following with a plan.jsonfile that I generated from a plan.save (same workflow as described in the docs)

infracost --tfdir=. --tfjson=plan.json
⠋ Calculating costs… panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/infracost/infracost/pkg/schema.AddRawValue(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x87d84f, 0x6, 0x7ef520, ...)
        /home/runner/work/infracost/infracost/pkg/schema/resource_data.go:49 +0x106
github.com/infracost/infracost/internal/providers/terraform.parseResourceData(0x5, 0xc000270000, 0x48de2, 0x0, 0x0, 0x0, 0x0, 0x5, 0xc000296d2f, 0x45f, ...)
        /home/runner/work/infracost/infracost/internal/providers/terraform/parser.go:64 +0x5c1
github.com/infracost/infracost/internal/providers/terraform.parsePlanJSON(0xc0001f0000, 0x48de2, 0x7fe00, 0x48de2, 0x7fe00, 0x0)
        /home/runner/work/infracost/infracost/internal/providers/terraform/parser.go:32 +0x367
github.com/infracost/infracost/internal/providers/terraform.(*terraformProvider).LoadResources(0xc000099830, 0xc00010fd88, 0x2, 0x2, 0x0, 0x0)
        /home/runner/work/infracost/infracost/internal/providers/terraform/provider.go:59 +0x75
main.main.func2(0xc0000bcf00, 0xc0000acf00, 0xe)
        /home/runner/work/infracost/infracost/cmd/infracost/main.go:116 +0x253
github.com/urfave/cli/v2.(*App).RunContext(0xc000082900, 0x91f680, 0xc0000b4010, 0xc0000bc040, 0x4, 0x4, 0x0, 0x0)
        /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:315 +0x70b
github.com/urfave/cli/v2.(*App).Run(...)
        /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:215
main.main()
        /home/runner/work/infracost/infracost/cmd/infracost/main.go:147 +0x4b0

I can provide the json file if it helps
Thanks !

Support GitHub Windows Runners

GitHub documentation:

Docker container actions can only execute on runners with a Linux operating system

There should be either two actions (windows/linux) or a JavaScript executed binary which will allow an action to be run from all support GitHub Runners.

[DOCS] Update README.md with Docker usage

Add to the usage section-

Docker

Replace the --tf-dir value with your infra's path, or git clone this repository to check the examples

docker run --rm -v $PWD/:/code/ infracost/infracost:latest --tf-dir /code/examples/small_terraform

Terraform0.13 module "count" & "depends_on" does not work

This tool is having problems with the Beta of Terraform0.13 configurations.

INFO Running command: /Users/teranos/go/bin/terraform init 
ERROR There are some problems with the configuration, described below. 
ERROR                                              
ERROR The Terraform configuration must be valid before initialization so that 
ERROR Terraform can determine which modules and providers need to be installed. 
ERROR                                         
ERROR Error: Reserved argument name in module block 
ERROR                                              
ERROR   on ingest.tf line 4, in module "ingest": 
ERROR    4:   count = var.enable_raven_ingest ? 1 : 0 
ERROR                                          
ERROR The name "count" is reserved for use in a future version of Terraform. 
ERROR                                      
ERROR                                         
ERROR Error: Reserved argument name in module block 
ERROR                                              
ERROR   on ingest.tf line 27, in module "ingest": 
ERROR   27:   depends_on = [               
ERROR                                          
ERROR The name "depends_on" is reserved for use in a future version of Terraform. 
ERROR                                      
exit status 1

Add Infracost Terraform Provider for modelling usage based costs

This is a proposal for adding an Infracost Terraform Provider for representing usage based costs. This would allow us to reference any existing Terraform resource and augment it with additional information we can use to calculate the usage costs.

Here is an example of how this could be represented for a lambda function:

resource "infracost_usage_aws_lambda_function" "test_lambda" {
  resources = [aws_lambda_function.test_lambda]

  estimated_request_count {
    min = 10000
    max = 15000
  } 
  estimated_request_duration {
    min = 260
    max = 300
  }
}

This would also require a min/max cost range to be represented as first suggested in aliscott#21.

Other options for this could include an additional config file (as suggested in aliscott#34). Other suggestions are welcome.

Show carbon cost of infrastructure

It would be good to have a mode or option to show the carbon cost of the infrastructure as well as / instead of the monetary cost. This isn’t necessarily proportional to the monetary cost, as different resources (compute, storage, bandwidth) have different carbon weightings, and the different AWS data centre locations have different carbon intensities of their power supplies (some are powered renewably, many aren’t, aiui).

This would give developers some ability to factor in the carbon implications of their infrastructure into decisions, or into calculations of the carbon emissions of their project or business.

Worth considering? 🙂

Support AWS CloudWatch costs

Terraform cloud's cost estimation supports these:

  • aws_cloudwatch_dashboard: should be $3 per dashboard per month ?
  • aws_cloudwatch_metric_alarm: might be difficult with Anomaly detection and high-resolution

Improve performance of integration tests

Currently the integrations tests take ~10 seconds each to run. This is because they are running terraform init, terraform plan and hitting the pricing.infracost.io service for each test.

There's various options to improve the performance. Some initial ideas:

  • Parallelise the tests
  • Cache the pricing API responses
  • Cache the terraform plan outputs
  • Only run terraform init and terraform plan once when the tests run by somehow merging the tests into a single Terraform project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.