This message was deleted.
# general
b
This message was deleted.
w
@nice-morning-3455 that is still supported 🙂 My guess is the github token doesn’t have access but do you see any errors in the github actions logs tab? Also, can you check the same logs for the Setup Infracost task to see what version of the Infracost CLI it shows?
b
You can also try
--commit=$GITHUB_SHA
env var as the commit ID
n
Thank you for the fast response! The setup
Copy code
Run infracost/actions/setup@v1
  with:
    api-key: ***
    version: 0.9.x
    currency: USD
    github-token: ***
  env:
    TFPath: Azure/
    TF_VAR_PREFIX: JBI-IAC-DEMO
    TF_VAR_LOCATION: westeurope
    TF_VAR_USERNAME: azureuser
    TF_VAR_PASSWORD: ***
    TF_VAR_FLEXVM_API_USERNAME: ***
    TF_VAR_FLEXVM_API_PASSWORD: ***
    TF_VAR_FLEXVM_PROGRAM_SERIAL: ***
    TF_VAR_FLEXVM_CONFIG_NAME: ***
    TF_VAR_FLEXVM_VM_SERIAL: ***
    ARM_CLIENT_ID: ***
    ARM_CLIENT_SECRET: ***
    ARM_SUBSCRIPTION_ID: ***
    ARM_TENANT_ID: ***
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/063842bf-6bae-40b3-bc5d-bb8e80d67c23 -f /home/runner/work/_temp/b1c8b699-def9-4440-8075-13000e7a985c
Setup Infracost CLI version 0.9.24
/home/runner/work/_temp/063842bf-6bae-40b3-bc5d-bb8e80d67c23/infracost configure set api_key ***
/home/runner/work/_temp/063842bf-6bae-40b3-bc5d-bb8e80d67c23/infracost configure set currency USD
The calculation:
Copy code
Run infracost breakdown --path plan.json --format json --usage-file infracost-usage.yml --out-file /tmp/infracost.json
  infracost breakdown --path plan.json --format json --usage-file infracost-usage.yml --out-file /tmp/infracost.json
  shell: /usr/bin/bash -e {0}
  env:
    TFPath: Azure/
    TF_VAR_PREFIX: JBI-IAC-DEMO
    TF_VAR_LOCATION: westeurope
    TF_VAR_USERNAME: azureuser
    TF_VAR_PASSWORD: ***
    TF_VAR_FLEXVM_API_USERNAME: ***
    TF_VAR_FLEXVM_API_PASSWORD: ***
    TF_VAR_FLEXVM_PROGRAM_SERIAL: ***
    TF_VAR_FLEXVM_CONFIG_NAME: ***
    TF_VAR_FLEXVM_VM_SERIAL: ***
    ARM_CLIENT_ID: ***
    ARM_CLIENT_SECRET: ***
    ARM_SUBSCRIPTION_ID: ***
    ARM_TENANT_ID: ***
    INFRACOST_GITHUB_ACTION: true
    INFRACOST_SKIP_UPDATE_CHECK: true
    INFRACOST_VCS_REPOSITORY_URL: <https://github.com/jbismans/github-actions-infra-as-code-demo>
    INFRACOST_LOG_LEVEL: info
