From 53064cd27d862138cf1aa5b523a3ef2179174411 Mon Sep 17 00:00:00 2001 From: dstecholution <96495336+dstecholution@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:40:29 -0500 Subject: [PATCH 1/2] Update main.yml --- .github/workflows/main.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca86467..53e6ba8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -112,14 +112,20 @@ jobs: if: steps.plan.outcome == 'failure' run: exit 1 - - name: Snyk scan + - name: Setup snyk uses: snyk/actions/setup@master + + - name: IaC Test run: snyk iac test env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - name: Report infrastructure costs + - name: setup infracost uses: infracost/actions/setup@v2 + + - name: Report on IaC Costs + env: + INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }} run: | infracost breakdown --path=. \ --format=json \ @@ -134,8 +140,6 @@ jobs: --compare-to=infracost-base.json \ --format=json \ --out-file=infracost.json - with: - api-key: ${{ secrets.INFRACOST_API_KEY }} - name: 'Sentinel Test' uses: hashicorp/sentinel-github-actions@master @@ -147,8 +151,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Terraform Apply if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve From a3176dc11b70418ee03d623a40a9642e2ca1f0e8 Mon Sep 17 00:00:00 2001 From: dstecholution <96495336+dstecholution@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:42:07 -0500 Subject: [PATCH 2/2] Create policy.policy --- policy/policy.policy | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 policy/policy.policy diff --git a/policy/policy.policy b/policy/policy.policy new file mode 100644 index 0000000..3053b4f --- /dev/null +++ b/policy/policy.policy @@ -0,0 +1,47 @@ +import "strings" + +limitTotalDiff = rule { + float(breakdown.totalMonthlyCost) < 1500 +} + +awsInstances = filter breakdown.projects[0].breakdown.resources as _, resource { + strings.split(resource.name, ".")[0] is "aws_instance" +} + +limitInstanceCost = rule { + all awsInstances as _, instance { + float(instance.hourlyCost) <= 2.00 + } +} + +instanceBaseCost = func(instance) { + cost = 0.0 + for instance.costComponents as cc { + cost += float(cc.hourlyCost) + } + return cost +} + +instanceIOPSCost = func(instance) { + cost = 0.0 + for instance.subresources as sr { + for sr.costComponents as cc { + if cc.name == "Provisioned IOPS" { + cost += float(cc.hourlyCost) + } + } + } + return cost +} + +limitInstanceIOPSCost = rule { + all awsInstances as _, instance { + instanceIOPSCost(instance) <= instanceBaseCost(instance) + } +} + +main = rule { + limitTotalDiff and + limitInstanceCost and + limitInstanceIOPSCost +}