From 8fb57d655aad2dcabd60fb7eb940456c99c983e7 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Mon, 4 Jun 2018 15:07:58 +0200 Subject: [PATCH 1/2] Added support for CPU credits --- .pre-commit-config.yaml | 4 ++-- README.md | 2 ++ examples/basic/README.md | 1 + examples/basic/outputs.tf | 5 +++++ main.tf | 3 +++ outputs.tf | 5 +++++ variables.tf | 5 +++++ 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8189a755..804e5bb6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 8a6cf008..a037e8a5 100644 --- a/README.md +++ b/README.md @@ -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 | `` | 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" { | 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 | diff --git a/examples/basic/README.md b/examples/basic/README.md index afb3c61d..85e74d54 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -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 | diff --git a/examples/basic/outputs.tf b/examples/basic/outputs.tf index e87e2d8b..138e9af0 100644 --- a/examples/basic/outputs.tf +++ b/examples/basic/outputs.tf @@ -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]}" +} diff --git a/main.tf b/main.tf index fd4f53db..c5dd71d8 100644 --- a/main.tf +++ b/main.tf @@ -33,6 +33,9 @@ resource "aws_instance" "this" { # 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: diff --git a/outputs.tf b/outputs.tf index f5031104..6907e349 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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}"] diff --git a/variables.tf b/variables.tf index a437e8ac..d4f9f87d 100644 --- a/variables.tf +++ b/variables.tf @@ -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" +} From a0c219c8a190d5b2de763cd9cb4a78bcc5b23a3a Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Mon, 4 Jun 2018 15:09:42 +0200 Subject: [PATCH 2/2] Updated formatting --- main.tf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index c5dd71d8..646524b4 100644 --- a/main.tf +++ b/main.tf @@ -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}" @@ -30,13 +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)