but it still saying no terraform files found
# help
f
but it still saying no terraform files found
m
HI @fresh-refrigerator-73809 what does your
path/to/terragrunt/repo
contain? Are there any
.tf
,
.tf.json
or
.hcl
files in that folder?
f
.hcl files
m
and does your top level terragrunt project contain a
terragrunt.hcl
file?
f
at root level or where jenkins file is located?
yes- at jenkins file directory level, and NO at root directory
m
we basically need a root terragrunt configuration under the
path/to/terragrunt/repo
path
either of the above options should work
Terragrunt figures out the path to its config file according to the following rules:
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.
we however, do not support
terragrunt-config
infracost breakdown --path
should point to either the path where your
terragrunt.hcl
lives
f
so we need to have terragrunt at root level to run infracost against it?
the error i am getting is something like ” root/app/dir/terragrunt.hcl’ thats the directory and
its searching for terragrunt.hcl at ‘root/app/’
but i dont have any terragrunt.hcl files at “root/app”
m
i’m sorry I’m confused as to what your error is
can you post the output from the
infracost breakdown
is?
if your
terragrunt.hcl
lives at the root directory, running
infracost breakdown --path .
should work
f
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
Copy code
infracost breakdown --path plan.json --format json --out-file infracost.json
this is the command i am running
and we dont have terragrunt.hcl at the place where infracost is seraching for.. terragrunt exists at path
Copy code
home/jenkins/agent/workspace/PR/root/dir/env/module/terragrunt.hcl:
m
Copy code
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?
@fresh-refrigerator-73809 how do you run terragrunt in your Jenkins pipeline?
f
so can i run directly this ” infracost breakdown --path=home/jenkins/agent/workspace/PR/root/dir/env/module/terragrunt.hcl ”
Copy code
terragrunt run-all plan -out=tfplan
m
^ this command is run in which directory?
f
home/jenkins/agent/workspace/PR/root/dir
m
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
f
okay let me try running 2nd one..and update
this is the error i am getting
Copy code
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.
m
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
f
i actually have generated a terragrunt plan and then trying to output that json file ..something like this’
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
But this is throwing up some errors
Copy code
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
╵
m
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
f
Hi.. i do see that the project is uploaded to infracost..
But it shows 0 cost estimate
message has been deleted
message has been deleted
m
@fresh-refrigerator-73809 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
f
Name Monthly Qty Unit Monthly Cost OVERALL TOTAL $0.00 ──────────────────────────────────
after running locally
HI.. i got it
But can u help me with how can i get the estimates for the PR diff
message has been deleted
nothing is uploaded for PR
i am looking at this , pls correct me if there is something else i have to look at
Copy code
infracost comment github --path "infracost.json" ...

 infracost upload --path infracost.json
m
infracost comment
should upload the results of the PR for you, so you don’t need a
upload
step
okay great thanks
i will try that
m
let me check that your org is setup correctly because we should have the PR here if you’re using
comment
f
ok
m
what is the organization id of your Infracost Cloud organization?
f
sundavalli
m
yeah from the looks of it you haven’t implemented the
infracost comment
step yet right?
f
i have implement just now
completed now
Copy code
Error: required flag(s) "github-token", "repo" not set
i am getting this error
m
Copy code
infracost comment github --path=infracost.json \
    --repo=$GITHUB_REPOSITORY \
    --pull-request=$PR_NUMBER `# or --commit=$GITHUB_SHA` \
    --github-token=$GITHUB_TOKEN \
    --behavior=update
f
so i have to set up github token in jenkins ?
m
yes you’ll need a github token setup in the pipeline if you want the comment in the PR
I’m assuming you’ve seen this example we have for jenkins: https://github.com/infracost/infracost-jenkins
f
yes i did
HI quick question
does it only publish to public github.com or can it also do private GHE
?
m
yes it can handle GHE
but you’ll need to set the API url for your private GHE using the
--github-api-url
flag on
comment
164 Views