Hi , I have my state file on gitlab , right now i ...
# help
r
Hi , I have my state file on gitlab , right now i have to download the state and do infracost breakdown with that state file , is there a way we can directly reference the statefile in remote state in git lab ?
l
@rough-lamp-14794 unfortunately not at the moment. We process the state JSON format, so need you to run
terraform show -json
first.
r
so , i need to download the statefile then run
terraform show -json
and then run breakdonw ?
l
Yes, or you can run Infracost directly on your source repo using
infracost breakdown --path=path/to/repo
r
My aim is to run
infracost diff
in my git lab pipeline which store the state in gitlab. I am able to do the breakdown it is good , I want to do the diff on my feature branch whenever i update the code . right now i am downloading the state form gitlab and doing below download the existing statefile {prj}-{env}-{target}.json mv {prj}-{env}-{target}.json terraform.tfstate terraform show -json > {prj}-{env}-{target}-state.json infracost breakdown --path statefile {prj}-{env}-{target}-state.json --format json --out-file estimate-{prj}-{env}-{target}-state.json rm terraform.tfstate infracost diff --path . --compare-to {prj}-{env}-{target}-state is there any better way ? so that i can avoide the statefile download using api call?
l
@rough-lamp-14794 I’d recommend either: 1. Using the GitLab App: https://www.infracost.io/docs/integrations/gitlab_app/ which should handle all of this for you 2. Using one of our GitLab CI examples: https://gitlab.com/infracost/infracost-gitlab-ci