bumpy-wall-81758
09/23/2024, 4:46 AMinfracost-usage.yml
where my resource is google_compute_instance
now all I want is that I want to put usage in a way that it will be running only for 8 hours a day rather 24 hours a day. How do I achieve this, I checked org setttings and usage but I did not find the relevant field.
Also, below is the result of one of my merge request, not sure why it is not in proper table i.e. you see how new monthly cost has nothing under it..white-airport-8778
resource_usage
or all VMs using resource_type_default_usage
bumpy-wall-81758
09/23/2024, 5:12 AMimage: dipkmish/terraform:v1.9.3
variables:
GOOGLE_PROJECT: $GOOGLE_PROJECT
SERVICE_ACCOUNT: "$GOOGLE_CREDENTIALS"
TF_STATE_BUCKET: "infracost-state-bucket"
TF_STATE_PREFIX: "terraform/state"
INFRACOST_API_KEY: $INFRACOST_API_KEY
TF_ROOT: terraform
TOKEN: $GITLAB_TOKEN
stages:
- validate
- plan
- infracost
- apply
- destroy
before_script:
- rm -rf .terraform
- terraform --version
- export GCP_KEY='${SERVICE_ACCOUNT}'
- echo "$GCP_KEY" > /tmp/gcpkey.json
- export GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcpkey.json
- cd terraform
- terraform init -reconfigure -get=true -upgrade=true -backend-config=bucket=${TF_STATE_BUCKET} -backend-config=prefix=${TF_STATE_PREFIX} -no-color
infracost-report:
stage: infracost
image:
name: infracost/infracost:ci-0.10
entrypoint: [""]
before_script: []
script:
# Clone the base branch of the pull request (e.g. main/master) into a temp directory.
- git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base
# Generate an Infracost cost snapshot from the comparison branch, so that Infracost can compare the cost difference.
- infracost breakdown --path /tmp/base/${TF_ROOT} --usage-file infracost-usage.yml --format json --out-file=infracost-base.json
- infracost output --path infracost-base.json --format html > infracost_report.html
# Generate an Infracost diff and save it to a JSON file.
- infracost diff --path . --usage-file infracost-usage.yml --compare-to infracost-base.json --format=json --out-file=infracost.json
# Posts a comment to the PR using the 'update' behavior.
- infracost comment gitlab --path infracost.json --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --gitlab-server-url $CI_SERVER_URL --gitlab-token $TOKEN --behavior=update
artifacts:
paths:
- infracost_report.html
# - infracost_report_usage.html
expire_in: never
only:
- merge_requests
# Run Infracost on default branch and update Infracost Cloud
infracost:default-branch-update:
stage: infracost
image:
name: infracost/infracost:ci-0.10
entrypoint: [""]
before_script: []
script:
- |
infracost breakdown --path ${TF_ROOT} \
--format=json \
--out-file=infracost.json
infracost upload --path infracost.json
variables:
INFRACOST_API_KEY: $INFRACOST_API_KEY
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Set the MR status to Merged in Infracost Cloud
infracost:merge-request-status-update:
stage: infracost
image:
name: infracost/infracost:ci-0.10
entrypoint: [""]
before_script: []
script:
- |
# Extract Merge Request ID from the Commit Message
if [[ ${CI_COMMIT_MESSAGE} =~ ${PATTERN} ]]; then
MR_ID=${BASH_REMATCH[1]};
else
echo "${VTY_RB}Unable to extract Merge Request ID${VTY_P}"; exit 1;
fi
curl \
--request POST \
--header "Content-Type: application/json" \
--header "X-API-Key: ${INFRACOST_API_KEY}" \
--data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"${CI_PROJECT_URL}/merge_requests/${MR_ID}\\\", status: MERGED )}\" }" \
"<https://dashboard.api.infracost.io/graphql>";
variables:
PATTERN: "See merge request.+?!([0-9]+)"
INFRACOST_API_KEY: $INFRACOST_API_KEY
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_TITLE =~ /^Merge branch/
validate:
stage: validate
script:
- terraform validate
plan:
stage: plan
script:
- terraform plan -var-file="terraform.tfvars" -out=tfplan
artifacts:
paths:
- terraform/tfplan
apply:
stage: apply
needs:
- plan
script:
- terraform apply -auto-approve tfplan
when: manual
destroy:
stage: destroy
needs:
- plan
script:
- terraform destroy -var-file="terraform.tfvars" -auto-approve
when: manual
white-airport-8778
bumpy-wall-81758
09/23/2024, 5:20 AMbumpy-wall-81758
09/23/2024, 5:21 AMbumpy-wall-81758
09/23/2024, 5:25 AMbumpy-wall-81758
09/23/2024, 5:39 AMbumpy-wall-81758
09/23/2024, 1:43 PMbumpy-wall-81758
09/23/2024, 1:45 PMbumpy-wall-81758
09/23/2024, 2:40 PMwhite-airport-8778
bumpy-wall-81758
09/23/2024, 3:47 PM