Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for CPU credits #35

Merged
merged 2 commits into from
Jun 4, 2018
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.0
rev: v1.7.3
hooks:
- id: terraform_fmt
- id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
rev: v1.3.0
hooks:
- id: check-merge-conflict
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ data "aws_ami" "ubuntu-xenial" {
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| 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 |
| 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 |
Expand Down Expand Up @@ -119,6 +120,7 @@ data "aws_ami" "ubuntu-xenial" {
| Name | Description |
|------|-------------|
| availability_zone | List of availability zones of instances |
| credit_specification | List of credit specification of instances |
| id | List of IDs of instances |
| key_name | List of key names of instances |
| network_interface_id | List of IDs of the network interface of instances |
Expand Down
1 change: 1 addition & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Note that this example may create resources which can cost money. Run `terraform

| Name | Description |
|------|-------------|
| credit_specification | Credit specification of EC2 instance |
| id | List of IDs of instances |
| instance_id | EC2 instance ID |
| instance_public_dns | Public DNS name assigned to the EC2 instance |
Expand Down
5 changes: 5 additions & 0 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}"
}

output "credit_specification" {
description = "Credit specification of EC2 instance"
value = "${module.ec2.credit_specification[0]}"
}
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
######
# EC2 instance
#
# Note: network_interface can't be specified together with associate_public_ip_address
######
resource "aws_instance" "this" {
count = "${var.instance_count}"
Expand Down Expand Up @@ -30,10 +32,12 @@ resource "aws_instance" "this" {
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"

# Note: network_interface can't be specified together with associate_public_ip_address
# network_interface = "${var.network_interface}"
credit_specification {
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))}"

lifecycle {
# 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)
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ output "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" {
description = "List of tags of instances"
value = ["${aws_instance.this.*.tags}"]
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,8 @@ variable "network_interface" {
description = "Customize network interfaces to be attached at instance boot time"
default = []
}

variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)"
default = "standard"
}