From 790888388765bed59f791ca09329c9e0136e4c8b Mon Sep 17 00:00:00 2001 From: Ali Date: Sun, 18 Feb 2024 16:32:31 +0300 Subject: [PATCH 1/2] docs: update CI/CD integrations --- docs/faq.md | 18 +- docs/features/cli_commands.md | 12 -- docs/{integrations => features}/vscode.md | 0 docs/getting_started.md | 4 - docs/guides/actions_migration.md | 114 ----------- docs/guides/atlantis_migration.md | 41 ---- docs/guides/azure_devops_migration.md | 102 ---------- docs/guides/gitlab_ci_migration.md | 94 --------- docs/guides/source_control_benefits.md | 142 ------------- docs/guides/uninstall.md | 39 ---- docs/guides/v0.10_migration.md | 179 ----------------- docs/guides/v0.8_migration.md | 161 --------------- docs/guides/v0.9_migration.md | 96 --------- docs/infracost_cloud/finops_policies.md | 4 - docs/infracost_cloud/get_started.md | 102 +++++++--- docs/infracost_cloud/guardrails.md | 4 - docs/infracost_cloud/tagging_policies.md | 4 - docs/integrations/atlantis.md | 12 -- docs/integrations/azure_pipelines.md | 10 - docs/integrations/cicd.mdx | 20 +- docs/integrations/cicd_integrations.md | 8 + docs/integrations/generic_cicd.md | 40 ---- docs/integrations/github_actions.md | 12 -- docs/integrations/github_app.md | 13 +- docs/integrations/gitlab_app.md | 2 +- docs/integrations/gitlab_ci.md | 14 -- docs/integrations/slack.md | 2 +- docs/integrations/third_party_integrations.md | 3 +- .../cloud_pricing_api.md} | 4 +- docs/troubleshooting.md | 190 +----------------- docusaurus.config.js | 14 +- sidebars.js | 37 +--- 32 files changed, 136 insertions(+), 1361 deletions(-) rename docs/{integrations => features}/vscode.md (100%) delete mode 100644 docs/guides/actions_migration.md delete mode 100644 docs/guides/atlantis_migration.md delete mode 100644 docs/guides/azure_devops_migration.md delete mode 100644 docs/guides/gitlab_ci_migration.md delete mode 100644 docs/guides/source_control_benefits.md delete mode 100644 docs/guides/uninstall.md delete mode 100644 docs/guides/v0.10_migration.md delete mode 100644 docs/guides/v0.8_migration.md delete mode 100644 docs/guides/v0.9_migration.md delete mode 100644 docs/integrations/atlantis.md delete mode 100644 docs/integrations/azure_pipelines.md create mode 100644 docs/integrations/cicd_integrations.md delete mode 100644 docs/integrations/generic_cicd.md delete mode 100644 docs/integrations/github_actions.md delete mode 100644 docs/integrations/gitlab_ci.md rename docs/{cloud_pricing_api/api_usage.md => supported_resources/cloud_pricing_api.md} (99%) diff --git a/docs/faq.md b/docs/faq.md index bb616900..5436dba3 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -5,20 +5,20 @@ title: FAQ ## How does Infracost work? -Infracost has a [CLI](https://github.com/infracost/infracost) and a [Cloud Pricing API](/docs/cloud_pricing_api/overview) backend service, as well as many [CI/CD integrations](/docs/integrations/cicd). There is also a SaaS product, Infracost Cloud, that complements the open source CLI by giving teams advanced visibility and controls. +Infracost has a [CLI](https://github.com/infracost/infracost) and a [Cloud Pricing API](/docs/supported_resources/cloud_pricing_api) backend service, as well as many [CI/CD integrations](/docs/integrations/cicd). There is also a SaaS product, Infracost Cloud, that complements the open source CLI by giving teams advanced visibility and controls. When the CLI runs, it: 1. **Extracts cost-related parameters**
The CLI parses Terraform HCL code to extract only [cost-related parameters](/docs/faq#example-request), such as the instance type or disk size. 2. **Retrieves prices from the Cloud Pricing API**
- The CLI retrieves prices from the Cloud Pricing API. The CLI **does not** send the actual plan JSON file, or any cloud credentials or secrets to the Cloud Pricing API. The API [returns the prices](/docs/faq#example-response). + The CLI retrieves prices from the Cloud Pricing API. The CLI **does not** send the Terraform plan JSON file, or any cloud credentials or secrets to the Cloud Pricing API. The API [returns the prices](/docs/faq#example-response). 3. **Calculates the monthly costs**
- The CLI calculates the monthly costs. The results can be output in table, JSON format or [other formats](/docs/features/cli_commands/#combined-output-formats). + The CLI calculates the monthly costs. The results can be output in [various formats](/docs/features/cli_commands/#combined-output-formats) including JSON or text table. 4. **Infracost Cloud**
- If you have enabled this product, the CLI sends the final cost estimate in JSON format to your account in Infracost Cloud. + If you use Infracost Cloud, the CLI sends the final cost estimate in JSON format to your dashboard, the JSON does not contain any cloud credentials or secrets. ## Security and Privacy @@ -80,15 +80,15 @@ query { ### Does Infracost need cloud credentials? -No! Infracost parses code and uses pricing data to estimate costs. +No! Infracost parses code directly and uses pricing data to estimate costs. ### Does the Infracost CLI send the Terraform plan to the Cloud Pricing API? -No. The Infracost CLI parses the Terraform plan JSON file to find [cost-related parameters](/docs/faq#example-request) and uses those to lookup cloud prices. +No. The Infracost CLI parses the Terraform HCL code directly or the plan JSON file to find [cost-related parameters](/docs/faq#example-request) and uses those to lookup cloud prices. ### What data is sent to Infracost Cloud? -If you have [enabled](/docs/infracost_cloud/get_started/) this, the CLI sends its [JSON output](/docs/features/cli_commands/#examples) to your account in Infracost Cloud; you can generate and inspect this JSON. It does not contain any cloud credentials or secrets. +If you use [Infracost Cloud](/docs/infracost_cloud/get_started/), the CLI sends its [JSON output](/docs/features/cli_commands/#combined-output-formats) to your dashboard; you can generate and inspect this JSON. It does not contain any cloud credentials or secrets. ### Do you sell my data? @@ -135,9 +135,7 @@ Sure! See the [currency](/docs/features/environment_variables/#infracost_currenc ### What's the difference between source control and CI/CD integration? -Source control integration is when you connect Infracost directly to your GitHub or GitLab. CI/CD integration is when you install the Infracost CLI in your CI/CD pipelines and run commands. - -We recommend source control integration as it is much simpler to setup, and faster to run. [This page](/docs/guides/source_control_benefits/) explains more about the benefits of source control integrations over CI/CD integrations. +Source control integration is when you connect Infracost directly to your GitHub or GitLab. CI/CD integration is when you install the Infracost CLI in your CI/CD pipelines and run commands. We recommend source control integration as it is simpler to setup and faster to run. ### Do you offer support? diff --git a/docs/features/cli_commands.md b/docs/features/cli_commands.md index be4dd0c1..08db2239 100644 --- a/docs/features/cli_commands.md +++ b/docs/features/cli_commands.md @@ -49,7 +49,6 @@ This is the **default and recommended** option. It does not require a Terraform Usually no extra setup is needed for handling the following on your local development machines. For CI/CD, see the corresponding pages. - **Private modules** see [this page](/docs/features/terraform_modules/) for more details. - **Terragrunt** see [this page](/docs/features/terragrunt/) for more details. -- **Terraform Cloud/Enterprise** see [this page](/docs/integrations/terraform_cloud_enterprise/#running-infracost-on-local-dev-machines) for more details. ### Option 2: Terraform plan JSON @@ -314,7 +313,6 @@ infracost comment github --path=infracost.json \ - `--github-token`: required, use `$GITHUB_TOKEN`. - `--github-api-url`: optional (default "https://api.github.com"), GitHub Enterprise users can set this to `$GITHUB_API_URL` in GitHub Actions. Also see `--github-tls-cert-file`, `--github-tls-key-file` and `--github-tls-insecure-skip-verify`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### Azure Pipelines with GitHub @@ -334,7 +332,6 @@ infracost comment github --path=infracost.json \ - `--github-token`: required, use `$GITHUB_TOKEN`. - `--github-api-url`: optional (default "https://api.github.com"), GitHub Enterprise users can set this to `https://GITHUB_SERVER/api`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### Atlantis with GitHub @@ -354,7 +351,6 @@ infracost comment github --path=infracost.json \ - `--github-token`: required, provide your GitHub token, for example, as an environment variable `$GITHUB_TOKEN`. - `--github-api-url`: optional (default "https://api.github.com"), GitHub Enterprise users can set this to `https://GITHUB_SERVER/api`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### CircleCI with GitHub @@ -374,7 +370,6 @@ infracost comment github --path=infracost.json \ - `--github-token`: required, provide your GitHub token, for example, as an environment variable `$GITHUB_TOKEN`. - `--github-api-url`: optional (default "https://api.github.com"), GitHub Enterprise users can set this to `https://GITHUB_SERVER/api`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. ### GitLab @@ -398,7 +393,6 @@ infracost comment gitlab --path=infracost.json \ - `--gitlab-token`: required, use `$GITLAB_TOKEN`. - `--gitlab-server-url`: optional, URL for GitLab Enterprise users (default "https://gitlab.com"). In GitLab CI you can set this to `$CI_SERVER_URL`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### Atlantis with GitLab @@ -418,7 +412,6 @@ infracost comment gitlab --path=infracost.json \ - `--gitlab-token`: required, provide your GitLab token as an environment variable, for example as `$GITLAB_TOKEN`. - `--gitlab-server-url`: optional, URL for GitLab Enterprise users (default "https://gitlab.com"). - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. ### Azure Repos @@ -440,7 +433,6 @@ infracost comment azure-repos --path=infracost.json \ - `--pull-request`: required to post on a pull request, `$SYSTEM_PULLREQUEST_PULLREQUESTID`. - `--azure-access-token`: required, use `$SYSTEM_ACCESSTOKEN`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### Atlantis with Azure Repos @@ -458,7 +450,6 @@ infracost comment azure-repos --path=infracost.json \ - `--pull-request`: required to post on a pull request, use `$PULL_NUM`. - `--azure-access-token`: required, provide your Azure DevOps access token, for example, as an environment variable `$AZURE_ACCESS_TOKEN`. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. ### Bitbucket @@ -483,7 +474,6 @@ infracost comment bitbucket --path=infracost.json \ - `--bitbucket-server-url`: optional, URL for Bitbucket Server/Data Center users (default "https://bitbucket.org"). - `--exclude-cli-output`: optional, exclude CLI output so comment has just the summary table. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### CircleCI with Bitbucket @@ -504,7 +494,6 @@ infracost comment bitbucket --path infracost.json \ - `--bitbucket-server-url`: optional, URL for Bitbucket Server/Data Center users (default "https://bitbucket.org"). - `--exclude-cli-output`: optional, exclude CLI output so comment has just the summary table. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. #### Atlantis with Bitbucket @@ -525,7 +514,6 @@ infracost comment bitbucket --path=infracost.json \ - `--bitbucket-server-url`: optional, URL for Bitbucket Server/Data Center users (default "https://bitbucket.org"). - `--exclude-cli-output`: optional, exclude CLI output so comment has just the summary table. - `--tag`: optional, customize hidden markdown tag used to detect comments posted by Infracost. -- `--policy-path`: optional, path to Infracost [cost policy](/docs/features/cost_policies/) files, glob patterns need quotes (experimental). - `--show-all-projects`: optional, show all projects in the table of the comment output. ## Upload runs diff --git a/docs/integrations/vscode.md b/docs/features/vscode.md similarity index 100% rename from docs/integrations/vscode.md rename to docs/features/vscode.md diff --git a/docs/getting_started.md b/docs/getting_started.md index c1acbfca..d6fe5cd0 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -184,7 +184,3 @@ Example output: If you run into any issues, please join our [community Slack channel](https://www.infracost.io/community-chat), we'll help you very quickly πŸ˜„ Infracost pull request comment - -If you use VS Code, checkout our [VS Code extension](https://github.com/infracost/vscode-infracost/) to also see cost estimates right in your editor! - -Infracost VS Code extension diff --git a/docs/guides/actions_migration.md b/docs/guides/actions_migration.md deleted file mode 100644 index f6c769db..00000000 --- a/docs/guides/actions_migration.md +++ /dev/null @@ -1,114 +0,0 @@ ---- -slug: actions_migration -title: GitHub Actions migration ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -If you encounter any issues while migrating, please join our [community Slack channel](https://www.infracost.io/community-chat), we'll help you very quickly πŸ˜„ - -# Actions to GitHub App migration - -:::tip -We recommend using the [GitHub App](/docs/integrations/github_app/) as it has several benefits over GitHub Actions. -::: - -1. Follow the [GitHub App](/docs/integrations/github_app/) docs to install the app. You can do this from the same Infracost organization you use already, and going into the Org Settings > Integrations page. -2. Test it by sending a pull request that costs money, and ensuring that the pull request comment matches between the GitHub Actions and the GitHub App. The GitHub App automatically uses your [config file](/docs/features/config_file/). -3. Remove the Infracost steps from your GitHub Actions completely. - -# GitHub Actions v1 to v2 migration - -Follow this section to migrate your [Infracost GitHub actions](https://github.com/infracost/actions) from v1 to v2. - -## What's new? - -The v1 actions used Infracost v0.9.x of the Infracost CLI, whereas the v2 actions use Infracost v0.10.x. With this new release, we'll support two ways to run Infracost with Terraform via `--path`: -1. **Parsing HCL code (recommended)**: this is the default and recommended option as it has [5 key benefits](/docs/guides/v0.10_migration/#1-faster-cli). This page describes how you can migrate to this option. - ```shell - # Terraform variables can be set using --terraform-var-file or --terraform-var - infracost breakdown --path /code - ``` - -2. **Parsing plan JSON file**: this will continue to work as before. There are [examples here](https://github.com/infracost/actions/tree/master/examples#plan-json-examples) of generating Terraform plan JSON files in GitHub Actions and passing them to Infracost. - ```shell - cd /code - terraform init - terraform plan -out tfplan.binary - terraform show -json tfplan.binary > plan.json - - infracost breakdown --path plan.json - ``` - -## Actions v2 migration guide - -Changing your workflow to work with the parse HCL option requires the following changes: - -1. Remove the Terraform and Terragrunt dependencies: - - Delete any `hashicorp/setup-terraform` or `autero1/action-terragrunt` steps as Infracost now parses the HCL code directly, so it does not depend on these. - - Delete any step that runs `terraform` or `terragrunt`, e.g. "terraform init", "terraform plan" and "terraform show" are no longer needed. - -2. Bump the version of the `infracost/actions/setup` action from `v1` to `v2`: - - ```yaml - - name: Setup Infracost - uses: infracost/actions/setup@v2 - with: - api-key: ${{ secrets.INFRACOST_API_KEY }} - ``` - -3. After the "Setup Infracost" step, add the following two steps for generating a cost estimate baseline from the main/master branch. - - ```yaml - - name: Checkout base branch - uses: actions/checkout@v2 - with: - ref: '${{ github.event.pull_request.base.ref }}' - - - name: Generate Infracost cost estimate baseline - run: | - infracost breakdown --path=PATH/TO/YOUR_TERRAFORM_CODE \ - --format=json \ - --out-file=/tmp/infracost-base.json - ``` - - :::note - You should replace any `--terraform-plan-flags` flags with either `--terraform-var` to add variables or `--terraform-var-file` to point to var files. These work similarly to Terraform's `-var` and `-var-file` flags and can be repeated. - ::: - - :::note - If you have variables stored on Terraform Cloud/Enterprise Infracost will pull these in automatically if you add the following environment variables to your job: - - ```yaml - jobs: - infracost: - # ... - env: - INFRACOST_TERRAFORM_CLOUD_TOKEN: ${{ secrets.TFC_TOKEN }} - # Change this if you're using Terraform Enterprise - INFRACOST_TERRAFORM_CLOUD_HOST: app.terraform.io - ``` - ::: - - :::note - If you have a Terraform mono-repo and you want to pass separate variables to each Terraform project you can create a [config file](/docs/features/config_file) and pass that with the `--config-file` flag as per [this example](https://github.com/infracost/actions/tree/master/examples/multi-project-config-file#readme) - ::: - -4. After the above, add the following two steps for comparing against the Infracost cost estimate baseline. If you added any required variable or config file flags in step 3, also add them to the `infracost diff` command below. - - ```yml - - name: Checkout PR branch - uses: actions/checkout@v2 - - - name: Run Infracost - run: | - infracost diff --path=PATH/TO/YOUR_TERRAFORM_CODE \ - --format=json \ - --compare-to=/tmp/infracost-base.json \ - --out-file=/tmp/infracost.json - - # Post pull request comment in the same way as before by running: - # infracost comment github --path=/tmp/infracost.json ... - ``` - -5. See [our full examples](https://github.com/infracost/actions/tree/master/examples) that use the new parsing HCL option. You can find one that is the closest to your use-case and adapt as required. diff --git a/docs/guides/atlantis_migration.md b/docs/guides/atlantis_migration.md deleted file mode 100644 index 5356c517..00000000 --- a/docs/guides/atlantis_migration.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -slug: atlantis_migration -title: Atlantis migration ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Follow this page to migrate your [Infracost Atlantis integration](https://github.com/infracost/infracost-atlantis). - -If you encounter any issues while migrating, please join our [community Slack channel](https://www.infracost.io/community-chat), we'll help you very quickly πŸ˜„ - -## What's new? - -With the v0.10 release, we'll support two ways to run Infracost with Terraform via `--path`: -1. **Parsing HCL code**: this is the default CLI option as it has [5 key benefits](/docs/guides/v0.10_migration/#1-faster-cli). - ```shell - # Terraform variables can be set using --terraform-var-file or --terraform-var - infracost breakdown --path /code - ``` - -2. **Parsing plan JSON file**: this will continue to work as before and is recommended for deployment systems such as Atlantis which are already generating a plan JSON. This page describes how you can migrate to this option. - -## Infracost Atlantis migration guide - -1. If you are using the `infracost-atlantis` Docker image update the tag to use v0.10 of Infracost. For examples if you were using `infracost/infracost-atlantis:atlantis0.19-infracost0.9` Docker image you should update to `infracost/infracost-atlantis:atlantis0.19-infracost0.10`. - - If you already use a custom Docker image for Atlantis, change the line that's installing Infracost to download from `https://infracost.io/downloads/v0.10/infracost-linux-amd64.tar.gz`. This downloads the latest 0.10.x version and lets you pick up bug fixes and new resource costs each time you build your image. You can also use lock the version using our [releases](https://github.com/infracost/infracost/releases). - -2. If you are calling Infracost with `--path=$PLANFILE` you should change this to `--plan=$SHOWFILE` to pass the plan JSON file instead of the plan binary file, since Infracost will be supporting that long term. This might require you to add a `show` step after the `plan` step of the workflow, e.g: - ```yaml - workflows: - terraform-infracost: - plan: - steps: - - init - - plan - - show # this writes the plan JSON to $SHOWFILE - ... - ``` - -3. You can see [our full examples](https://github.com/infracost/infracost-atlantis/tree/master/examples) and find one that is the closest to your use-case and adapt as required. diff --git a/docs/guides/azure_devops_migration.md b/docs/guides/azure_devops_migration.md deleted file mode 100644 index f53b2ffe..00000000 --- a/docs/guides/azure_devops_migration.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -slug: azure_devops_migration -title: Azure DevOps migration ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Follow this page to migrate your [Infracost Azure Pipelines integration](https://github.com/infracost/infracost-azure-devops) to use Infracost v0.10. - -If you encounter any issues while migrating, please join our [community Slack channel](https://www.infracost.io/community-chat), we'll help you very quickly πŸ˜„ - -## What's new? - -The InfracostSetup@0 task used Infracost v0.9.x of the Infracost CLI, whereas the InfracostSetup@1 task use Infracost v0.10.x. With this new release, we'll support two ways to run Infracost with Terraform via `--path`: -1. **Parsing HCL code (recommended)**: this is the default and recommended option as it has [5 key benefits](/docs/guides/v0.10_migration/#1-faster-cli). This page describes how you can migrate to this option. - ```shell - # Terraform variables can be set using --terraform-var-file or --terraform-var - infracost breakdown --path /code - ``` - -2. **Parsing plan JSON file**: this will continue to work as before. There are [examples here](https://github.com/infracost/infracost-azure-devops/tree/master/examples#plan-json-examples) of generating Terraform plan JSON files in Azure Pipelines and passing them to Infracost. - ```shell - cd /code - terraform init - terraform plan -out tfplan.binary - terraform show -json tfplan.binary > plan.json - - infracost breakdown --path plan.json - ``` - -## Infracost Azure Pipelines migration guide - -Changing your workflow to work with the parse HCL option requires the following changes: - -1. Remove the Terraform and Terragrunt dependencies: - - Delete any `TerraformInstaller` steps as Infracost now parses the HCL code directly, so it does not depend on these. - - Delete any stages and jobs that runs `terraform` or `terragrunt`, e.g. "terraform init", "terraform plan" and "terraform show" are no longer needed. - -2. Bump the version of the InfracostSetup task from `0` to `1`: - - ```yaml - - task: InfracostSetup@1 - displayName: Setup Infracost - inputs: - apiKey: $(infracostApiKey) - ``` - -3. After the "Setup Infracost" step, add the following two steps for generating a cost estimate baseline from the main/master branch. - - ```yaml - - bash: | - branch=$(System.PullRequest.TargetBranch) - branch=${branch#refs/heads/} - git clone $(Build.Repository.Uri) --branch=${branch} --single-branch /tmp/base - displayName: Checkout base branch - - - bash: | - infracost breakdown --path=$(TF_ROOT) \ - --format=json \ - --out-file=/tmp/infracost-base.json - displayName: Generate Infracost cost estimate baseline - ``` - - :::note - You should replace any `--terraform-plan-flags` flags with either `--terraform-var` to add variables or `--terraform-var-file` to point to var files. These work similarly to Terraform's `-var` and `-var-file` flags and can be repeated. - ::: - - :::note - If you have variables stored on Terraform Cloud/Enterprise Infracost will pull these in automatically if you add the following environment variables to your job: - - ```yaml - jobs: - - job: infracost - # ... - env: - INFRACOST_TERRAFORM_CLOUD_TOKEN: $(tfcToken) - # Change this if you're using Terraform Enterprise - INFRACOST_TERRAFORM_CLOUD_HOST: app.terraform.io - ``` - ::: - - :::note - If you have a Terraform mono-repo and you want to pass separate variables to each Terraform project you can create a [config file](/docs/features/config_file) and pass that with the `--config-file` flag as per [this example](https://github.com/infracost/infracost-azure-devops/tree/master/examples/multi-project-config-file#readme) - ::: - -4. After the above, add the following two steps for comparing against the Infracost cost estimate baseline. If you added any required variable or config file flags in step 3, also add them to the `infracost diff` command below. - - ```yml - - bash: | - infracost diff --path=$(TF_ROOT) \ - --format=json \ - --compare-to=/tmp/infracost-base.json \ - --out-file=/tmp/infracost.json - displayName: Generate Infracost diff - - # Posts a comment in the same way as before - - bash: | - infracost comment github --path=/tmp/infracost.json ... - displayName: Post Infracost comment - ``` - -5. See [our full examples](https://github.com/infracost/infracost-azure-devops/tree/master/examples) that use the new parsing HCL option. You can find one that is the closest to your use-case and adapt as required. diff --git a/docs/guides/gitlab_ci_migration.md b/docs/guides/gitlab_ci_migration.md deleted file mode 100644 index 0e626623..00000000 --- a/docs/guides/gitlab_ci_migration.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -slug: gitlab_ci_migration -title: GitLab CI migration ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Follow this page to migrate your [Infracost GitLab CI integration](https://gitlab.com/infracost/infracost-gitlab-ci) to use Infracost v0.10. - -If you encounter any issues while migrating, please join our [community Slack channel](https://www.infracost.io/community-chat), we'll help you very quickly πŸ˜„ - -## What's new? - -With the v0.10 release, we'll support two ways to run Infracost with Terraform via `--path`: -1. **Parsing HCL code (recommended)**: this is the default and recommended option as it has [5 key benefits](/docs/guides/v0.10_migration/#1-faster-cli). This page describes how you can migrate to this option. - ```shell - # Terraform variables can be set using --terraform-var-file or --terraform-var - infracost breakdown --path /code - ``` - -2. **Parsing plan JSON file**: this will continue to work as before. There are [examples here](https://gitlab.com/infracost/infracost-gitlab-ci/-/tree/master/examples#plan-json-exampless) of generating Terraform plan JSON files in GitLab CI and passing them to Infracost. - ```shell - cd /code - terraform init - terraform plan -out tfplan.binary - terraform show -json tfplan.binary > plan.json - - infracost breakdown --path plan.json - ``` - -## Infracost GitLab CI migration guide - -Changing your workflow to work with the parse HCL option requires the following changes: - -1. Remove the Terraform and Terragrunt dependencies: - - Delete any stages and jobs that runs `terraform` or `terragrunt`, e.g. "terraform init", "terraform plan" and "terraform show" are no longer needed. - -2. Bump the version of the Infracost Docker image from `infracost/infracost:ci-0.9` to `infracost/infracost:ci-0.10`: - - ```yaml - infracost: - stage: infracost - image: - name: infracost/infracost:ci-0.10 - entrypoint: [""] - ``` - -3. Update the `infracost` job's script to add the following two steps for generating a cost estimate baseline from the main/master branch. - - ```yaml - - git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base - - - | - infracost breakdown --path=/tmp/base/${TF_ROOT} \ - --format=json \ - --out-file=infracost-base.json - ``` - - :::note - You should replace any `--terraform-plan-flags` flags with either `--terraform-var` to add variables or `--terraform-var-file` to point to var files. These work similarly to Terraform's `-var` and `-var-file` flags and can be repeated. - ::: - - :::note - If you have variables stored on Terraform Cloud/Enterprise Infracost will pull these in automatically if you add the following environment variables to your job: - - ```yaml - infracost: - # ... - variables: - INFRACOST_TERRAFORM_CLOUD_TOKEN: $INFRACOST_TERRAFORM_CLOUD_TOKEN - # Change this if you're using Terraform Enterprise - INFRACOST_TERRAFORM_CLOUD_HOST: app.terraform.io - ``` - ::: - - :::note - If you have a Terraform mono-repo and you want to pass separate variables to each Terraform project you can create a [config file](/docs/features/config_file) and pass that with the `--config-file` flag as per [this example](https://gitlab.com/infracost/infracost-gitlab-ci/-/tree/master/examples/multi-project-config-file) - ::: - -4. After the above, add the following two steps for comparing against the Infracost cost estimate baseline. If you added any required variable or config file flags in step 3, also add them to the `infracost diff` command below. - - ```yml - - | - infracost diff --path=${TF_ROOT} \ - --compare-to=infracost-base.json \ - --format=json \ - --out-file=infracost.json - - # Posts a comment in the same way as before - - | - infracost comment gitlab --path=infracost.json ... - ``` - -5. See [our full examples](https://gitlab.com/infracost/infracost-gitlab-ci/-/tree/master/examples) that use the new parsing HCL option. You can find one that is the closest to your use-case and adapt as required. diff --git a/docs/guides/source_control_benefits.md b/docs/guides/source_control_benefits.md deleted file mode 100644 index 74a50506..00000000 --- a/docs/guides/source_control_benefits.md +++ /dev/null @@ -1,142 +0,0 @@ ---- -slug: source_control_benefits -title: Source control integration benefits ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Source control integrations ([GitHub App](/docs/integrations/github_app/) or [GitLab App](/docs/integrations/gitlab_app/)) have three key benefits over [CI/CD integrations](/docs/integrations/cicd/#cicd-integration): - -1. You can quickly add Infracost to multiple repos with one click, no need to install or update CLI versions in your CI/CD pipeline. Infracost runs on our infrastructure and we keep it up to date. - -2. Infracost runs significantly faster as only changed folders are run based on the GitHub/GitLab App events. - -3. If you use Infracost Cloud (our SaaS product), all features work without you needing to make any changes to your CI/CD pipelines. If you use CI/CD integrations, you should implement the following extra steps. - -## Extra steps needed for CI/CD integrations and Infracost Cloud - -### 1. Required CLI version - -Currently, version 0.10.30+ of the Infracost CLI is needed for the Infracost Cloud features to work correctly. We recommend you upgrade the CLI every one to two months to pickup latest features and bug fixes. - -### 2. Branch costs, FinOps and tagging policy failures - -To show costs, FinOps and tagging policy failures on default (e.g. master or main) or other base branches: - - In your CI/CD integration, on each default or base branch push, you should run these steps to run Infracost breakdown and upload the results. If you do not need a [config file](/docs/features/config_file/), you can use `infracost breakdown --path=.` and point it to your repo root or Terraform directory. - ```sh - infracost breakdown --config-file=infracost.yaml \ - --format=json --out-file=/tmp/infracost.json - - infracost upload --path=/tmp/infracost.json - ``` - -### 3. FinOps and tagging policies - -To make the [FinOps policies](/docs/infracost_cloud/finops_policies/) and [Tagging policies](/docs/infracost_cloud/tagging_policies/) "blocking/unblocking pull requests" feature work: - - In your CI/CD integration, you should check the exit code of the `infracost comment` command (or `infracost upload` if you don't use `comment`), and fail the build if it returns an exit code of `1`. That indicates that FinOps or tagging policies failed. Once the engineer fixes the issue, the CLI returns exit code `0` (meaning success). - -### 4. Guardrails - -To make the [Guardrails](/docs/infracost_cloud/guardrails/) blocking/unblocking pull requests feature work: - - In your CI/CD integration, you should check the exit code of the `infracost comment` command (or `infracost upload` if you don't use `comment`), and fail the build if it returns an exit code of `1`. That indicates that Guardrails failed. - - When a pull request is reviewed and unblocked in Infracost Cloud, the engineer needs to re-run the Infracost CLI (or pipeline). This is so it can pick up the unblocked status from Infracost Cloud and return an exit code of `0` (meaning success). - -### 5. Pull request status - -To set the pull request status (e.g. open, closed, merged), use the following API call. This will enable you to see the pull request status in Infracost Cloud and use them in dashboard filters or reports. - -```shell -curl -X POST -H "Content-Type: application/json" \ --H "X-API-Key: $INFRACOST_API_KEY" \ --d '{ "query": "mutation { updatePullRequestStatus(url: \"https://github.com/YOUR_ORG/YOUR_REPO/pull/323\", status: MERGED) }" }' \ -https://dashboard.api.infracost.io/graphql -``` - -The pull request status can be one of three: - - `OPEN`: the pull request is currently open, thus if you want to review the most expensive pull requests that are in-flight, only focus on these. - - `CLOSED`: the pull request was closed without being merged. These pull requests can probably be ignored altogether as most of the time they're just noise. - - `MERGED`: the pull request was merged into the base branch, these can be checked when auditing actual cloud costs to see what happened. - -
Example GitLab CI code to set status to Merged - - ```yaml - stages: - - infracost # the main infracost stage from https://gitlab.com/infracost/infracost-gitlab-ci - - infracost:update-mr-status # new stage below to update the merge request status - - # Set the MR status to Merged in Infracost Cloud - infracost:update-mr-status: - image: bash:latest - before_script: - - apk add curl --upgrade - # Extract Merge Request ID from the Commit Message - - if [[ ${CI_COMMIT_MESSAGE} =~ ${PATTERN} ]]; - then MR_ID=${BASH_REMATCH[1]}; - else echo "${VTY_RB}Unable to extract Merge Request ID${VTY_P}"; exit 1; - fi; - script: - - | - curl \ - --request POST \ - --header "Content-Type: application/json" \ - --header "X-API-Key: ${INFRACOST_API_KEY}" \ - --data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"${CI_PROJECT_URL}/merge_requests/${MR_ID}\\\", status: MERGED )}\" }" \ - "https://dashboard.api.infracost.io/graphql"; - variables: - PATTERN: "See merge request.+?!([0-9]+)" - INFRACOST_API_KEY: $INFRACOST_API_KEY - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_TITLE =~ /^Merge branch/ - ``` -
- -
Example Azure Pipelines code to set status to Merged - - ```yaml - trigger: - - main - - pool: - vmImage: ubuntu-latest - - steps: - - bash: | - PATTERN="Merged PR ([0-9]+):" - if [[ "$(Build.SourceVersionMessage)" =~ $PATTERN ]]; then - PR_ID=${BASH_REMATCH[1]} - echo "Updating status of $PR_ID" - curl \ - --request POST \ - --header "Content-Type: application/json" \ - --header "X-API-Key: $(infracostApiKey)" \ - --data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"$(Build.Repository.Uri)/pullrequest/${PR_ID}\\\", status: MERGED )}\" }" \ - "https://dashboard.api.infracost.io/graphql"; - else - echo "No Pull Request ID detected" - fi - displayName: 'Update PR status in Infracost' - - ``` -
- -
Example Bitbucket Pipeline code to set status to Merged - - ```yaml - pipelines: - branches: - main: - - step: - name: Update PR status in Infracost - image: bash:latest - script: - - PR_NUMBER=$(git show $BITBUCKET_COMMIT | grep -o 'pull request \#[0-9]\+' | grep -o '[0-9]\+') && echo $PR_NUMBER - - apk update && apk add curl - - | - curl -X POST -H "Content-Type: application/json" \ - -H "X-API-Key: ${INFRACOST_API_KEY}" \ - -d "{ \"query\": \"mutation { updatePullRequestStatus(url: \\\"${BITBUCKET_GIT_HTTP_ORIGIN}/pull-requests/${PR_NUMBER}\\\", status: MERGED) }\" }" \ - https://dashboard.api.infracost.io/graphql - - echo "Done" - ``` - -
diff --git a/docs/guides/uninstall.md b/docs/guides/uninstall.md deleted file mode 100644 index 4fff9cd3..00000000 --- a/docs/guides/uninstall.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -slug: uninstall -title: Uninstall Infracost ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -To uninstall Infracost: - - - - - ```shell - brew uninstall infracost - ``` - - - - - ```shell - rm -rf /usr/local/bin/infracost - ``` - - - - - ```shell - choco uninstall infracost - ``` - - - diff --git a/docs/guides/v0.10_migration.md b/docs/guides/v0.10_migration.md deleted file mode 100644 index 5b3260f9..00000000 --- a/docs/guides/v0.10_migration.md +++ /dev/null @@ -1,179 +0,0 @@ ---- -slug: v0.10_migration -title: v0.10 migration guide ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Once you've [installed Infracost v0.10](/docs/#1-install-infracost), follow this page to migrate. If you run into any issues, please join our [community Slack channel](https://www.infracost.io/community-chat) or [create an issue](https://github.com/infracost/infracost/issues/new), we'll help you very quickly πŸ˜„ - -## What's new? - -Back in February, we started an ambitious journey: remove our dependency on the Terraform CLI by parsing code directly! Infracost v0.10 completes that journey πŸŽ‰ - -Infracost is now much faster, simpler to add to CI/CD, and does not need cloud creds since a plan is not required. - -The experimental `--terraform-parse-hcl` flag has been removed and going forward, Infracost can be run in two ways via `--path`: - -1. **Parsing HCL code (directory)**: the default and recommended option as it has the following 5 key benefits. - ```shell - # Terraform variables can be set using --terraform-var-file or --terraform-var - infracost breakdown --path /code - ``` -2. **Parsing plan JSON file**: this will continue to work as before. - ```shell - cd /code - terraform init - terraform plan -out tfplan.binary - terraform show -json tfplan.binary > plan.json - - infracost breakdown --path plan.json - ``` - -### 1. Faster CLI - -Infracost can now generate cost estimates *without* needing a Terraform plan. This removes our dependency on the Terraform CLI altogether, which means no more `terraform init` and `terraform plan`. - -That, in turn, means a super-fast CLI: Infracost used to take around 50 seconds to run on our internal Terraform mono-repo, that's now reduced to 2 seconds. πŸš€ - -### 2. No cloud creds needed - -Removing our dependency on the Terraform CLI means you no longer need to set cloud credentials or Terraform secrets, which simplifies CI/CD integrations too. - -### 3. Cost of TF modules - -Not needing cloud creds/secrets or a Terraform plan means you can now generate cost estimates from [Terraform modules](/docs/features/terraform_modules/). It also enables cost estimates to be put in Infra-as-Code [repo readmes](https://github.com/infracost/infracost/issues/43) and [Visual Studio](https://github.com/infracost/infracost/issues/1546)! - -To make `infracost diff` work without a plan, we introduced a new `--compare-to` flag so git-based cost diffs can be produced: -```shell -git checkout main -infracost breakdown --path /code --format json --out-file infracost-base.json - -git checkout my-branch -infracost diff --path /code --compare-to infracost-base.json -``` - -### 4. Compare Infracost runs - -The `infracost diff` command can now also be used to compare Infracost runs to see what's changed between historic runs: - -```shell -infracost diff --path infracost-today.json --compare-to infracost-last-week.json -``` - -### 5. Detect multi-project repos - -Setting the `--path` flag to a top-level repo directory will now attempt to process all projects automatically by: -1. Looking at the specified path or in any of the subdirectories with a depth less than 5. -2. Processing Terraform variable files with the `.auto.tfvars` extension (similar to what Terraform does). -3. Processing environment variables with a `TF_VAR_` prefix (similar to what Terraform does). - -If this does not work for your use-case, use a [config-file](/docs/features/config_file/) and run `infracost breakdown --config-file=infracost.yml`, for example: -```yaml -# infracost.yml -version: 0.1 -projects: - - path: prod - terraform_var_files: - - prod.tfvars - - us-east.tfvars - - - path: dev - terraform_var_files: - - dev.tfvars -``` - -## Removed functionality - -If you previously used the following two options to see the cost breakdown of the current Terraform state, you can now just run `infracost breakdown --path /code` against the already-deployed branch. -1. The `--terraform-use-state` flag has been removed. -2. Running Infracost against a Terraform state JSON file is no longer supported. - -If you previously ran Infracost with a Terraform plan binary file, you should now generate a plan JSON file and use that instead: -```shell -terraform plan -out tfplan.binary -terraform show -json tfplan.binary > plan.json - -infracost breakdown --path plan.json -``` - -If you previously used the `INFRACOST_TERRAGRUNT_FLAGS` environment variable, you can now use `--exclude-path` with `breakdown` and `diff`: -```shell -infracost breakdown --path=. --exclude-path=dev --exclude-path=test -``` - -## Known issues - -There are [known issues](/docs/features/terragrunt/#known-issues) with Terragrunt, and some Terraform users. However, there are [workarounds](/docs/features/terragrunt/#known-issues) you can use to unblock yourself and continue to upgrade to v0.10. - -## Migrations guides - -1. [**GitHub Actions**](/docs/guides/actions_migration/) -2. [**GitLab CI**](/docs/guides/gitlab_ci_migration/) -3. [**Azure DevOps**](/docs/guides/azure_devops_migration/) -4. [**Atlantis**](/docs/guides/atlantis_migration/) - -We've also updated our [Jenkins](https://github.com/infracost/infracost-jenkins/), [Bitbucket](https://bitbucket.org/infracost/infracost-bitbucket-pipeline) and [CircleCI](https://github.com/infracost/infracost-circleci/) examples. - -
-Generic migration guide (if you can't use the above guides) - -#### Option 1: Terraform directory (recommended) - -Parsing HCL has no concept of Terraform state. This makes it super-fast, but this means you'll need to compare Infracost runs to show cost differences. - -For example, the following v0.9 commands: - -```shell -cd /code - -# Checkout your feature branch -git checkout my-branch - -# Generate Infracost JSON file, this internally invoked the -# Terraform CLI to create a plan JSON that was used by Infracost. -infracost breakdown --path . \ - --format json --out-file infracost.json - -infracost comment github --path infracost.json ... -``` - -Needs to be rewritten as such in v0.10: - -```shell -cd /code - -# Generate Infracost JSON file as the baseline. -# Terraform variables can be set using --terraform-var-file or --terraform-var -git checkout main - -infracost breakdown --path . \ - --format json --out-file infracost-base.json - -# Generate a diff by comparing the latest code change with the baseline -git checkout my-branch - -infracost diff --path . \ - --compare-to infracost-base.json \ - --format json --out-file infracost.json - -infracost comment github --path infracost.json ... -``` - -#### Option 2: Terraform plan JSON - -If you already use Infracost with a Terraform plan JSON, you don't need to change anything as that will continue to work (since the Infracost `--path` flag detects a Terraform plan JSON). - -If you were used to running Infracost against a Terraform project directory, and want the old behavior where Infracost invoked the Terraform CLI, you can manually generate a plan JSON and use that instead: -```shell -cd /code -terraform init -terraform plan -out tfplan.binary -terraform show -json tfplan.binary > plan.json - -infracost breakdown --path plan.json \ - --format json --out-file infracost.json - -infracost comment github --path infracost.json ... -``` -
diff --git a/docs/guides/v0.8_migration.md b/docs/guides/v0.8_migration.md deleted file mode 100644 index 32e91816..00000000 --- a/docs/guides/v0.8_migration.md +++ /dev/null @@ -1,161 +0,0 @@ ---- -slug: v0.8_migration -title: v0.8 migration guide ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Once you've [installed Infracost v0.8](/docs/#1-install-infracost), follow this page to migrate to use the new features. Whilst we tried hard not to break old functionality by adding deprecation warnings, there is the risk of breakage as these improvements required significant code changes. Please report any [issues](https://github.com/infracost/infracost/issues/new) and we'll address them as soon as possible. - -## What's new? - -πŸš€ Infracost `v0.8.0` included major improvements to the CLI: - -### New diff command - -A new `infracost diff` command has been added to show a diff of monthly costs between the current and planned state. This was requested by many users as we already provided similar functionality in our CI/CD integrations, but it wasn't available in the CLI, and the CI output could be confusing. We've addressed both issues by adding this new command. - -Infracost diff command - -### Simplified table output - -The dashes (-) have been replaced with price descriptions such as `Cost depends on usage: $0.20 per 1M requests` so you can understand the pricing structure of [usage-based resources](/docs/features/usage_based_resources) such as AWS Lambda or Google Cloud Storage. - -Infracost breakdown command - -### Simplified inputs - -A new `path` flag has been introduced to replace the various methods of running Infracost. You can now simply point Infracost to the path of a Terraform directory, plan binary file, or plan JSON file and it'll just work. This lays some of the groundwork for supporting other IaC tools in the future πŸ˜‰ - -### Simplified config file - -The config file has been updated to support infra-as-code repos that have multiple workspaces and projects. This command combines the projects into the same breakdown or diff output. So if a Terraform module or variable is used across workspaces/projects, you can quickly see the cost impact of changing it. - -## Migration guide - -### Commands - -#### Root command - -The root `infracost` command has been deprecated as we've moved to using subcommands: -- `infracost breakdown`: this works similarly to the previous `infracost` root command and shows a table breakdown of all resources by default. Run `infracost breakdown --help` to see the other options. -- `infracost diff`: this shows a list of the resources along with costs that will change when the Terraform plan is applied. - -The old root command will be fully removed in v0.9.0. - -#### Report command - -The `infracost report` command has been deprecated and replaced with `infracost output`. - -This takes Infracost JSON files as inputs via `--path` and allows them to be combined and outputted in any format using `--format json|diff|table|html`. This command can be used with wildcards too, e.g. `infracost output --format html --path "infracost*.json" > output.html`. - -### Flags - -The following flags have all been deprecated and replaced with `--path`: - -- `--terraform-dir` / `--tfdir` -- `--terraform-json-file` / `--tfjson` -- `--terraform-plan-file` / `--tfplan` - -The `--output`/ `-o` flag has been replaced with `--format`. - -### Environment variables - -The following environment variables have been deprecated: - -- `TERRAFORM_BINARY`: replaced with `INFRACOST_TERRAFORM_BINARY` -- `TERRAFORM_CLOUD_HOST`: replaced with `INFRACOST_TERRAFORM_CLOUD_HOST` -- `TERRAFORM_CLOUD_TOKEN`: replaced with `INFRACOST_TERRAFORM_CLOUD_TOKEN` -- `SKIP_UPDATE_CHECK`: replaced with `INFRACOST_SKIP_UPDATE_CHECK` - -### Config file - -The format of the config file has been simplified and a new version parameter has been introduced to enable safer iterations in the future. Initially the config file can be used for supporting repos that have multiple workspaces or projects. See the [config file](/docs/features/config_file) docs for details. - -```yaml -version: 0.1 -projects: - - path: path/to/my_terraform - terraform_workspace: dev - - - path: path/to/my_terraform - terraform_workspace: prod -``` - -The following top-level keys in the old config format have been removed: `log_level`, `no_color` `outputs`. These can be set using flags (`--log-level`, `--no-color` and `--format / --show-skipped`). If you were using multiple outputs you can use the `infracost output` command to perform the same functionality, e.g.: - -```shell -infracost breakdown --path=path/to/code --format=json > infracost_breakdown.json -infracost output --path=infracost_breakdown.json --format=table -infracost output --path=infracost_breakdown.json --format=diff -``` - -In the future we may add these keys back into the config format, but need to better handle edge cases when these are used in combination with flags and environment variables. - -### JSON output - -The JSON output from `infracost breakdown --format json` has been changed to the following format: - -```json -{ - "version": "0.1", - "projects": [ - { - "path": "path/to/code", - "metadata": { - "terraformWorkspace": "stage", - }, - "pastBreakdown": { - "resources": [...] - "totalMonthlyCost": "730", - "totalHourlyCost": "1" - }, - "breakdown": { - "resources": [...] - "totalMonthlyCost": "1460", - "totalHourlyCost": "1" - }, - "diff": { - "resources": [...] - "totalMonthlyCost": "730", - "totalHourlyCost": "1" - } - } - ], - "summary": { - "unsupportedResourceCounts": {...} - }, -} -``` - -The following top-level keys in the old JSON format are deprecated and will be removed in v0.9.0: `resources`, `totalMonthlyCost`, `totalHourlyCost`. The `resourceSummary > unsupportedCounts` key has been renamed to `summary > unsupportedResourceCounts`. - -### CI/CD integrations - -Follow the relevant sections below to upgrade your CI/CD integration. - -#### GitHub Actions - -Switch your GitHub Action config to use our v0.6.0 GitHub Action. This supports the new `path` or `config` parameters as mentioned above and in the [GitHub Actions readme](https://github.com/infracost/infracost-gh-action). - -The GitHub Action outputs `default_branch_monthly_cost` and `current_branch_monthly_cost` have been removed, and replaced with `past_total_monthly_cost` and `total_monthly_cost`. - -#### GitLab CI - -Switch your GitLab CI config to use the latest version of [our template](https://gitlab.com/infracost/infracost-gitlab-ci/-/blob/master/infracost.yml). This supports the new `path` or `config` parameters as mentioned above and in the [GitLab CI readme](https://gitlab.com/infracost/infracost-gitlab-ci). - -#### CircleCI - -Switch your CircleCI Orb to use our v0.6.0 Orb. This supports the new `path` or `config` parameters as mentioned above and in the [Orb readme](https://gitlab.com/infracost/infracost-orb). - -#### Bitbucket Pipelines - -Update your Bitbucket pipeline config to use the example in the latest [Pipeline readme](https://bitbucket.org/infracost/infracost-bitbucket-pipeline/src/master/). This supports the new `path` or `config` parameters as mentioned above. - -#### Atlantis - -Both Atlantis integration methods now run `infracost diff` using the `$PLANFILE` that Atlantis generates. - -If you used the Docker image before, please update to the latest [infracost-atlantis Docker image](https://hub.docker.com/repository/docker/infracost/infracost-atlantis/), or build your own image using the instructions mentioned [here](https://github.com/infracost/infracost-atlantis#1-docker-image). The `terraform_plan_flags` environment variable is no longer needed, so remove that from your Atlantis config. - -If you used the Infracost API, no changes are needed as the API has been updated to return a diff. diff --git a/docs/guides/v0.9_migration.md b/docs/guides/v0.9_migration.md deleted file mode 100644 index ffef0ecb..00000000 --- a/docs/guides/v0.9_migration.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -slug: v0.9_migration -title: v0.9 migration guide ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -Once you've [installed Infracost v0.9](/docs/#1-install-infracost), follow this page to migrate. If you encounter any issues while migrating, [please report them](https://github.com/infracost/infracost/issues/new) and we'll address them as soon as possible. - -## What's new? - -πŸš€ We added support for Microsoft Azure! We also updated our JSON output format in Infracost `v0.9.0`. Finally, we removed commands, flags and environment variables that were marked as deprecated in `v0.8.0`. - -## Migration guide - -### JSON output - -The JSON output from `infracost breakdown --path=path/to/code --format json` has been changed to the following format: - -* `version` has been bumped from `v0.1` to `v0.2`. -* `projects[*].path` has moved to `projects[*].metadata.path` and a new `projects[*].name` key has been introduced. This name is autogenerated from your code repository URL or the path you pass to Infracost. This enables you to see details of the project that was used to generate the cost estimate. -* The deprecated top-level `resources` key has been removed as they are now scoped by project. - -```json -{ - "version": "0.2", - "timeGenerated": "2021-05-31T18:02:49.412164+01:00", - "projects": [ - { - "name": "org/repo/subpath (stage)", - "metadata": { - "path": "path/to/code", - "terraformWorkspace": "stage", - }, - "pastBreakdown": { - "resources": [...], - "totalMonthlyCost": "730", - "totalHourlyCost": "1" - }, - "breakdown": { - "resources": [...], - "totalMonthlyCost": "1460", - "totalHourlyCost": "1" - }, - "diff": { - "resources": [...], - "totalMonthlyCost": "730", - "totalHourlyCost": "1" - } - } - ], - "totalMonthlyCost": "2920", - "totalHourlyCost": "4", - "summary": { - "unsupportedResourceCounts": {...} - }, -} -``` - -### Deprecated functionality that has now been removed - -#### Root command - -The deprecated root `infracost` command has been removed as we've moved to using subcommands: -- `infracost breakdown`: this works similarly to the previous `infracost` root command and shows a table breakdown of all resources by default. Run `infracost breakdown --help` to see the other options. -- `infracost diff`: this shows a list of the resources along with costs that will change when the Terraform plan is applied. - -#### Report command - -The deprecated `infracost report` command has been removed and replaced with `infracost output`. - -This takes Infracost JSON files as inputs via `--path` and allows them to be combined and outputted in any format using `--format json|diff|table|html`. This command can be used with wildcards too, e.g. `infracost output --format html --path "infracost*.json" > output.html`. Run `infracost output --help` to see the other options. - -#### Flags - -The following deprecated flags have all been removed and replaced with `--path`: - -- `--terraform-dir` / `--tfdir` -- `--terraform-json-file` / `--tfjson` -- `--terraform-plan-file` / `--tfplan` - -The `--output`/ `-o` flag has been replaced with `--format`. - -#### Environment variables - -The following deprecated environment variables have been removed: - -- `TERRAFORM_BINARY`: replaced with `INFRACOST_TERRAFORM_BINARY` -- `TERRAFORM_CLOUD_HOST`: replaced with `INFRACOST_TERRAFORM_CLOUD_HOST` -- `TERRAFORM_CLOUD_TOKEN`: replaced with `INFRACOST_TERRAFORM_CLOUD_TOKEN` -- `SKIP_UPDATE_CHECK`: replaced with `INFRACOST_SKIP_UPDATE_CHECK` - - -### CI/CD integrations - -No changes are required for any CI/CD integrations. diff --git a/docs/infracost_cloud/finops_policies.md b/docs/infracost_cloud/finops_policies.md index a79fef71..1bbdbe39 100644 --- a/docs/infracost_cloud/finops_policies.md +++ b/docs/infracost_cloud/finops_policies.md @@ -35,10 +35,6 @@ When engineers create a pull request to change infrastructure, Infracost scans t The pull request comment shows exactly what file and line number need to be updated to fix the issue. -:::note -If you do not use source control integrations ([GitHub App](/docs/integrations/github_app/) or [GitLab App](/docs/integrations/gitlab_app/)), you must [implement some extra steps](/docs/guides/source_control_benefits/) for CI/CD integrations to work with tagging policies. Tagging policies do not currently work with the [Terraform Plan JSON](/docs/features/cli_commands/#option-2-terraform-plan-json) method; [contact us](mailto:hello@infracost.io) for assistance. -::: - ## 4. Update policy settings From the Governance > FinOps page, you can click on the details of any policy and update its settings. These settings include the option to block requests that fail the policy, and the ability to customize the message shown to engineers in pull requests. This is useful if you need to customize the message to recommend your company's specific policy or a link to internal wiki pages where engineers can learn more. diff --git a/docs/infracost_cloud/get_started.md b/docs/infracost_cloud/get_started.md index 915cb966..51ae5dce 100644 --- a/docs/infracost_cloud/get_started.md +++ b/docs/infracost_cloud/get_started.md @@ -31,26 +31,36 @@ In your code repo, create a new branch. In the test branch, add a new file calle ```hcl provider "aws" { - region = "us-east-1" + region = "us-east-1" + skip_credentials_validation = true + skip_requesting_account_id = true + access_key = "mock_access_key" + secret_key = "mock_secret_key" } resource "aws_instance" "my_web_app" { - instance_type = "m3.xlarge" # <<<<< Try changing this to m5.xlarge to compare the costs + ami = "ami-005e54dee72cc1d00" + + instance_type = "m3.xlarge" # <<<<<<<<<< Try changing this to m5.xlarge to compare the costs tags = { Environment = "production" - Service = "web-app" + Service = "web-app" } root_block_device { - volume_size = 1000 # <<<<< Try adding volume_type="gp3" to compare costs + volume_size = 1000 # <<<<<<<<<< Try adding volume_type="gp3" to compare costs } } resource "aws_lambda_function" "my_hello_world" { - runtime = "nodejs12.x" - memory_size = 512 + runtime = "nodejs12.x" + handler = "exports.test" + image_uri = "test" + function_name = "test" + role = "arn:aws:ec2:us-east-1:123123123123:instance/i-1231231231" + memory_size = 512 tags = { Environment = "Prod" } @@ -67,41 +77,64 @@ In the above example, the Infracost pull request comment points out that: ```hcl provider "azurerm" { + skip_provider_registration = true + features {} } resource "azurerm_linux_virtual_machine" "my_linux_vm" { - location = "eastus" + location = "eastus" + name = "test" + resource_group_name = "test" + admin_username = "testuser" + admin_password = "Testpa5s" - size = "Standard_F16s" # <<<<< Try changing this to Standard_F16s_v2 to compare the costs + size = "Standard_F16s" # <<<<<<<<<< Try changing this to Standard_F16s_v2 to compare the costs tags = { Environment = "production" - Service = "web-app" + Service = "web-app" } os_disk { - caching = "ReadWrite" + caching = "ReadWrite" storage_account_type = "Standard_LRS" } -} -resource "azurerm_app_service_plan" "my_app_service" { - location = "eastus" + network_interface_ids = [ + "/subscriptions/123/resourceGroups/testrg/providers/Microsoft.Network/networkInterfaces/testnic", + ] - sku { - tier = "PremiumV2" - size = "P1v2" - capacity = 4 # <<<<< Try changing this to 8 to compare the costs + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" } +} + +resource "azurerm_service_plan" "my_app_service" { + location = "eastus" + name = "test" + resource_group_name = "test_resource_group" + os_type = "Windows" + + sku_name = "P1v2" + worker_count = 4 # <<<<<<<<<< Try changing this to 8 to compare the costs tags = { Environment = "Prod" - Service = "web-app" + Service = "web-app" } } -resource "azurerm_function_app" "my_function" { +resource "azurerm_linux_function_app" "my_function" { location = "eastus" + name = "test" + resource_group_name = "test" + service_plan_id = "/subscriptions/123/resourceGroups/testrg/providers/Microsoft.Web/serverFarms/serverFarmValue" + storage_account_name = "test" + storage_account_access_key = "test" + site_config {} tags = { Environment = "Prod" @@ -111,7 +144,7 @@ resource "azurerm_function_app" "my_function" { In the above example, the Infracost pull request comment points out that: 1. The `Standard_F16s` instance type is previous generation and should be upgraded to `Standard_F16s_v2`, since that gives you a more performant machine at a lower cost. -2. The `PremiumV2` App Service plan should be upgraded to a v3 plan, such as `P0v3` (with `tier=PremiumV3`), since that gives you more performance and is eligible for savings plans and reserved instance pricing, opening opportunities for major savings. +2. The App Service plan SKU name should be upgraded to a v3 plan, such as `P0v3`, since that gives you more performance and is eligible for savings plans and reserved instance pricing, opening opportunities for major savings. @@ -119,35 +152,48 @@ In the above example, the Infracost pull request comment points out that: ```hcl provider "google" { - region = "us-central1" + region = "us-central1" + project = "test" } resource "google_compute_instance" "my_instance" { - zone = "us-central1-a" + zone = "us-central1-a" + name = "test" + + machine_type = "n1-standard-16" # <<<<<<<<<< Try changing this to n1-standard-32 to compare the costs + network_interface { + network = "default" + access_config {} + } - machine_type = "n1-standard-16" # <<<<< Try changing this to n1-standard-32 to compare the costs + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } scheduling { preemptible = true } guest_accelerator { - type = "nvidia-tesla-t4" # <<<<< Try changing this to nvidia-tesla-p4 to compare the costs + type = "nvidia-tesla-t4" # <<<<<<<<<< Try changing this to nvidia-tesla-p4 to compare the costs count = 4 } labels = { - Environment = "production" - Service = "web-app" + environment = "production" + service = "web-app" } } resource "google_cloudfunctions_function" "my_function" { - runtime = "nodejs10" + runtime = "nodejs20" + name = "test" available_memory_mb = 512 labels = { - Environment = "Prod" + environment = "Prod" } } ``` diff --git a/docs/infracost_cloud/guardrails.md b/docs/infracost_cloud/guardrails.md index 6049570e..6d882867 100644 --- a/docs/infracost_cloud/guardrails.md +++ b/docs/infracost_cloud/guardrails.md @@ -23,10 +23,6 @@ You can create multiple guardrails, for example one with a lower threshold that To create a guardrail, log in to [Infracost Cloud](https://dashboard.infracost.io) and go to the Governance > Guardrails page. -:::note -If you do not use source control integrations ([GitHub App](/docs/integrations/github_app/) or [GitLab App](/docs/integrations/gitlab_app/)), you must [implement some extra steps](/docs/guides/source_control_benefits/) for CI/CD integrations to work with guardrails. -::: - ### 1. Scope of guardrail Give your guardrail a name, and select the whether the guardrail should be evaluated against the pull request cost as a whole, or against projects individually. diff --git a/docs/infracost_cloud/tagging_policies.md b/docs/infracost_cloud/tagging_policies.md index 01806ca2..80c90b1c 100644 --- a/docs/infracost_cloud/tagging_policies.md +++ b/docs/infracost_cloud/tagging_policies.md @@ -69,10 +69,6 @@ When engineers create a pull request to change infrastructure, Infracost scans t Create a pull request to test your tagging policy. -:::note -If you do not use source control integrations ([GitHub App](/docs/integrations/github_app/) or [GitLab App](/docs/integrations/gitlab_app/)), you must [implement some extra steps](/docs/guides/source_control_benefits/) for CI/CD integrations to work with tagging policies. Tagging policies do not currently work with the [Terraform Plan JSON](/docs/features/cli_commands/#option-2-terraform-plan-json) method; [contact us](mailto:hello@infracost.io) for assistance. -::: - ## How tagging policies work Tagging policies check all AWS, Azure and Google Terraform resources that support tagging, including resources that Infracost does not show cost estimates for yet. The following list describes things that are checked by tagging policies: diff --git a/docs/integrations/atlantis.md b/docs/integrations/atlantis.md deleted file mode 100644 index d8c2e73f..00000000 --- a/docs/integrations/atlantis.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -slug: atlantis -title: Atlantis ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; - -See the [Infracost Atlantis integration](https://github.com/infracost/infracost-atlantis/) for instructions and a demo. - -If you used the old [infracost_atlantis_diff.sh](https://github.com/infracost/infracost-atlantis/blob/c510d9d8c3f8d226be1d0882d95f3f477b3fe058/README.md) bash script, please see our [migration guide](guides/atlantis_migration.md). - -Cost estimate comment for Atlantis diff --git a/docs/integrations/azure_pipelines.md b/docs/integrations/azure_pipelines.md deleted file mode 100644 index ca8c7fab..00000000 --- a/docs/integrations/azure_pipelines.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -slug: azure_pipelines -title: Azure Pipelines ---- - -See the [Infracost Azure Pipeline integration](https://marketplace.visualstudio.com/items?itemName=Infracost.infracost-tasks) in the Azure DevOps Marketplace for instructions and a demo. - -If you used the old [pipeline bash scripts](https://github.com/infracost/infracost-azure-devops/blob/0c662db3982f53666e89e69a406c572f48dc5c33/README.md), please see our [migration guide](guides/azure_devops_migration.md). - -Example Infracost diff output diff --git a/docs/integrations/cicd.mdx b/docs/integrations/cicd.mdx index 7c42b0ff..fd2e2603 100644 --- a/docs/integrations/cicd.mdx +++ b/docs/integrations/cicd.mdx @@ -37,7 +37,7 @@ export const CIBox = ({image, link, maxHeight, newWindow, text}) => ( ) -Use one of our many integrations so your engineering team can see cost estimates and FinOps best practices in pull requests **before making changes**. This provides your team with a safety net as people can discuss costs as part of the workflow. +Use one of our many integrations so your engineering team can see cost estimates and FinOps best practices in pull requests **before making changes**. This provides your team with a safety net as people can discuss FinOps as part of the workflow. Infracost pull request comment @@ -45,8 +45,8 @@ If you run into any issues, please join our [community Slack channel](https://ww ## Source control integrations (recommended) -Infracost supports direct integration with GitHub and GitLab. -We recommend these integrations as they are much simpler to setup, and faster to run. [This page](/docs/guides/source_control_benefits/) explains more about the benefits of source control integrations over CI/CD integrations. +Infracost supports direct integration with GitHub and GitLab. We recommend these integrations as they are much simpler to setup and faster to run. + -## Third-party integrations +
-Infracost can also be used alongside many other [third-party systems](/docs/integrations/third_party_integrations/) including Terraform Cloud/Enterprise, Env0, Scalr and Spacelift. Note that these integrations are very minimal, do not post pull request comments or work with other Infracost Cloud features such as [FinOps policies](/docs/infracost_cloud/finops_policies/), [Tagging policies](/docs/infracost_cloud/tagging_policies/), or [Guardrails](/docs/infracost_cloud/guardrails/). +For other CI/CD systems, the GitLab CI integration above is a good example to follow. Please [email us](mailto:hello@infracost.io) if you need help. We main the [`infracost/infracost:ci-0.10`](https://hub.docker.com/r/infracost/infracost/tags) Docker image that can be used in other CI/CD integrations. This uses latest patch version of 0.10 to pickup bug fixes and new resources. diff --git a/docs/integrations/cicd_integrations.md b/docs/integrations/cicd_integrations.md new file mode 100644 index 00000000..a879c437 --- /dev/null +++ b/docs/integrations/cicd_integrations.md @@ -0,0 +1,8 @@ +--- +slug: cicd_integrations +title: CI/CD integrations +--- + +import useBaseUrl from '@docusaurus/useBaseUrl'; + +Infracost can be integrated into any CI/CD system, see the [integrations page](/docs/integrations/cicd/#cicd-integrations) for details. diff --git a/docs/integrations/generic_cicd.md b/docs/integrations/generic_cicd.md deleted file mode 100644 index 306e0a9e..00000000 --- a/docs/integrations/generic_cicd.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -slug: generic_cicd -title: Generic CI/CD integration ---- - -import useBaseUrl from '@docusaurus/useBaseUrl'; -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -This page is useful if you cannot use one of our [existing CI/CD](/docs/integrations/cicd/) integration. Infracost can be used in any CI/CD system using the following steps. Follow our [GitLab CI integration](https://gitlab.com/infracost/infracost-gitlab-ci/) to see examples of how the following steps are used. - -1. Use one of the following options to add the Infracost CLI into your CI/CD: - - - - - We maintain specific [CI Docker images](https://hub.docker.com/r/infracost/infracost/tags): - ```text - infracost/infracost:ci-0.10 - Recommended, uses latest patch version of 0.10 to pickup bug fixes and new resources - infracost/infracost:ci-latest - Use latest Infracost image, might break when new minor/major versions are released - ``` - - - - - Use `curl -O -L https://infracost.io/downloads/v0.10/infracost-linux-amd64.tar.gz` to download the latest patch version of 0.10 to pickup bug fixes and new resource costs. You can also use [latest](https://github.com/infracost/infracost/releases/latest/download/infracost-linux-amd64.tar.gz), which might break when new minor/major versions are released. - - - - -2. If your infra code is in GitHub, GitLab, Azure Repos, or Bitbucket, run the [`breakdown`, `diff` and `comment` commands](/docs/features/cli_commands/#comment-on-pull-requests) to generate a cost estimate and post a comment directly. - - Otherwise, run the [`breakdown`, `diff` and `output` commands](/docs/features/cli_commands/#combined-output-formats) to save the comment markdown (e.g. using `--format github-comment`) and post it from your CI/CD system using curl or other command line tools. - - You should also set the [required environment variables](/docs/features/environment_variables/#environment-variables-to-set-metadata). diff --git a/docs/integrations/github_actions.md b/docs/integrations/github_actions.md deleted file mode 100644 index be307ab3..00000000 --- a/docs/integrations/github_actions.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -slug: github_actions -title: GitHub Actions ---- - -:::tip -We recommend using the [GitHub App](/docs/integrations/github_app/) instead as it has several benefits over GitHub Actions. -::: - -See the [Infracost actions](https://github.com/infracost/actions/) repo for instructions and examples. - -Example Infracost diff output diff --git a/docs/integrations/github_app.md b/docs/integrations/github_app.md index adec90a3..e27f9c44 100644 --- a/docs/integrations/github_app.md +++ b/docs/integrations/github_app.md @@ -1,6 +1,6 @@ --- slug: github_app -title: GitHub App (recommended) +title: GitHub App --- import useBaseUrl from '@docusaurus/useBaseUrl'; @@ -13,10 +13,9 @@ The Infracost GitHub App is an automated integration meaning that Infracost runs ## Benefits -There are three key benefits of using the GitHub App over manual CI/CD integrations: +There are two key benefits of using the GitHub App over manual CI/CD integrations: 1. You can add Infracost to multiple repos with one click, no need to install or update CLI versions in your CI/CD pipeline. -2. Infracost runs significantly faster as only changed folders are run based on the GitHub App events. -3. If you use Infracost Cloud (our SaaS product), all features work without you needing to make any changes to your CI/CD pipelines. If you use CI/CD integrations, you should implement [these extra steps](/docs/guides/source_control_benefits/). +2. Infracost runs faster as only changed folders are run based on the GitHub App events. ## Usage @@ -68,3 +67,9 @@ Each time a pull request is opened or a new commit is pushed to open pull reques ### Disable pull request comments From the Org Settings > Integrations > GitHub App page, you can disable pull request comments so cost estimates, guardrails and tagging policies are only shown in Infracost Cloud. This enables you to test these features without impacting engineering workflows. + +### GitHub Actions to App migration + +1. Follow the [usage](#usage) docs to install the app. You can do this from the same Infracost organization you use already, and going into the Org Settings > Integrations page. +2. Test it by [sending a pull request](/docs/infracost_cloud/get_started/#4-send-a-pull-request). +3. Remove all Infracost steps from your GitHub Actions. diff --git a/docs/integrations/gitlab_app.md b/docs/integrations/gitlab_app.md index 0e19a2d8..840f7ff4 100644 --- a/docs/integrations/gitlab_app.md +++ b/docs/integrations/gitlab_app.md @@ -1,6 +1,6 @@ --- slug: gitlab_app -title: GitLab App (recommended) +title: GitLab App --- import useBaseUrl from '@docusaurus/useBaseUrl'; diff --git a/docs/integrations/gitlab_ci.md b/docs/integrations/gitlab_ci.md deleted file mode 100644 index 81fde0fc..00000000 --- a/docs/integrations/gitlab_ci.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -slug: gitlab_ci -title: GitLab CI ---- - -:::tip -We recommend using the [GitLab App](/docs/integrations/gitlab_app/) instead as it has several benefits over GitLab CI. -::: - -See the [Infracost GitLab CI template](https://gitlab.com/infracost/infracost-gitlab-ci) for instructions and examples. - -If you used the [older setup](https://gitlab.com/infracost/infracost-gitlab-ci/-/blob/master/README-deprecated.md), please see our [migration guide](guides/gitlab_ci_migration.md). - -Example Infracost diff output diff --git a/docs/integrations/slack.md b/docs/integrations/slack.md index 0b1a4a2c..cf6e853f 100644 --- a/docs/integrations/slack.md +++ b/docs/integrations/slack.md @@ -5,7 +5,7 @@ title: Slack import useBaseUrl from '@docusaurus/useBaseUrl'; -To post cost estimates to Slack: +Infracost Cloud [Guardrails](/docs/infracost_cloud/guardrails/) have native support for Slack notifications that trigger when your defined thresholds are exceeded. If you are not using that feature, you can post cost estimates to Slack by following these steps in your CI/CD system: 1. Create a [Slack Webhook](https://slack.com/intl/en-tr/help/articles/115005265063-Incoming-webhooks-for-Slack) in your workspace. 2. Use the `infracost output --format slack-message` [command](/docs/features/cli_commands/) to produce a Slack-flavored Markdown message. Slack message blocks have a 3000 char limit so the Infracost CLI automatically truncates the middle of the `slack-message` output format if required. diff --git a/docs/integrations/third_party_integrations.md b/docs/integrations/third_party_integrations.md index 7cb379ae..768fd9ab 100644 --- a/docs/integrations/third_party_integrations.md +++ b/docs/integrations/third_party_integrations.md @@ -5,7 +5,8 @@ title: Third-party integrations import useBaseUrl from '@docusaurus/useBaseUrl'; -Infracost can also be used alongside third-party systems including: +Infracost can be used in the following third-party systems. You should only consider using them if you cannot use our [CI/CD integrations](/docs/integrations/cicd/) as these integrations are very minimal, do not post pull request comments nor do they work with other Infracost Cloud features such as [FinOps policies](/docs/infracost_cloud/finops_policies/), [Tagging policies](/docs/infracost_cloud/tagging_policies/) or [Guardrails](/docs/infracost_cloud/guardrails/). + - [Terraform Cloud/Enterprise Run Tasks](/docs/integrations/terraform_cloud_enterprise/) - [Scalr](https://docs.scalr.com/en/latest/cost_estimate.html) - [Spacelift](https://docs.spacelift.io/vendors/terraform/infracost) diff --git a/docs/cloud_pricing_api/api_usage.md b/docs/supported_resources/cloud_pricing_api.md similarity index 99% rename from docs/cloud_pricing_api/api_usage.md rename to docs/supported_resources/cloud_pricing_api.md index f4f3b32f..79784ee9 100644 --- a/docs/cloud_pricing_api/api_usage.md +++ b/docs/supported_resources/cloud_pricing_api.md @@ -1,6 +1,6 @@ --- -slug: overview -title: Overview and usage +slug: cloud_pricing_api +title: Cloud Pricing API --- import Tabs from '@theme/Tabs'; diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 4f8395cf..eeef8418 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -15,187 +15,18 @@ If the Terraform CLI fails, check their [debugging page](https://www.terraform.i ## 2. Generating plan JSON files -By default, the Infracost CLI parses Terraform HCL code to estimate costs. If that does not work for your use-case, or you already have a Terraform plan JSON file, Infracost can also parse that. See the relevant [Terraform CLI](#terraform-cli), [Terraform Cloud](#terraform-cloud) or [Terragrunt](#terragrunt) sections below on how to generate plans. These bash scripts can be modified and used in your CI/CD pipelines. +By default, the Infracost CLI parses Terraform HCL code to estimate costs. If that does not work for your use-case, Infracost can also parse the Terraform/Terragrunt [plan JSON file](/docs/features/cli_commands/#option-2-terraform-plan-json). -### Terraform CLI - -The Terraform CLI can be used to produce a plan JSON file as shown below: - -#### Single project - -```bash -cd path/to/code -terraform init - -# Customize this to how you run Terraform -# e.g. if you are using variables you can pass them with -var or -var-file -terraform plan -out tfplan.binary -terraform show -json tfplan.binary > plan.json - -infracost breakdown --path plan.json -``` - -#### Multi-projects - -We recommend that you use an Infracost [config file](/docs/features/config_file/) to define paths to the projects plan JSON files. If that doesn't work for your use-case, you can use the following bash script to generate Terraform plan JSON files, dynamically create a config file and pass it to Infracost. - -```bash -# Path to Terraform code -TF_ROOT=path/to/code - -cd $TF_ROOT - -# Find all subfolders that have .tf files, but exclude "modules" folders, can be customized -tfprojects=($(find . -type f -name '*.tf' | sed -E 's|/[^/]+$||' | grep -v modules | sort -u)) - -plans=() -planjsons=() -for project in "${tfprojects[@]}"; do - # You can remove this if Terraform is already init'd - echo "Running terraform init for $project" - terraform -chdir=$project init - - # Customize this to how you run Terraform - # e.g. if you are using variables you can pass them with -var or -var-file - echo "Running terraform plan for $project" - terraform -chdir=$project plan -out tfplan.binary - - echo "Running terraform show for $project" - terraform -chdir=$project show -json tfplan.binary > $project/plan.json - - plans=(${plans[@]} "$project/tfplan.binary") - planjsons=(${planjsons[@]} "$project/plan.json") -done - -# Generate Infracost config file -echo -e "version: 0.1\n\nprojects:\n" > infracost-generated.yml -for planjson in "${planjsons[@]}"; do - echo -e " - path: $planjson" >> infracost-generated.yml -done - -# Infracost CLI commands can be run now -infracost breakdown --config-file=infracost-generated.yml - -# Cleanup generated files -rm infracost-generated.yml -rm $plans -rm $planjsons -``` - -### Terraform Cloud - -When Terraform Cloud/Enterprise's [remote execution mode](https://www.terraform.io/cloud-docs/workspaces/settings#execution-mode) is used, the Terraform CLI doesn't allow you to save the plan output directly. Thus the following bash script is needed to fetch the plan JSON from Terraform Cloud: - -```bash -# Path to Terraform code -TF_ROOT=path/to/code -# If you're using Terraform Enterprise update this to your Terraform enterprise hostname (without https://) -TFC_HOST=app.terraform.io -# Create a Team API Token or User API Token that can be used to fetch the plan, see https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html -TFC_TOKEN=my_token_here - -# This file is used by the Terraform CLI to authenticate with Terraform Cloud, it might also live in /root/.terraformrc on Linux CI/CD machines -cp ~/.terraformrc ~/.terraformrc.old -cat < /root/.terraformrc -credentials "$TFC_HOST" { - token = "$TFC_TOKEN" -} -EOF - -cd $TF_ROOT - -# You can remove this if Terraform is already init'd -echo "Running terraform init" -terraform init - -# When using TFC remote execution, terraform doesn't allow us to save the plan output. -# So we have to save the plan logs so we can parse out the run ID and fetch the plan JSON -echo "Running terraform plan" -terraform plan -no-color | tee /tmp/plan_logs.txt - -echo "Retrieving the plan JSON" -# Parse the run URL and ID from the logs -run_url=$(grep -A1 'To view this run' /tmp/plan_logs.txt | tail -n 1) -run_id=$(basename $run_url) - -# Get the run plan response and parse out the path to the plan JSON -run_plan_resp=$(wget -q -O - --header="Authorization: Bearer $TFC_TOKEN" "https://$TFC_HOST/api/v2/runs/$run_id/plan") -plan_json_path=$(echo $run_plan_resp | sed 's/.*\"json-output\":\"\([^\"]*\)\".*/\1/') - -# Download the plan JSON -wget -q -O plan.json --header="Authorization: Bearer $TFC_TOKEN" "https://$TFC_HOST$plan_json_path" - -# Infracost CLI commands can be run now -infracost breakdown --path plan.json - -# Cleanup generated files -rm /tmp/plan_logs.txt -rm plan.json -``` - -### Terragrunt - -If the built-in [CLI integration with Terragrunt](/docs/features/terragrunt/#how-the-terragrunt-integration-works) does not work for your use-case, we recommend using/customizing the following bash script. This is required as Terragrunt does not provide a quick way of creating a Terraform plan JSON file for the whole project. - -```bash -# Path to Terraform code -TF_ROOT=path/to/code - -cd $TF_ROOT - -# Generate plan JSON files for all Terragrunt modules and add them to an Infracost config file -terragrunt run-all --terragrunt-ignore-external-dependencies plan -out tfplan.binary - -# Find the plan files -plans=($(find . -name tfplan.binary)) - -# Generate plan JSON files by running terragrunt show for each plan file -planjsons=() -for plan in "${plans[@]}"; do - # Find the Terraform working directory for running terragrunt show - # We want to take the dir of the plan file and strip off anything after the .terraform-cache dir - # to find the location of the Terraform working directory that contains the Terraform code - dir=$(dirname $plan) - dir=$(echo "$dir" | sed 's/\(.*\)\/\.terragrunt-cache\/.*/\1/') - - # Customize this to how you run Terragrunt - echo "Running terragrunt show for $(basename $plan) for $dir" - terragrunt show -json $(basename $plan) --terragrunt-working-dir=$dir --terragrunt-no-auto-init > $dir/plan.json - planjsons=(${planjsons[@]} "$dir/plan.json") -done - -# Sort the plan JSONs so we get consistent project ordering in the config file -IFS=$'\n' planjsons=($(sort <<<"${planjsons[*]}")) - -# Generate Infracost config file -echo -e "version: 0.1\n\nprojects:\n" > infracost-generated.yml -for planjson in "${planjsons[@]}"; do - echo -e " - path: $planjson" >> infracost-generated.yml -done - -# Infracost CLI commands can be run now -infracost breakdown --config-file=infracost-generated.yml - -# Cleanup generated files -rm infracost-generated.yml -rm $plans -rm $planjsons -``` +If you have multiple Terraform plan JSON files, you can +1. run [`infracost breakdown`](/docs/features/cli_commands/#breakdown) with `--path plan-1.json --format json --out-file infracost-1.json` to generate an Infracost JSON file for each. +2. run [`infracost output`](/docs/features/cli_commands/#combined-output-formats) with `--path "infracost-*.json" --format diff` (glob patterns need quotes) to combine the Infracost JSON files into one output format then use that file with `infracost comment`. The `infracost output --help` command shows the other options. ## 3. Check supported versions Check the Terraform version matches what you expect. Infracost works with Terraform v0.12 and above. Use `ls -lah` in the CI build to check for any `.terraform*` files/folders that might be confusing Terraform running in CI vs previous runs that were used to create them. Removing those files might help. -## 4. Combining plan JSON files - -Once you have multiple Terraform plan JSON files, you can -1. run [`infracost breakdown`](/docs/features/cli_commands/#breakdown) with `--path plan-1.json --format json --out-file infracost-1.json` to generate an Infracost JSON file for each. -2. run [`infracost output`](/docs/features/cli_commands/#combined-output-formats) with `--path "infracost-*.json" --format diff` (glob patterns need quotes) to combine the Infracost JSON files into one output format. The `infracost output --help` command shows the other options. - -These steps are used by our [CI/CD integrations](/docs/#4-add-to-cicd) to post pull request comments. - -## 5. Posting comments +## 4. Posting comments If you're having issues posting pull request comments, please review the troubleshooting section for your version control system: @@ -204,19 +35,14 @@ If you're having issues posting pull request comments, please review the trouble - [Azure Repos](https://github.com/infracost/infracost-azure-devops#troubleshooting) - [Bitbucket](https://bitbucket.org/infracost/infracost-bitbucket-pipeline) > see the Troubleshooting section -## 6. Infracost Cloud dashboard +## 5. Infracost Cloud dashboard Try the following troubleshooting steps and join our [community Slack channel](https://www.infracost.io/community-chat) - we'll help you very quickly πŸ˜„πŸš€ If Infracost is **erroring or running too slow**, email us at [hello@infracost.io](mailto:hello@infracost.io) so we can arrange a debugging session with you quickly. If your pull requests comments are being posted but they are **not showing in the dashboard**, ensure that the: -1. [Cost estimate dashboard](/docs/infracost_cloud/get_started/#3-setup-infracost-cloud) organization setting is enabled. +1. In Infracost Cloud's Org settings page, the cost estimate dashboard is enabled. 2. Infracost CLI version (`infracost --version`) being used is latest patch version of v0.10. 3. [Required environment variables](/docs/features/environment_variables/#environment-variables-to-set-metadata) are set before theΒ `infracost breakdown` and `infracost diff`Β commands are run. You can verify this by runningΒ `cat infracost.json | jq .metadata` or `infracost breakdown --path /code --format json | jq .metadata` and checking the Infracost JSON block shows your pull request metadata. -4. Either [`infracost comment`](/docs/features/cli_commands/#comment-on-pull-requests) or [`infracost upload`](/docs/features/cli_commands/#upload-runs) is used in your CI/CD integration. If Infracost Cloud is enabled (step 2 above), these commands send the Infracost JSON data to your organization in Infracost Cloud. - -Notes for legacy users: -1. Old Infracost API keys, ones that **do not** start with `ico-`, will continue to work in the CLI and Cloud Pricing API, but not with Infracost Cloud. -2. Currently there is no automated migration of your old API keys since they were only used by the CLI to retrieve prices from our Cloud Pricing API, e.g. get prices for instance types. We recommend you switch to using your API key from Infracost Cloud if you'd like to create organizations or regenerate API keys. You can simply discard your old API keys. -3. We recommend [Terraform Cloud Run Task](/docs/integrations/terraform_cloud_enterprise/#option-2-terraform-run-tasks) users to sign up to Infracost Cloud and create a new Run Task integration so they can associate that with an organization. +4. Either [`infracost comment`](/docs/features/cli_commands/#comment-on-pull-requests) or [`infracost upload`](/docs/features/cli_commands/#upload-runs) is used in your CI/CD integration. If Infracost Cloud is enabled (step 1 above), these commands send the Infracost JSON data to your organization in Infracost Cloud. diff --git a/docusaurus.config.js b/docusaurus.config.js index 89bb57e3..58f0bc6b 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -25,7 +25,7 @@ module.exports = { redirects: [ { from: '/integrations', - to: '/integrations/github_actions', + to: '/integrations/cicd', }, { from: ['/environment_variables', '/integrations/environment_variables'], @@ -99,6 +99,14 @@ module.exports = { from: '/integrations/jira', to: '/infracost_cloud/jira_integration', }, + { + from: '/integrations/generic_cicd', + to: '/integrations/cicd/', + }, + { + from: '/integrations/vscode', + to: '/features/vscode/', + }, { from: '/infracost_cloud/authentication', to: '/infracost_cloud/key_concepts', @@ -115,6 +123,10 @@ module.exports = { from: '/cloud_pricing_api/self_hosted', to: '/', }, + { + from: '/cloud_pricing_api/overview', + to: '/supported_resources/cloud_pricing_api', + }, ], }, ], diff --git a/sidebars.js b/sidebars.js index c8574dd5..a323af2a 100644 --- a/sidebars.js +++ b/sidebars.js @@ -16,6 +16,7 @@ module.exports = { 'features/cli_commands', 'features/config_file', 'features/usage_based_resources', + 'features/vscode', 'features/terraform_modules', 'features/terragrunt', 'features/environment_variables', @@ -33,11 +34,11 @@ module.exports = { 'infracost_cloud/jira_integration', 'infracost_cloud/reports', 'infracost_cloud/data_export', + 'infracost_cloud/sso', 'infracost_cloud/custom_price_books', 'infracost_cloud/actual_costs', 'infracost_cloud/readme_badge', 'infracost_cloud/key_concepts', - 'infracost_cloud/sso', ], }, { @@ -47,15 +48,10 @@ module.exports = { items: [ 'integrations/github_app', 'integrations/gitlab_app', - 'integrations/github_actions', - 'integrations/gitlab_ci', - 'integrations/atlantis', - 'integrations/azure_pipelines', - 'integrations/generic_cicd', + 'integrations/cicd_integrations', + 'integrations/slack', 'integrations/terraform_cloud_enterprise', - 'integrations/vscode', 'integrations/open_policy_agent', - 'integrations/slack', 'integrations/infracost_api', 'integrations/third_party_integrations', ], @@ -69,30 +65,7 @@ module.exports = { 'supported_resources/aws', 'supported_resources/azure', 'supported_resources/google', - ], - }, - { - type: 'category', - label: 'Cloud Pricing API', - collapsed: true, - items: [ - 'cloud_pricing_api/api_usage', - ], - }, - { - type: 'category', - label: 'Guides', - collapsed: true, - items: [ - 'guides/source_control_benefits', - 'guides/v0.10_migration', - 'guides/v0.9_migration', - 'guides/v0.8_migration', - 'guides/actions_migration', - 'guides/gitlab_ci_migration', - 'guides/atlantis_migration', - 'guides/azure_devops_migration', - 'guides/uninstall', + 'supported_resources/cloud_pricing_api', ], }, { From 14a0e25d1cb13bfd0e8093966d84a5835ae499e8 Mon Sep 17 00:00:00 2001 From: Vadim Golub Date: Sun, 18 Feb 2024 15:58:03 +0100 Subject: [PATCH 2/2] docs: Fix typo in CI/CD integrations --- docs/integrations/cicd.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/cicd.mdx b/docs/integrations/cicd.mdx index fd2e2603..fd544c91 100644 --- a/docs/integrations/cicd.mdx +++ b/docs/integrations/cicd.mdx @@ -101,4 +101,4 @@ The following integrations can also be used to post pull request comments.
-For other CI/CD systems, the GitLab CI integration above is a good example to follow. Please [email us](mailto:hello@infracost.io) if you need help. We main the [`infracost/infracost:ci-0.10`](https://hub.docker.com/r/infracost/infracost/tags) Docker image that can be used in other CI/CD integrations. This uses latest patch version of 0.10 to pickup bug fixes and new resources. +For other CI/CD systems, the GitLab CI integration above is a good example to follow. Please [email us](mailto:hello@infracost.io) if you need help. We maintain the [`infracost/infracost:ci-0.10`](https://hub.docker.com/r/infracost/infracost/tags) Docker image that can be used in other CI/CD integrations. This uses the latest patch version of 0.10 to pick up bug fixes and new resources.