This Terraform Infrastructure as code (IaC) sample helps to Opting in or Opting out AWS Compute Optimizer in your account.
There is open issue to Add resources for ComputeOptimizer Recommendation Preferences. So currently Terraform does not have resource for AWS Compute Optimizer.
As a workaround, we tried to provide customised sample to opt-in and opt-out your account for AWS compute optimizer. You may need to update the code as per your requirements and Terraform releases.
For more details, refer AWS Documentation on put-recommendation-preferences.
- This module requires Terraform version >= 0.12.
Name | Description | Type | Default | Required |
---|---|---|---|---|
status | Whether AWS Computer Optimizer should be Active or Inactive | string |
n/a | yes |
scope_name | The name of the scope. It can be Organization|AccountId|ResourceArn | string |
null | no |
scope_value | The value of the scope. It should be ALL_ACCOUNTS if scope_name is Organization, values for Account ID or resource arn to be mentioned as per scope name | string |
null | no |
resource_type | The target resource type of the recommendation preference to create | string |
null | no |
enhanced_monitoring | The status of the enhanced infrastructure metrics recommendation preference to make it Active or Inactive | string |
null | no |
Update the variables in dev.auto.tfvars
file as per your requirement.
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# null_resource.compute_optimiser will be created
+ resource "null_resource" "compute_optimiser" {
+ id = (known after apply)
+ triggers = {
+ "file_hash" = "1c90c11c9c712ffb320ea81490f501cc53952331a428c329a97b680a5cf5d66b"
+ "scope_name" = "Organization"
+ "status" = "Active"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ executable_command = <<-EOT
aws compute-optimizer update-enrollment-status --status Active
aws compute-optimizer put-recommendation-preferences --scope name=Organization,value=ALL_ACCOUNTS --resource-type Ec2Instance --enhanced-infrastructure-metrics Inactive
EOT
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
null_resource.compute_optimiser: Creating...
null_resource.compute_optimiser: Creation complete after 0s [id=2527645616079253896]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
executable_command = <<EOT
aws compute-optimizer update-enrollment-status --status Active
aws compute-optimizer put-recommendation-preferences --scope name=Organization,value=ALL_ACCOUNTS --resource-type Ec2Instance --enhanced-infrastructure-metrics Inactive
EOT
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.