time="2022-07-14T14:05:31Z" level=info msg="Detected Terraform plan JSON file at plan.json"
time="2022-07-14T14:05:31Z" level=info msg="Starting: Extracting only cost-related params from terraform"
time="2022-07-14T14:05:31Z" level=info msg="Starting: Retrieving cloud prices to calculate costs"
time="2022-07-14T14:05:31Z" level=warning msg="Multiple products with prices found for azurerm_virtual_machine.lnxvm Instance usage (pay as you go, Standard_B1s), using the first product"
time="2022-07-14T14:05:31Z" level=warning msg="Multiple products with prices found for azurerm_virtual_machine.lnxvm Instance usage (pay as you go, Standard_B1s), using the first product"
time="2022-07-14T14:05:31Z" level=info msg="Output saved to /tmp/infracost.json"
The post
Copy code
Run infracost/actions/comment@v1
  with:
    path: /tmp/infracost.json
    behavior: update
    github-token: ***
  env:
    TFPath: Azure/
    TF_VAR_PREFIX: JBI-IAC-DEMO
    TF_VAR_LOCATION: westeurope
    TF_VAR_USERNAME: azureuser
    TF_VAR_PASSWORD: ***
    TF_VAR_FLEXVM_API_USERNAME: ***
    TF_VAR_FLEXVM_API_PASSWORD: ***
    TF_VAR_FLEXVM_PROGRAM_SERIAL: ***
    TF_VAR_FLEXVM_CONFIG_NAME: ***
    TF_VAR_FLEXVM_VM_SERIAL: ***
    ARM_CLIENT_ID: ***
    ARM_CLIENT_SECRET: ***
    ARM_SUBSCRIPTION_ID: ***
    ARM_TENANT_ID: ***
    INFRACOST_GITHUB_ACTION: true
    INFRACOST_SKIP_UPDATE_CHECK: true
    INFRACOST_VCS_REPOSITORY_URL: <https://github.com/jbismans/github-actions-infra-as-code-demo>
    INFRACOST_LOG_LEVEL: info
No errors I'm afraid. However, you are mentioning this github token and I must admit, I'm seeing a mention of it in the code:
Copy code
uses: actions/github-script@0.9.0
        if: github.event_name == 'pull_request'
        env:
          PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }} #Variable needs to be fixed?
          script: |
            const output = `#### Terraform Format and Style đź–Ś\`${{ steps.fmt.outcome }}\`
            #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
            #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
            #### Terraform Plan đź“–\`${{ steps.plan.outcome }}\`

            <details><summary>Show Plan</summary>

            \`\`\`\n
            ${process.env.PLAN}
            \`\`\`

            </details>

            *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: output
            })
I haven't created the token in my secrets because I wasn't sure if it was a real Github API token and what access rights would be needed. And after some googling, I thought it was some intrinsic to github https://docs.github.com/en/actions/security-guides/automatic-token-authentication which doesn't need you to create something.
b
I also noticed that you're using v1 of the setup action. We have v2 now that uses CLI v0.10.x that is much quicker as it parses HCL code directly. You may want to update it:
infracost/actions/setup@v2
I guess you're trying to replicate your colleague's setup. But maybe it can be easier start from scratch? Have you looked at our examples, like this one? https://github.com/infracost/actions/tree/master/examples/terraform-project
The cool part of v0.10.x CLI is that you don't need to provide any secrets (apart from the case when you need to download private modules), so maybe the setup will be much simpler compared to the older one
n
You guys are great. 🙂 It's working now. Setup v2 with the infracost comment it's working now. The GithubSha was the tip I needed.
Copy code
Project	Previous	New	Diff
jbismans/github-actions-infra-as-code-demo/Azure/plan.json	$97.95	$180	+$82.49 (+84%)
Infracost output
Project: jbismans/github-actions-infra-as-code-demo/Azure/plan.json



~ azurerm_virtual_machine.fgtvm

  +$82.49 ($84.00 → $166)



    ~ Instance usage (pay as you go, Standard_F2s → Standard_F4s)

      +$82.49 ($83.22 → $166)



Monthly cost change for jbismans/github-actions-infra-as-code-demo/Azure/plan.json

Amount:  +$82.49 ($97.95 → $180)

Percent: +84%
b
Awesome!! 👏
w
🎉 Glad it’s working! I was wondering if you could help us with a quick 20min usability test for Infracost Cloud? (our new SaaS product that works closely with the open source CLI and CI/CD integrations). This’ll involve a zoom screenshare where I give you a task and observe as you try it and take notes about issues you run into 🙂
n
Well, since you guys were so helpful. I think I should return the favor, but I'm not a devops engineer (as you might have noticed). I'm a presales (network security) engineer at Fortinet and the goal is using infracost as part of an automation demo to show our partners. So not sure how valuable my opinion is. (also I'm afraid I'm not in a corporate buying position for infracost either...)
w
No pressure at all 🙂 this isn’t related to sales and it doesn’t need expertise in devops, it’s testing our user experience and helps us see obvious issues with our docs or UI that we missed during development. I’ll ping you a link so you can pick a time that suits you.