https://infracost.io logo
Title
m

millions-plumber-38090

03/03/2023, 8:13 AM
Hi, we are looking to do a POC on this tool as it looks great. Just a quick question, we use Azure Pipelines and we use variables to deploy our Iac
terraform plan -var 'geo=us' -var 'environment=ecos'
How can we build this into our pull requests to say env ecos cost X, env qa2 cost X, prod1 will cost X.
m

mysterious-teacher-68276

03/03/2023, 8:50 AM
Hi @millions-plumber-38090 , You’d need to use a config file for something like this: https://www.infracost.io/docs/features/config_file/ for example, based on the information provided, your config file would look something like this:
version: 0.1

projects:
  - path: path/to/your/project
    name: ecos
    env:
      environment: ecos
      geo: us

  - path: path/to/your/project
    name: prod
    env:
      environment: prod
      geo: eu
Then it would be a matter of pointing infracost to that config file, e.g.
infracost breakdown --config-file infracost.yml
But, if you’re using GitHub as your repository, I’d recommend using our GitHub app to run your POC with. It’s much easier to iterate on an means you don’t have to define loads of boilerplate in your Azure pipelines. Hope this helps
m

millions-plumber-38090

03/03/2023, 8:51 AM
Thanks Hugo, I did see the config file but wasn't sure how that would apply to us. I will have a go and reach out if we hit anymore issues.
m

mysterious-teacher-68276

03/03/2023, 8:51 AM
👍
m

millions-plumber-38090

03/03/2023, 10:39 AM
I am trying to set up the PR comment section now with an Azure pipeline but getting an error of
fatal: could not read Password for '<https://OrgName@dev.azure.com>': terminal prompts disabled
I am using the example provided here (https://github.com/infracost/infracost-azure-devops/tree/master/examples/multi-project-config-file) I copied and pasted as suggested by the documentation. I did also add the following in as suggested by some people.
- checkout: self
        persistCredentials: true
m

mysterious-teacher-68276

03/03/2023, 10:42 AM
are you using azure repos or github?
m

millions-plumber-38090

03/03/2023, 10:42 AM
Azure repos
m

mysterious-teacher-68276

03/03/2023, 10:42 AM
what does your
infracost comment
command look like?
m

millions-plumber-38090

03/03/2023, 10:43 AM
I am only using what is in the example provided for the whole pipeline.
m

mysterious-teacher-68276

03/03/2023, 10:43 AM
that is using
github
m

millions-plumber-38090

03/03/2023, 10:43 AM
Azure pipelines
m

mysterious-teacher-68276

03/03/2023, 10:43 AM
yes but the example posts to github repo
you need to change it to azure repos
so the command would look something like:
infracost comment azure-repos --repo-url <https://dev.azure.com/my-org/my-project/_git/my-repo> --pull-request 3 --path infracost.json --behavior new --azure-access-token $AZURE_ACCESS_TOKEN
m

millions-plumber-38090

03/03/2023, 10:44 AM
ah okay, then its not even getting to that stage. As it fails on Checkout base branch
m

mysterious-teacher-68276

03/03/2023, 10:46 AM
so this step:
# Clone the base branch of the pull request (e.g. main/master) into a temp directory.
      - bash: |
          branch=$(System.PullRequest.TargetBranch)
          branch=${branch#refs/heads/}
          git clone $(Build.Repository.Uri) --branch=${branch} --single-branch /tmp/base
        displayName: Checkout base branch
and you’ve added this:
- checkout: self
  persistCredentials: true
as the first step in the pipeline?
Hmm i’m not sure, this sounds like permission issues with the build agent
have you tried:
Grant version control permissions to the build service.
1. Go to project settings --> Repositories menu --> Your repository --> Security tab, and grant the following permissions to the
Project Collection Build Service ({your organization})
identity:
◦ Create branch: Allow
◦ Contribute: Allow
◦ Read: Allow
◦ Create tag: Allow
m

millions-plumber-38090

03/03/2023, 10:55 AM
I found it, I was missing the following as the multi-project-config-file example didn't give the suggested option
--config http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)
Sorry
Sorry again, Hugo, I got this all working fine, and then I changed my infracost.yml from
- path: env
    include_all_paths: true # include root and non-root modules
    name: POD - DELP
    env:
      environment: delp
      geo: us
      purpose: devqa
To
- path: env
    include_all_paths: true # include root and non-root modules
    name: POD - DELP
    terraform_vars:
      environment: delp
      geo: us
      purpose: devqa
Now when the PR build runs, it shows the error of
Error: The pull request comment was generated successfully but could not be posted:
Error creating comment: 400 Bad Request
When I run the CLI locally on the new terraform_vars it works fine.
m

mysterious-teacher-68276

03/03/2023, 1:57 PM
was comment working in your pipeline before the
terraform_vars
change? I don’t think changing these parameters would have any affect on the comment posting logic?
m

millions-plumber-38090

03/03/2023, 1:58 PM
Yes they were working fine beforehand the only change was from env to terraform_vars. It does seem very odd
m

mysterious-teacher-68276

03/03/2023, 1:59 PM
so you managed to get a PR comment in your PR?
m

millions-plumber-38090

03/03/2023, 1:59 PM
Yep if I use the following, works fine no problem
- path: env
    include_all_paths: true # include root and non-root modules
    name: POD - DELP
    env:
      environment: delp
      geo: us
      purpose: devqa
m

mysterious-teacher-68276

03/03/2023, 2:00 PM
ok have you committed the updated infracost.yml into your main branch?
m

millions-plumber-38090

03/03/2023, 2:00 PM
ah okay that could be it
m

mysterious-teacher-68276

03/03/2023, 2:00 PM
it could be because of conflicts between the config files
m

millions-plumber-38090

03/03/2023, 2:01 PM
That would make sense
I just walk away now 😞
m

mysterious-teacher-68276

03/03/2023, 2:03 PM
don’t worry, that is confusing - and something that we’re not happy with. Sadly, all of this UX is fixed with the GH app, but we’re yet to get round to azure repos
m

millions-plumber-38090

03/03/2023, 2:09 PM
That fixed it 🙂 thanks again
m

mysterious-teacher-68276

03/03/2023, 2:09 PM
🚀
m

millions-plumber-38090

03/03/2023, 2:27 PM
if we wanted to request a resource type to be added is it best to do a issue per resource request? e.g.
azurerm_windows_function_app
and
azurerm_route_table
m

mysterious-teacher-68276

03/03/2023, 2:27 PM
yes please