Commit a49d57a3 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Added support for CPU credits (#35)

* Added support for CPU credits

* Updated formatting
parent c269860b
repos: repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform - repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.0 rev: v1.7.3
hooks: hooks:
- id: terraform_fmt - id: terraform_fmt
- id: terraform_docs - id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks - repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3 rev: v1.3.0
hooks: hooks:
- id: check-merge-conflict - id: check-merge-conflict
...@@ -89,6 +89,7 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -89,6 +89,7 @@ data "aws_ami" "ubuntu-xenial" {
|------|-------------|:----:|:-----:|:-----:| |------|-------------|:----:|:-----:|:-----:|
| ami | ID of AMI to use for the instance | string | - | yes | | ami | ID of AMI to use for the instance | string | - | yes |
| associate_public_ip_address | If true, the EC2 instance will have associated public IP address | string | `false` | no | | associate_public_ip_address | If true, the EC2 instance will have associated public IP address | string | `false` | no |
| cpu_credits | The credit option for CPU usage (unlimited or standard) | string | `standard` | no |
| disable_api_termination | If true, enables EC2 Instance Termination Protection | string | `false` | no | | disable_api_termination | If true, enables EC2 Instance Termination Protection | string | `false` | no |
| ebs_block_device | Additional EBS block devices to attach to the instance | string | `<list>` | no | | ebs_block_device | Additional EBS block devices to attach to the instance | string | `<list>` | no |
| ebs_optimized | If true, the launched EC2 instance will be EBS-optimized | string | `false` | no | | ebs_optimized | If true, the launched EC2 instance will be EBS-optimized | string | `false` | no |
...@@ -119,6 +120,7 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -119,6 +120,7 @@ data "aws_ami" "ubuntu-xenial" {
| Name | Description | | Name | Description |
|------|-------------| |------|-------------|
| availability_zone | List of availability zones of instances | | availability_zone | List of availability zones of instances |
| credit_specification | List of credit specification of instances |
| id | List of IDs of instances | | id | List of IDs of instances |
| key_name | List of key names of instances | | key_name | List of key names of instances |
| network_interface_id | List of IDs of the network interface of instances | | network_interface_id | List of IDs of the network interface of instances |
......
...@@ -24,6 +24,7 @@ Note that this example may create resources which can cost money. Run `terraform ...@@ -24,6 +24,7 @@ Note that this example may create resources which can cost money. Run `terraform
| Name | Description | | Name | Description |
|------|-------------| |------|-------------|
| credit_specification | Credit specification of EC2 instance |
| id | List of IDs of instances | | id | List of IDs of instances |
| instance_id | EC2 instance ID | | instance_id | EC2 instance ID |
| instance_public_dns | Public DNS name assigned to the EC2 instance | | instance_public_dns | Public DNS name assigned to the EC2 instance |
......
...@@ -17,3 +17,8 @@ output "instance_public_dns" { ...@@ -17,3 +17,8 @@ output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance" description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}" value = "${module.ec2.public_dns[0]}"
} }
output "credit_specification" {
description = "Credit specification of EC2 instance"
value = "${module.ec2.credit_specification[0]}"
}
###### ######
# EC2 instance # EC2 instance
#
# Note: network_interface can't be specified together with associate_public_ip_address
###### ######
resource "aws_instance" "this" { resource "aws_instance" "this" {
count = "${var.instance_count}" count = "${var.instance_count}"
...@@ -30,10 +32,12 @@ resource "aws_instance" "this" { ...@@ -30,10 +32,12 @@ resource "aws_instance" "this" {
placement_group = "${var.placement_group}" placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}" tenancy = "${var.tenancy}"
# Note: network_interface can't be specified together with associate_public_ip_address credit_specification {
# network_interface = "${var.network_interface}" cpu_credits = "${var.cpu_credits}"
}
tags = "${merge(var.tags, map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name))}" tags = "${merge(var.tags, map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name))}"
lifecycle { lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance: # Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036) # (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
......
...@@ -64,6 +64,11 @@ output "subnet_id" { ...@@ -64,6 +64,11 @@ output "subnet_id" {
value = ["${aws_instance.this.*.subnet_id}"] value = ["${aws_instance.this.*.subnet_id}"]
} }
output "credit_specification" {
description = "List of credit specification of instances"
value = ["${aws_instance.this.*.credit_specification}"]
}
output "tags" { output "tags" {
description = "List of tags of instances" description = "List of tags of instances"
value = ["${aws_instance.this.*.tags}"] value = ["${aws_instance.this.*.tags}"]
......
...@@ -123,3 +123,8 @@ variable "network_interface" { ...@@ -123,3 +123,8 @@ variable "network_interface" {
description = "Customize network interfaces to be attached at instance boot time" description = "Customize network interfaces to be attached at instance boot time"
default = [] default = []
} }
variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)"
default = "standard"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment