Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ This is not an official HashiCorp product.
- [x] Optionally, using [cost.modules.tf](https://cost.modules.tf/)
- [x] Can be executed on restricted CI/CD platforms where Terraform can run


## Supported resources

1. EC2 instances (on-demand) and Autoscaling Groups (Launch Configurations and Launch Templates):
- [x] aws_instance
- [ ] aws_autoscaling_group
- [ ] aws_launch_configuration
- [ ] aws_launch_template

2. EC2 Fleets (on-demand)
- [ ] aws_ec2_fleet

3. EBS Volumes, Snapshots, Snapshot Copies
- [x] aws_ebs_volume
- [x] aws_ebs_snapshot
- [x] aws_ebs_snapshot_copy

4. Elastic Load Balancing (ELB, ALB, NLB)
- [x] aws_elb
- [x] aws_alb / aws_lb

5. NAT Gateways
- [x] aws_nat_gateway

6. Redshift Clusters
- [x] aws_redshift_cluster


## Usages

### Using AWS Pricing API: Terraform state or plan as JSON
Expand Down Expand Up @@ -134,8 +162,9 @@ When you use this type of backend, there is no way to run `terraform output`.

### Known issues/limitations

1. Autoscaling groups resources
1. When changing values price is sometimes higher after the first run because it is calculated based on keys and there can be some previous keys. Solution is to update code to include some unique key/prefix. Or just disable terraform state (no state = no past).
2. At some point later, maybe add support for other providers like [Azure](http://davecallan.com/azure-price-api-examples/) and [Google Cloud](https://stackoverflow.com/questions/59048071/how-to-get-gcp-pricing-list-from-catalogue-api)
1. At some point later, maybe add support for other providers like [Azure](http://davecallan.com/azure-price-api-examples/) and [Google Cloud](https://stackoverflow.com/questions/59048071/how-to-get-gcp-pricing-list-from-catalogue-api)


## Examples
Expand Down
286 changes: 280 additions & 6 deletions dev/aws_pricing.md

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions dev/calculate_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Run all AWS CLI commands and verify that 1 result is returned
# Make sure to run: terraform apply (with `local.debug_output = true` to populate aws_cli_commands)

set +e # do not exit on bad exit code

aws_cli_commands=$(terraform output -json aws_cli_commands | jq -r '.[] | gsub("[\\n\\t]"; "")')

while IFS=$'\n' read -ra commands; do
for one in "${commands[@]}"; do
printf '%*s\n' 58 | tr ' ' '-'
echo $one
result=$(/bin/bash -c "$one")
exit_code=$?

if [ $exit_code -ne 0 ]; then
echo "Error!"
continue
fi

products=$(echo $result | jq -r '.PriceList | length')

if [ $products -eq 0 ]; then
echo "0 products found. Expected 1!"
elif [ $products -ne 1 ]; then
echo "$products products found. Expected 1!"
echo $result | jq -r '.PriceList[0] | fromjson | .product'
echo $result | jq -r '.PriceList[1] | fromjson | .product'
else
echo "OK!"
echo $result | jq -r '.PriceList[0] | fromjson | .terms.OnDemand[].priceDimensions[].pricePerUnit.USD'
echo $result | jq -r '.PriceList[0] | fromjson | .product'
fi

done
done <<< "$aws_cli_commands"

22 changes: 0 additions & 22 deletions dev/filters.json

This file was deleted.

Loading