Hi, we are looking to do a POC on this tool as it ...
# help
m
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
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:
Copy code
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.
Copy code
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
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
👍
m
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.
Copy code
- checkout: self
        persistCredentials: true
m
are you using azure repos or github?
m
Azure repos
m
what does your
infracost comment
command look like?
m
I am only using what is in the example provided for the whole pipeline.
m
that is using
github
m
Azure pipelines
m
yes but the example posts to github repo
you need to change it to azure repos
so the command would look something like:
Copy code
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
ah okay, then its not even getting to that stage. As it fails on Checkout base branch
m
so this step:
Copy code
# 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:
Copy code
- 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
I found it, I was missing the following as the multi-project-config-file example didn't give the suggested option
Copy code
--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
Copy code
- path: env
    include_all_paths: true # include root and non-root modules
    name: POD - DELP
    env:
      environment: delp
      geo: us
      purpose: devqa
To
Copy code
- 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
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
Yes they were working fine beforehand the only change was from env to terraform_vars. It does seem very odd
m
so you managed to get a PR comment in your PR?
m
Yep if I use the following, works fine no problem
Copy code
- path: env
    include_all_paths: true # include root and non-root modules
    name: POD - DELP
    env:
      environment: delp
      geo: us
      purpose: devqa
m
ok have you committed the updated infracost.yml into your main branch?
m
ah okay that could be it
m
it could be because of conflicts between the config files
m
That would make sense
I just walk away now 😞
m
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
That fixed it 🙂 thanks again
m
🚀
m
if we wanted to request a resource type to be added is it best to do a issue per resource request? e.g.
Copy code
azurerm_windows_function_app
and
Copy code
azurerm_route_table
m
yes please