Title
#help
s

sahaja

11/07/2022, 4:17 PM
but it still saying no terraform files found
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:18 PM
HI @sahaja what does your
path/to/terragrunt/repo
contain? Are there any
.tf
,
.tf.json
or
.hcl
files in that folder?
s

sahaja

11/07/2022, 4:18 PM
.hcl files
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:19 PM
and does your top level terragrunt project contain a
terragrunt.hcl
file?
s

sahaja

11/07/2022, 4:20 PM
at root level or where jenkins file is located?
4:21 PM
yes- at jenkins file directory level, and NO at root directory
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:21 PM
we basically need a root terragrunt configuration under the
path/to/terragrunt/repo
path
4:22 PM
either of the above options should work
4:22 PM
Terragrunt figures out the path to its config file according to the following rules:
4:22 PM
1. The value of the
--terragrunt-config
command-line option, if specified.
2. The value of the
TERRAGRUNT_CONFIG
environment variable, if defined.
3. A
terragrunt.hcl
file in the current working directory, if it exists.
4. A
terragrunt.hcl.json
file in the current working directory, if it exists.
5. If none of these are found, exit with an error.
4:23 PM
we however, do not support
terragrunt-config
4:23 PM
infracost breakdown --path
should point to either the path where your
terragrunt.hcl
lives
s

sahaja

11/07/2022, 4:29 PM
so we need to have terragrunt at root level to run infracost against it?
4:30 PM
the error i am getting is something like ” root/app/dir/terragrunt.hcl’ thats the directory and
4:31 PM
its searching for terragrunt.hcl at ‘root/app/’
4:31 PM
but i dont have any terragrunt.hcl files at “root/app”
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:31 PM
i’m sorry I’m confused as to what your error is
4:31 PM
can you post the output from the
infracost breakdown
is?
4:32 PM
if your
terragrunt.hcl
lives at the root directory, running
infracost breakdown --path .
should work
s

sahaja

11/07/2022, 4:35 PM
msg=Error reading file at path /home/jenkins/agent/workspace/PR/root/dir/env/terragrunt.hcl: open /home/jenkins/agent/workspace/PR/root/dir/env/terragrunt.hcl: no such file or directory
4:36 PM
infracost breakdown --path plan.json --format json --out-file infracost.json
4:36 PM
this is the command i am running
4:36 PM
and we dont have terragrunt.hcl at the place where infracost is seraching for.. terragrunt exists at path
4:37 PM
home/jenkins/agent/workspace/PR/root/dir/env/module/terragrunt.hcl:
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:37 PM
infracost breakdown --path plan.json --format json --out-file infracost.json
^ this doesn’t look correct - this is pointing to a plan JSON. Are you running another infracost cmd?
4:38 PM
@sahaja how do you run terragrunt in your Jenkins pipeline?
s

sahaja

11/07/2022, 4:38 PM
so can i run directly this ” infracost breakdown --path=home/jenkins/agent/workspace/PR/root/dir/env/module/terragrunt.hcl ”
4:39 PM
terragrunt run-all plan -out=tfplan
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:39 PM
^ this command is run in which directory?
s

sahaja

11/07/2022, 4:41 PM
home/jenkins/agent/workspace/PR/root/dir
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 4:43 PM
1. So if you run
infracost breakdown --path /home/jenkins/agent/workspace/PR/root/dir
what is the error/output 2. if this errors - try running
infracost breakdown --path /home/jenkins/agent/workspace/PR/root/dir --terraform-force-cli
s

sahaja

11/07/2022, 4:43 PM
okay let me try running 2nd one..and update
6:02 PM
this is the error i am getting
6:03 PM
infracost breakdown --path /home/jenkins/agent/workspace/PR/root/dir/env/ --terraform-force-cli
 time="2022-11-07T17:47:08Z" level=info msg="Detected Terraform CLI at /home/jenkins/agent/workspace/PR/root/dir/env/"
 time="2022-11-07T17:47:08Z" level=info msg="Starting: Running terraform plan"

 Error: terraform plan failed: exit status 1

   Terraform command failed with:
     Error: No configuration files
     Plan requires configuration to be present. Planning without a configuration
     would mark everything for destruction, which is normally not what is desired.
     If you would like to destroy everything, run plan with the -destroy option.
     Otherwise, create a Terraform configuration file (.tf file) and try again.
