This message was deleted.
# contributors
b
This message was deleted.
m
Hey Hany 👋
d
Hi @mysterious-teacher-68276
m
I’m just checking this for you, give me 5 mins
You can use the env var
INFRACOST_TERRAFORM_BINARY
to specify the terraform version you want to use
d
what is the accepted value for it?
for example if i want to use 0.14.7
m
so if you wanted to use version 0.13.7 you would set
INFRACOST_TERRAFORM_BINARY=terraform_0.13.7
d
thanks! ill try it right now
m
no problem
w
@delightful-branch-79038 if you’re using Infracost v0.10 (just released a few hours ago), you don’t need a Terraform version anymore as the CLI parses HCL code directly. https://www.infracost.io/docs/integrations/cicd/#my-cicd-system-isnt-supported has the docker images (I updated https://www.infracost.io/docs/ earlier today to use the same images)
👍 1
d
i still use 0.9 , but ill try to change it to 0.10 now , hope to pass in gitlab ci
ill update in few mins
🙌 1
m
It should also be much quicker to run for you
d
i just tried it, it failed with this error:
Copy code
Error: To show a diff:
  1. Generate a cost estimate baseline: `infracost breakdown --path ./ --format json --out-file infracost-base.json`
  2. Make a Terraform code change
  3. Generate a cost estimate diff: `infracost diff --path ./ --compare-to infracost-base.json`
it just was working in 0.9
this is my job:
Copy code
infracost:
  stage: infracost
  image:
    name: infracost/infracost:0.10
    entrypoint: [""]
  variables:
    INFRACOST_API_KEY: $INFRACOST_API_KEY
    GITLAB_TOKEN: $GITLAB_TOKEN
  script:
    - infracost diff --config-file ./infracost.yaml --format json --out-file infracost.json
    - infracost comment gitlab --path infracost.json --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --gitlab-server-url $CI_SERVER_URL --gitlab-token $GITLAB_TOKEN --behavior update
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
so i just run diff directly and it compare it to current aws state
after i upgrade it it failed , it sound like request to generate the old state first
m
so 0.10.0 has a few interface changes, you’ll need to tweak a few things
👍 1
let me paste them here for you
Copy code
infracost:
  stage: infracost
  image:
    name: infracost/infracost:ci-0.10
    entrypoint: [""]
  variables:
    INFRACOST_API_KEY: $INFRACOST_API_KEY
    GITLAB_TOKEN: $GITLAB_TOKEN
  script:
    - git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base
    - |
      infracost breakdown --config-file=/tmp/base/infracost.yaml \
                          --format=json \
                          --out-file=infracost-base.json
    - |
      infracost diff --config-file=./infracost.yaml \
                     --compare-to=infracost-base.json \
                     --format=json \
                     --out-file=infracost.json
    - infracost comment gitlab --path infracost.json --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --gitlab-server-url $CI_SERVER_URL --gitlab-token $GITLAB_TOKEN --behavior update
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
^this is what your pipeline should look like
d
let me try it
Copy code
Error: config file does not exist at /tmp/base/infracost.yaml
aah, i can understand why
because in master i dont have it, so it failed
m
ah right, so you’re switching to a config file
d
i think it should copy it if not exist in master from the new one, so new integration will work
m
what do you have in your config file? v0.10.0 might work for you without the config file
as it can autodetect multi-project
d
it just must basic infracost file
Copy code
version: 0.1
projects:
  - path: ./
    terraform_workspace: ops
    terraform_plan_flags: -var-file=./ops.tfvars
    terraform_var_files:
      - ./ops.tfvars
but it does not exist in the target project, so it failed
i need it in order to configure my workspace
m
so this will work without a config file, let me paste what you need
you just have one project in this repo?
d
one project with multiple workspaces
m
ah right, I see
d
i did something like this :
Copy code
$ cp ./infracost.yaml /tmp/base/infracost.yaml
$ infracost breakdown --config-file=/tmp/base/infracost.yaml \ # collapsed multi-line command
Error: Flag terraform-plan-flags is deprecated and only compatible with --terraform-force-cli. If you want to pass Terraform variables use the --terraform-vars or --terraform-var-file flag.
copied infracost to tmp
but now i get different error
m
yeah so the config file params are out of date, let me paste the new ones here
d
ok
m
oh sorry you just need to remove the
terraform_plan_flags
argument
in config file
d
ok, trying
yes, it working fine ,
🙌 1
so to summarize in case and there is someone else want to start integrate with you amazing tool, and have multiple workspaces, 1. need to create config file like this:
Copy code
version: 0.1
projects:
  - path: ./
    terraform_workspace: <workspace name>
    terraform_var_files:
      - <workspace var file>
