broad-zoo-34077
11/02/2023, 7:00 PMcrooked-daybreak-55253
11/02/2023, 7:40 PMinfracost diff
to generate an infracost_${PROJECT}.json
for each child and save it as an artifiact.
2. have a final step that calls infracost comment gitlab
passing in all the previously generated jsons as the path (for example, as a glob --path="infracost_*.json"
echoing-piano-29088
11/02/2023, 7:40 PMechoing-piano-29088
11/02/2023, 7:40 PMechoing-piano-29088
11/02/2023, 8:54 PMxecuting busybox-1.35.0-r17.trigger
OK: 85 MiB in 44 packages
$ echo -e "credentials \"$CI_SERVER_HOST\" {\n token = \"$CI_JOB_TOKEN\"\n}" > $TF_CLI_CONFIG_FILE
$ infracost comment gitlab --path="infracost-*.json" \ # collapsed multi-line command
time="2023-11-02T20:44:20Z" level=info msg="Enabled policies V2"
time="2023-11-02T20:44:20Z" level=info msg="Enabled tag policies"
Post an Infracost comment to GitLab
USAGE
infracost comment gitlab [flags]
EXAMPLES
Update comment on a merge request:
infracost comment gitlab --repo my-org/my-repo --merge-request 3 --path infracost.json --gitlab-token $GITLAB_TOKEN
Post a new comment to a commit:
infracost comment gitlab --repo my-org/my-repo --commit 2ca7182 --path infracost.json --behavior delete-and-new --gitlab-token $GITLAB_TOKEN
FLAGS
--behavior string Behavior when posting comment, one of:
update (default) Update latest comment
new Create a new comment
delete-and-new Delete previous matching comments and create a new comment (default "update")
--commit string Commit SHA to post comment on, mutually exclusive with merge-request
--dry-run Generate comment without actually posting to GitLab
--gitlab-server-url string GitLab Server URL (default "<https://gitlab.com>")
--gitlab-token string GitLab token
-h, --help help for gitlab
--merge-request int Merge request number to post comment on, mutually exclusive with commit
-p, --path stringArray Path to Infracost JSON files, glob patterns need quotes
--policy-path stringArray Path to Infracost policy files, glob patterns need quotes (experimental)
--repo string Repository in format owner/repo
--show-all-projects Show all projects in the table of the comment output
--show-skipped List unsupported and free resources
--tag string Customize hidden markdown tag used to detect comments posted by Infracost
GLOBAL FLAGS
--debug-report Generate a debug report file which can be sent to Infracost team
--log-level string Log level (trace, debug, info, warn, error, fatal)
--no-color Turn off colored output
Error: either --commit or --merge-request is required
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
echoing-piano-29088
11/02/2023, 8:54 PMinfracost_comment:
stage: infracost_comment
image:
# Always use the latest 0.10.x version to pick up bug fixes and new resources.
# See <https://www.infracost.io/docs/integrations/cicd/#docker-images> for other options
name: infracost/infracost:ci-0.10
entrypoint: [""] # Override since we're running commands below
script:
- |
infracost comment gitlab --path="infracost-*.json" \
--repo=$CI_PROJECT_PATH \
--merge-request=$CI_MERGE_REQUEST_IID \
--gitlab-server-url=$CI_SERVER_URL \
--gitlab-token=$GITLAB_TOKEN \
--behavior=update
when: manual
crooked-daybreak-55253
11/02/2023, 9:03 PMrules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
echoing-piano-29088
11/03/2023, 2:02 PMechoing-piano-29088
11/03/2023, 3:29 PM{"code":0,"message":"Invalid API key\nPlease check your /root/.config/infracost/credentials.yml file or INFRACOST_API_KEY environment variable.\nIf you recently regenerated your API key, you can retrieve it from <https://dashboard.infracost.io>.\nSee <https://infracost.io/support> if you continue having issues.","data":null}]
even tried regenerating token from Ifracost dashboard today and putting in gitlab, and still getting that error.
also still running into the artifacts/globbing issues
$ echo -e "credentials \"$CI_SERVER_HOST\" {\n token = \"$CI_JOB_TOKEN\"\n}" > $TF_CLI_CONFIG_FILE
$ infracost comment gitlab --path="infracost-*.json" \ # collapsed multi-line command
time="2023-11-03T15:10:07Z" level=info msg="Enabled policies V2"
time="2023-11-03T15:10:07Z" level=info msg="Enabled tag policies"
Error: could not load input file infracost-*.json err: Infracost JSON file does not exist, generate it by running the following command then try again:
infracost breakdown --path /code --format json --out-file infracost-base.json
crooked-daybreak-55253
11/03/2023, 3:31 PMechoing-piano-29088
11/03/2023, 3:31 PMechoing-piano-29088
11/03/2023, 3:33 PMechoing-piano-29088
11/03/2023, 3:33 PMcrooked-daybreak-55253
11/03/2023, 3:35 PM...
3. Create a project environment variable called INFRACOST_API_KEY with your API key. This should be masked. To make sure this can be used on all merge requests untick the 'Protect variable' option.
Maybe check that the protect variable is unticked?echoing-piano-29088
11/03/2023, 3:36 PMcrooked-daybreak-55253
11/03/2023, 3:38 PMechoing-piano-29088
11/03/2023, 3:39 PMechoing-piano-29088
11/03/2023, 3:39 PMechoing-piano-29088
12/04/2023, 10:04 PMcrooked-daybreak-55253
12/04/2023, 10:12 PMvariables:
INFRACOST_API_KEY: $INFRACOST_API_KEY
echoing-piano-29088
12/05/2023, 3:18 AMechoing-piano-29088
12/05/2023, 1:23 PM"INFRACOST_API_KEY": {
"value": "$INFRACOST_API_KEY"
},
crooked-daybreak-55253
12/05/2023, 1:53 PMechoing-piano-29088
12/05/2023, 1:55 PM