/terraform-aws-ec2-pricing

Terraform module that uses the AWS Pricing API to query EC2 instance type attributes

Primary LanguageHCLMIT LicenseMIT

terraform-aws-ec2-pricing terraform workflow status

Terraform module that uses the AWS Pricing API to query EC2 instance type attributes

Usage

module "instance" {
  source        = "bendrucker/ec2-pricing/aws"
  instance_type = "m5.large"
}

The module exposes outputs that describe key attributes of the specified instance type. These values are helpful for creating monitoring or resource quotas that are defined relative to the instance's capacity.

For example, you might pass these along to a kubernetes_resource_quota in order to assign a percentage of cluster capacity to a namespace:

locals {
  # allow developers to use 80% of worker resources
  # reserve the remaining 20% for system components
  developer_quota = 0.8
}

resource "kubernetes_resource_quota" "developers" {
  metadata {
    name      = "developers-quota"
    namespace = "developers"
  }

  spec {
    hard = {
      cpu    = var.worker_count * module.instance.cpus * local.developer_quota
      memory = "${var.worker_count * module.instance.memory * local.developer_quota} GiB"
    }
  }
}

Providers

Name Version
aws ~> 2

Inputs

Name Description Type Default Required
instance_type EC2 instance type for which attributes will be fetched string n/a yes

Outputs

Name Description
cpus Number of CPU cores available on the instance
memory Memory available on the instance, in gibibytes (GiB)

Testing

This module is tested via Terratest.

make test

License

MIT © Ben Drucker