Skip to content

Commit

Permalink
POL-1373 Update AWS Superseded EBS Volumes - fix incorrect "New Month…
Browse files Browse the repository at this point in the history
…ly List Price" value (#2708)

* added changes to aws price list api request - doing an iterate for each region to ensure we capture all list price data for gp3 ebs volumes

* remove console.logs used for testing

* updated template version

* updated changelog to reflect the change

* change order of paramaters in datasource to be compliant

* fix template name

* Update Meta Parent Policy Templates (#2710)

Co-authored-by: nia-vf1 <nia-vf1@users.noreply.github.com>

* change order of parameters in datasource again

* Update Policy Master Permissions List (#2711)

Co-authored-by: nia-vf1 <nia-vf1@users.noreply.github.com>

* remove blank space on line 670

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: nia-vf1 <nia-vf1@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent ec5590c commit f119722
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cost/aws/superseded_ebs_volumes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v6.3.1

- Fixed issue where `New Monthly List Price` and `Estimated Monthly Savings` were being incorrectly reported in the policy incident.

## v6.3.0

- Added `Resource ARN` to incident table.
Expand Down
51 changes: 41 additions & 10 deletions cost/aws/superseded_ebs_volumes/aws_superseded_ebs_volumes.pt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name "AWS Superseded EBS Volumes"
rs_pt_ver 20180301
type "policy"
Expand All @@ -8,7 +7,7 @@ severity "low"
category "Cost"
default_frequency "weekly"
info(
version: "6.3.0",
version: "6.3.1",
provider: "AWS",
service: "Compute",
policy_set: "Inefficient Disk Usage",
Expand Down Expand Up @@ -565,20 +564,47 @@ script "js_volumes_tag_filtered", type: "javascript" do
EOS
end

# Get list of Volume regions for Pricing API requests
datasource "ds_volume_regions_list" do
run_script $js_volume_regions_list, $ds_volumes_tag_filtered
end

script "js_volume_regions_list", type: "javascript" do
parameters "ds_volumes_tag_filtered"
result "result"
code <<-EOS
result = _.uniq(_.pluck(ds_volumes_tag_filtered, "region"))
EOS
end

datasource "ds_gp2_prices" do
iterate $ds_volume_regions_list
request do
run_script $js_volume_prices, $ds_aws_api_hosts, "gp2"
run_script $js_volume_prices, iter_item, $ds_aws_api_hosts, "gp2"
end
result do
encoding "json"
collect jmes_path(response, "PriceList") do
field "priceList", jmes_path(col_item, "@")
end
end
end

datasource "ds_gp3_prices" do
iterate $ds_volume_regions_list
request do
run_script $js_volume_prices, $ds_aws_api_hosts, "gp3"
run_script $js_volume_prices, iter_item, $ds_aws_api_hosts, "gp3"
end
result do
encoding "json"
collect jmes_path(response, "PriceList") do
field "priceList", jmes_path(col_item, "@")
end
end
end

script "js_volume_prices", type: "javascript" do
parameters "ds_aws_api_hosts", "volumeApiName"
parameters "volume_region", "ds_aws_api_hosts", "volumeApiName"
result "request"
code <<-EOS
var request = {
Expand All @@ -603,6 +629,11 @@ script "js_volume_prices", type: "javascript" do
"Type": "TERM_MATCH",
"Field": "volumeApiName",
"Value": volumeApiName
},
{
"Type": "TERM_MATCH",
"Field": "regionCode",
"Value": volume_region
}
],
"FormatVersion": "aws_v1",
Expand All @@ -623,11 +654,11 @@ script "js_volumes_with_prices", type: "javascript" do
result "result"
code <<-EOS
// Function to convert price lists to proper JSON
function convertPriceList(priceList) {
function convertPriceList(prices) {
convertedPriceList = {}
_.each(priceList, function(price) {
entry = JSON.parse(price.replace(/\\"/g, '"'))
_.each(prices, function(price) {
entry = JSON.parse(price.priceList.replace(/\\"/g, '"'))
region = entry['product']['attributes']['regionCode']
if (convertedPriceList[region] == undefined) {
Expand Down Expand Up @@ -721,8 +752,8 @@ script "js_volumes_with_prices", type: "javascript" do
}
result = []
gp2_pricelist = convertPriceList(ds_gp2_prices['PriceList'])
gp3_pricelist = convertPriceList(ds_gp3_prices['PriceList'])
gp2_pricelist = convertPriceList(ds_gp2_prices)
gp3_pricelist = convertPriceList(ds_gp3_prices)
_.each(ds_volumes_tag_filtered, function(volume) {
gp2_price = getGP2Price(volume, gp2_pricelist) * ds_currency['exchange_rate']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "AWS",
version: "6.3.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "6.3.1", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@
{
"id": "./cost/aws/superseded_ebs_volumes/aws_superseded_ebs_volumes.pt",
"name": "AWS Superseded EBS Volumes",
"version": "6.3.0",
"version": "6.3.1",
"providers": [
{
"name": "aws",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@
required: true
- id: "./cost/aws/superseded_ebs_volumes/aws_superseded_ebs_volumes.pt"
name: AWS Superseded EBS Volumes
version: 6.3.0
version: 6.3.1
:providers:
- :name: aws
:permissions:
Expand Down

0 comments on commit f119722

Please sign in to comment.