2. need to use this gitlab job:
Copy code
- git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base
    - cp ./infracost.yaml /tmp/base/infracost.yaml
    - |
      infracost breakdown --config-file=/tmp/base/infracost.yaml \
      --format=json \
      --out-file=infracost-base.json
    - |
      infracost diff --config-file=./infracost.yaml \
      --compare-to=infracost-base.json \
      --format=json \
      --out-file=infracost.json
    - infracost comment gitlab --path infracost.json --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --gitlab-server-url $CI_SERVER_URL --gitlab-token $GITLAB_TOKEN --behavior update
but still think it better to use the default infracost config file instead of manuall copy it
thank you @mysterious-teacher-68276 for your help!
m
yes agreed - but after this change is merged into master the
cp
step can be removed
1
no problems, thanks for being patient with the support. I’m juggling many tasks at the moment 😅
d
general question please, in 0.10 , infracost didnt do any terraform plan anymore?
m
yes exactly, we now read the Terraform files directly
which is significantly quicker and means we don’t need your cloud credentials
d
i mean how it get the state in check the cost diff without do any plan ?
but you still check the current aws state , right ?
m
no we use your base branch as the current state
d
i mean if i change aws instance node manually in aws (ex) and then want to change terraform to be the same as the current state, it will not showing me any cost change
i see , so generally no need to any aws cred anymore
am i right ?
m
i mean if i change aws instance node manually in aws (ex) and then want to change terraform to be the same as the current state, it will not showing me any cost change
yes this is correct. This would be infrastructure drift. If you want to cover this case you can generate a Terraform plan JSON output and have Infracost read it.
i see , so generally no need to any aws cred anymore
Yes
d
😅 i just worked tow days in order to fix all needed permission in my runner ,
😢 1
m
nice
high five
d
sorry, but i think there is a problem with cost diff
m
righty ho
what’s the issue
d
the diff still showing zero, although that i tried to scaled up from 3 to 6 nodes
my workspace
ops
using terraform module
m
what terraform resource are you editing?
d
before i moving to latest version it was working fine
Copy code
resource "aws_autoscaling_group" "eks-autoscalling-group" {
      ~ desired_capacity          = 3 -> 6
        id                        = "eks-ops-worker"
      ~ max_size                  = 3 -> 6
      ~ min_size                  = 3 -> 6
        name                      = "eks-ops-worker"
        # (19 unchanged attributes hidden)

        # (5 unchanged blocks hidden)
    }
f
Could it be that terraform module changes are not seen?
m
@delightful-branch-79038 what’s infracost diff output for this resource. Is it missing or just 0?
also, do you have a launch configuration and or launch template attached to this autoscaling group?
d
Copy code
The following projects have no cost estimate changes: ops/terraform/eks/eks-development/. (dev), ops/terraform/eks/eks-development/. (ops), ops/terraform/eks/eks-development/. (qa)
Run the following command to see their breakdown: infracost breakdown --path=/path/to/code
yes, i have
m
ok right
do you have
infracost
locally?
d
yes
let me upgrade it first to 0.10version
m
cool - let’s migrate this to a direct chat so you don’t worry about leaking sensitive infra information
d
cool ,
m
@fast-motorcycle-7174 sorry I missed your comment, the error doesn’t appear to be that (from Hany and mines debugging session), however are you having problems with a similar issue. Or just offering a helping hand?
d
the final job ( working as expected)
Copy code
infracost:
  stage: infracost
  image:
    name: infracost/infracost:0.10
    entrypoint: [""]
  variables:
    INFRACOST_API_KEY: $INFRACOST_API_KEY
    GITLAB_TOKEN: $GITLAB_TOKEN
  script:
    - echo "git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base"
    - git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base
    - cp ./infracost.yaml /tmp/base/infracost.yaml; cd /tmp/base
    - |
      infracost breakdown --config-file=./infracost.yaml \
      --format=json \
      --out-file=$CI_PROJECT_DIR/infracost-base.json
    - cd -
    - |
      infracost diff --config-file=./infracost.yaml \
      --compare-to=$CI_PROJECT_DIR/infracost-base.json \
      --format=json \
      --out-file=infracost.json
    - infracost comment gitlab --path infracost.json --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --gitlab-server-url $CI_SERVER_URL --gitlab-token $GITLAB_TOKEN --behavior update
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
👍 1