Help reduce the cost of an AWS infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
quentin.vallin 6c6966cb9d Merge pull request 'fix/random_break_datasource' (#5) from fix/randon_break_datasource into master 4 weeks ago
examples doc: update changelog 4 weeks ago
modules/instances fix: fixes unexisting local 2 months ago
.gitignore Initial commit 2 months ago
.pre-commit-config.yaml test: pins pre-commit to 1.39.0 1 month ago
CHANGELOG.md doc: update changelog 4 weeks ago
Jenkinsfile test: adds Jenkinsfile content 2 months ago
LICENSE doc: updates LICENCE 2 months ago
README.md fix: Wrong datasource idem potency 4 weeks ago
data.tf fix: Wrong datasource idem potency 4 weeks ago
main.tf fix: Wrong datasource idem potency 4 weeks ago
outputs.tf feat: handles EC2/RDS instances 2 months ago
variables.tf fix: Wrong datasource idem potency 4 weeks ago
versions.tf refactor: changes strategy to determine first run 1 month ago

README.md

Terraform module: cost optimization

For our dear end users: to disable what this module does, use the SSM Parameter toggle under /FXCostOptimizer/ in your AWS Account. Do not try to modify the code here to disable anything. Do not try to manually destroy resources neither.

By using this module, you can optimize the cost of an AWS infrastructure by:

  • Accessing a key/value store toggle so you can choose programmatically to destroy or stop resources
  • Letting the module handle stopping EC2/RDS instances according to the toggle
  • Ensure that the destroy state or the stopped state is kept even after manual operations
  • Setup schedule jobs to automatically stop resources at given time windows (NOT IMPLEMENTED YET)

Usage scenario

  1. This module creates a toggle SSM Parameter for cost optimization. This SSM Parameter value is left untouched by Terraform.
  2. This module will read the value of the SSM Parameter to decide whether or not to optimize the workload. Meaning: instances or data might be stopped or destroyed, depending on the variables user has set in this module.
  3. If SSM Parameter toggle value has changes since last apply, Terraform will take care of optimizing or restoring the normal state, according to the boolean.

Notes

  • The module will advertise the value of the SSM Parameter for cost optimization. Thus, you can make your own custom optimizations according to the value.
  • The module will create read only and read/write policy to get access to the SSM Parameter. This allows automations for changing the value of the SSM parameter.
  • This module can be disabled. It is highly recommended to disable this module in production environment so toggle nor any resources regarding cost optimization are created.

Limitations

  • This modules calls a shell script that calls terraform itself. Make sure sh is installed and that both software are correctly set in your OS environment paths. For more information on this limitation, see data.tf.
  • It’s not yet possible to use or import and external SSM Parameter to controle cost optimization.
  • AWS itself has some limitations to stop RDS instances.
  • Because this module with AWS lifecycle, it’s possible that an instances end up in an unwanted state. For example, if optimization is on, someone tried to start an instances, disable optimization and run Terraform, the instance might still be in “Stopping” state, resulting in a “Stopped” state instead of the expected “Running” state.

Requirements

Name Version
terraform >= 0.12.29
aws >= 2.58, < 4
external ~> 1.2
null ~> 2.1

Providers

Name Version
aws >= 2.58, < 4
external ~> 1.2
null ~> 2.1

Inputs

Name Description Type Default Required
cloudwatch_event_rule_ec2_instance_maintain_stop_name Name of the CloudWatch Rule that will assure that the cost-optimized EC2 instances stays stopped. string "FXCostOptimizerEC2MaintainStopRule" no
cloudwatch_event_rule_rds_instance_maintain_stop_name Name of the CloudWatch Rule that will assure that the cost-optimized RDS instances stays stopped. string "FXCostOptimizerRDSMaintainStopRule" no
cloudwatch_tags Tags to be shared among all the CloudWatch resources created by the module. Will be merged with var.tags. map {} no
ec2_instances_cloudwatch_event_iam_policy_name Name of the IAM Policy to create to trigger actions on the EC2 instances by CloudWatch events. string "FXCostOptimizerEC2InstanceActionsForCloudWatchEventsPolicy" no
ec2_instances_cloudwatch_event_iam_role_name Name of the IAM Role to allow CloudWatch Events to trigger SSM Automation actions on the EC2 instances. string "FXCostOptimizerEC2InstanceActionsForCloudWatchEventsRole" no
ec2_instances_count How many EC2 instances to act upon. Cannot compute automatically in Terraform 0.12. number 0 no
ec2_instances_ids IDs of the EC2 instances to act upon. list [] no
ec2_instances_ssm_automation_iam_policy_name Name of the IAM Policy to allow to stop EC2 instances from CloudWatch trigger. string "FXCostOptimizerEC2InstanceActionsForSSMAutomationPolicy" no
ec2_instances_ssm_automation_iam_role_name Name of the IAM Role to create to allow actions on the EC2 instances by SSM Automation. string "FXCostOptimizerEC2InstanceActionsForSSMAutomationRole" no
enabled Whether or not to enable this entire module or not bool true no
iam_role_tags Tags to be shared among all the IAM Role created by the module. Will be merged with var.tags. map {} no
manual_random_value A random value that must be unique, manually provided (no build-in function can be used) and with a minimum length of 10. string n/a yes
name Name that represent the workload or component name that will be cost-optimized. string "" no
prefix Prefix to use for all the named resources of the module. Mainly use for testing purpose. string "" no
rds_instances_cloudwatch_event_iam_policy_name Name of the IAM Policy to create to trigger actions on the RDS instances by CloudWatch events. string "FXCostOptimizerRDSInstanceActionsForCloudWatchEventsPolicy" no
rds_instances_cloudwatch_event_iam_role_name Name of the IAM Role to allow CloudWatch Events to trigger SSM Automation actions on the RDS instances. string "FXCostOptimizerRDSInstanceActionsForCloudWatchEventsRole" no
rds_instances_count How many RDS instances to act upon. Cannot compute automatically in Terraform 0.12. number 0 no
rds_instances_ids IDs of the RDS instances to act upon. list [] no
rds_instances_ssm_automation_iam_policy_name Name of the IAM Policy to allow to stop RDS instances from CloudWatch trigger. string "FXCostOptimizerRDSInstanceActionsForSSMAutomationPolicy" no
rds_instances_ssm_automation_iam_role_name Name of the IAM Role to create to allow actions on the RDS instances by SSM Automation. string "FXCostOptimizerRDSInstanceActionsForSSMAutomationRole" no
ssm_association_ec2_instances_start Name of the SSM Association to wake up the EC2 instance string "FXCostOptimizerEC2Start" no
ssm_association_ec2_instances_stop Name of the SSM Association to shut down the EC2 instance string "FXCostOptimizerEC2Stop" no
ssm_association_rds_instances_start Name of the SSM Association to wake up the RDS instance string "FXCostOptimizerRDSStart" no
ssm_association_rds_instances_stop Name of the SSM Association to shut down the RDS instance string "FXCostOptimizerRDSStop" no
ssm_parameter_tags Tags to be shared among all the SSM Parameters created by the module. Will be merged with var.tags. map {} no
ssm_parameter_toggle_read_only_policy_name Name of the policy that allows RO access to the toggle SSM Parameter. string "FXCostOptimizerSSMParameterReadOnlyPolicy" no
ssm_parameter_toggle_read_write_policy_name Name of the policy that allows RW access to the toggle SSM Parameter. string "FXCostOptimizerSSMParameterReadWritePolicy" no
tags Tags to be shared among all resources of the module. map {} no
vpc_id ID of the VPC where to deploy this module. string "" no

Outputs

Name Description
cost_optimization_enabled n/a

Versioning

This repository follows Semantic Versioning 2.0.0

Git Hooks

This repository uses pre-commit hooks.