Hugo (Infracost)

Hugo (Infracost)

11/07/2022, 7:57 PM
infracost breakdown --path /home/jenkins/agent/workspace/PR/root/dir --terraform-force-cli
needs to point to the directory with the
terragrunt.hcl
file. It seems you are running it in the
/home/jenkins/agent/workspace/PR/root/dir/env/
directory
s

sahaja

11/08/2022, 4:09 AM
i actually have generated a terragrunt plan and then trying to output that json file ..something like this’
4:11 AM
1. terragrunt run-all plan -out=tfplan | tee output.log 2. terragrunt run-all show -json output.log > tfplan.json 3. infracost breakdown --path tfplan.json --format json --out-file infracost.json
4:11 AM
But this is throwing up some errors
4:22 AM
Error: Failed to read the given file as a state or plan file
│ 
│ State read error: Error loading statefile: open output.log: no such file or
│ directory
│ 
│ Plan read error: open output.log: no such file or directory
╵
Hugo (Infracost)

Hugo (Infracost)

11/08/2022, 6:44 AM
I'm not sure what the error here is but terra grunt plans and notoriously flaky to try and parse. We have a guide here https://www.infracost.io/docs/troubleshooting/ that might helpyou generate one that infracost can consume
s

sahaja

11/09/2022, 12:21 AM
Hi.. i do see that the project is uploaded to infracost..
12:21 AM
But it shows 0 cost estimate
12:22 AM
12:22 AM
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 8:30 AM
@sahaja do you have access to this infra project locally or are you only able to access it in the Jenkins pipeline? If the former - could you run the steps terragrunt bash steps locally and paste the output of an
infracost breakdown
using this plan
s

sahaja

11/09/2022, 3:00 PM
Name Monthly Qty Unit Monthly Cost OVERALL TOTAL $0.00 ──────────────────────────────────
3:00 PM
after running locally
4:23 PM
HI.. i got it
4:23 PM
But can u help me with how can i get the estimates for the PR diff
4:24 PM
4:24 PM
nothing is uploaded for PR
4:24 PM
i am looking at this , pls correct me if there is something else i have to look at
4:25 PM
infracost comment github --path "infracost.json" ...

 infracost upload --path infracost.json
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:25 PM
infracost comment
should upload the results of the PR for you, so you don’t need a
upload
step
4:26 PM
okay great thanks
4:26 PM
i will try that
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:26 PM
let me check that your org is setup correctly because we should have the PR here if you’re using
comment
s

sahaja

11/09/2022, 4:27 PM
ok
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:27 PM
what is the organization id of your Infracost Cloud organization?
s

sahaja

11/09/2022, 4:27 PM
sundavalli
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:33 PM
yeah from the looks of it you haven’t implemented the
infracost comment
step yet right?
s

sahaja

11/09/2022, 4:33 PM
i have implement just now
4:33 PM
completed now
4:34 PM
Error: required flag(s) "github-token", "repo" not set
4:34 PM
i am getting this error
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:34 PM
infracost comment github --path=infracost.json \
    --repo=$GITHUB_REPOSITORY \
    --pull-request=$PR_NUMBER `# or --commit=$GITHUB_SHA` \
    --github-token=$GITHUB_TOKEN \
    --behavior=update
s

sahaja

11/09/2022, 4:34 PM
so i have to set up github token in jenkins ?
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:34 PM
yes you’ll need a github token setup in the pipeline if you want the comment in the PR
4:35 PM
I’m assuming you’ve seen this example we have for jenkins: https://github.com/infracost/infracost-jenkins
s

sahaja

11/09/2022, 4:36 PM
yes i did
4:41 PM
HI quick question
4:41 PM
does it only publish to public github.com or can it also do private GHE
4:41 PM
?
Hugo (Infracost)

Hugo (Infracost)

11/09/2022, 4:44 PM
yes it can handle GHE
4:44 PM
but you’ll need to set the API url for your private GHE using the
--github-api-url
flag on
comment