Skip to content

Commit

Permalink
Merge pull request #1 from terraform-aws-modules/master
Browse files Browse the repository at this point in the history
Merge From Upstream
  • Loading branch information
sacres committed May 13, 2019
2 parents b9a4c55 + 1a201ea commit 210f66d
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 80 deletions.
81 changes: 41 additions & 40 deletions README.md
Expand Up @@ -84,59 +84,60 @@ data "aws_ami" "ubuntu-xenial" {
* `network_interface` can't be specified together with `associate_public_ip_address`, which makes `network_interface`
not configurable using this module at the moment
* Changes in `ebs_block_device` argument will be ignored. Use [aws_volume_attachment](https://www.terraform.io/docs/providers/aws/r/volume_attachment.html) resource to attach and detach volumes from AWS EC2 instances. See [this example](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment).
* One of `subnet_id` or `subnet_ids` is required. If both are provided, the value of `subnet_id` is prepended to the value of `subnet_ids`.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| ephemeral_block_device | Customize Ephemeral (also known as Instance Store) volumes on the instance | string | `<list>` | no |
| iam_instance_profile | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | string | `` | no |
| instance_count | Number of instances to launch | string | `1` | no |
| instance_initiated_shutdown_behavior | Shutdown behavior for the instance | string | `` | no |
| instance_type | The type of instance to start | string | - | yes |
| ipv6_address_count | A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. | string | `0` | no |
| ipv6_addresses | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | string | `<list>` | no |
| key_name | The key name to use for the instance | string | `` | no |
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | string | `false` | no |
| name | Name to be used on all resources as prefix | string | - | yes |
| network_interface | Customize network interfaces to be attached at instance boot time | string | `<list>` | no |
| placement_group | The Placement Group to start the instance in | string | `` | no |
| private_ip | Private IP address to associate with the instance in a VPC | string | `` | no |
| root_block_device | Customize details about the root block device of the instance. See Block Devices below for details | string | `<list>` | no |
| source_dest_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. | string | `true` | no |
| subnet_id | The VPC Subnet ID to launch in | string | - | yes |
| tags | A mapping of tags to assign to the resource | string | `<map>` | no |
| tenancy | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | string | `default` | no |
| user_data | The user data to provide when launching the instance | string | `` | no |
| volume_tags | A mapping of tags to assign to the devices created by the instance at launch time | string | `<map>` | no |
| vpc_security_group_ids | A list of security group IDs to associate with | list | - | yes |
| ami | ID of AMI to use for the instance | string | n/a | 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 | list | `<list>` | no |
| ebs\_optimized | If true, the launched EC2 instance will be EBS-optimized | string | `"false"` | no |
| ephemeral\_block\_device | Customize Ephemeral (also known as Instance Store) volumes on the instance | list | `<list>` | no |
| iam\_instance\_profile | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | string | `""` | no |
| instance\_count | Number of instances to launch | string | `"1"` | no |
| instance\_initiated\_shutdown\_behavior | Shutdown behavior for the instance | string | `""` | no |
| instance\_type | The type of instance to start | string | n/a | yes |
| ipv6\_address\_count | A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. | string | `"0"` | no |
| ipv6\_addresses | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | list | `<list>` | no |
| key\_name | The key name to use for the instance | string | `""` | no |
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | string | `"false"` | no |
| name | Name to be used on all resources as prefix | string | n/a | yes |
| network\_interface | Customize network interfaces to be attached at instance boot time | list | `<list>` | no |
| placement\_group | The Placement Group to start the instance in | string | `""` | no |
| private\_ip | Private IP address to associate with the instance in a VPC | string | `""` | no |
| root\_block\_device | Customize details about the root block device of the instance. See Block Devices below for details | list | `<list>` | no |
| source\_dest\_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. | string | `"true"` | no |
| subnet\_id | The VPC Subnet ID to launch in | string | `""` | no |
| subnet\_ids | A list of VPC Subnet IDs to launch in | list | `<list>` | no |
| tags | A mapping of tags to assign to the resource | map | `<map>` | no |
| tenancy | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | string | `"default"` | no |
| use\_num\_suffix | Always append numerical suffix to instance name, even if instance_count is 1 | string | `"false"` | no |
| user\_data | The user data to provide when launching the instance | string | `""` | no |
| volume\_tags | A mapping of tags to assign to the devices created by the instance at launch time | map | `<map>` | no |
| vpc\_security\_group\_ids | A list of security group IDs to associate with | list | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| availability_zone | List of availability zones of instances |
| credit_specification | List of credit specification of instances |
| 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 |
| primary_network_interface_id | List of IDs of the primary network interface of instances |
| private_dns | List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC |
| private_ip | List of private IP addresses assigned to the instances |
| public_dns | List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
| public_ip | List of public IP addresses assigned to the instances, if applicable |
| security_groups | List of associated security groups of instances |
| subnet_id | List of IDs of VPC subnets of instances |
| key\_name | List of key names of instances |
| primary\_network\_interface\_id | List of IDs of the primary network interface of instances |
| private\_dns | List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC |
| private\_ip | List of private IP addresses assigned to the instances |
| public\_dns | List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
| public\_ip | List of public IP addresses assigned to the instances, if applicable |
| security\_groups | List of associated security groups of instances |
| subnet\_id | List of IDs of VPC subnets of instances |
| tags | List of tags of instances |
| vpc_security_group_ids | List of associated security groups of instances, if running in non-default VPC |
| vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Expand Down
15 changes: 7 additions & 8 deletions examples/basic/README.md
Expand Up @@ -19,19 +19,18 @@ $ terraform apply
Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Outputs

| Name | Description |
|------|-------------|
| credit_specification | Credit specification of EC2 instance (empty list for not t2 instance types) |
| credit_specification_t2_unlimited | Credit specification of t2-type EC2 instance |
| credit\_specification | Credit specification of EC2 instance (empty list for not t2 instance types) |
| credit\_specification\_t2\_unlimited | Credit specification of t2-type EC2 instance |
| ids | List of IDs of instances |
| ids_t2 | List of IDs of t2-type instances |
| instance_id | EC2 instance ID |
| instance_public_dns | Public DNS name assigned to the EC2 instance |
| public_dns | List of public DNS names assigned to the instances |
| ids\_t2 | List of IDs of t2-type instances |
| instance\_id | EC2 instance ID |
| instance\_public\_dns | Public DNS name assigned to the EC2 instance |
| public\_dns | List of public DNS names assigned to the instances |
| tags | List of tags |
| vpc_security_group_ids | List of VPC security group ids assigned to the instances |
| vpc\_security\_group\_ids | List of VPC security group ids assigned to the instances |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11 changes: 9 additions & 2 deletions examples/basic/main.tf
Expand Up @@ -16,6 +16,8 @@ data "aws_subnet_ids" "all" {
data "aws_ami" "amazon_linux" {
most_recent = true

owners = ["amazon"]

filter {
name = "name"

Expand All @@ -34,8 +36,8 @@ data "aws_ami" "amazon_linux" {
}

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"

name = "example"
description = "Security group for example usage with EC2 instance"
Expand All @@ -62,6 +64,11 @@ module "ec2" {
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true

root_block_device = [{
volume_type = "gp2"
volume_size = 10
}]
}

module "ec2_with_t2_unlimited" {
Expand Down
12 changes: 8 additions & 4 deletions examples/volume-attachment/README.md
Expand Up @@ -19,14 +19,18 @@ $ terraform apply
Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| instances\_number | | string | `"1"` | no |

## Outputs

| Name | Description |
|------|-------------|
| ebs_volume_attachment_id | The volume ID |
| ebs_volume_attachment_instance_id | The instance ID |
| instance_id | EC2 instance ID |
| instance_public_dns | Public DNS name assigned to the EC2 instance |
| ebs\_volume\_attachment\_id | The volume ID |
| ebs\_volume\_attachment\_instance\_id | The instance ID |
| instances\_public\_ips | Public IPs assigned to the EC2 instance |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20 changes: 14 additions & 6 deletions examples/volume-attachment/main.tf
Expand Up @@ -2,6 +2,10 @@ provider "aws" {
region = "eu-west-1"
}

variable "instances_number" {
default = 1
}

##################################################################
# Data sources to get VPC, subnet, security group and AMI details
##################################################################
Expand Down Expand Up @@ -34,8 +38,8 @@ data "aws_ami" "amazon_linux" {
}

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"

name = "example"
description = "Security group for example usage with EC2 instance"
Expand All @@ -49,7 +53,7 @@ module "security_group" {
module "ec2" {
source = "../../"

instance_count = 1
instance_count = "${var.instances_number}"

name = "example-with-ebs"
ami = "${data.aws_ami.amazon_linux.id}"
Expand All @@ -60,12 +64,16 @@ module "ec2" {
}

resource "aws_volume_attachment" "this_ec2" {
count = "${var.instances_number}"

device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.this.id}"
instance_id = "${module.ec2.id[0]}"
volume_id = "${aws_ebs_volume.this.*.id[count.index]}"
instance_id = "${module.ec2.id[count.index]}"
}

resource "aws_ebs_volume" "this" {
availability_zone = "${module.ec2.availability_zone[0]}"
count = "${var.instances_number}"

availability_zone = "${module.ec2.availability_zone[count.index]}"
size = 1
}
15 changes: 5 additions & 10 deletions examples/volume-attachment/outputs.tf
@@ -1,19 +1,14 @@
output "instance_id" {
description = "EC2 instance ID"
value = "${module.ec2.id[0]}"
}

output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}"
output "instances_public_ips" {
description = "Public IPs assigned to the EC2 instance"
value = "${module.ec2.public_ip}"
}

output "ebs_volume_attachment_id" {
description = "The volume ID"
value = "${aws_volume_attachment.this_ec2.volume_id}"
value = "${aws_volume_attachment.this_ec2.*.volume_id}"
}

output "ebs_volume_attachment_instance_id" {
description = "The instance ID"
value = "${aws_volume_attachment.this_ec2.instance_id}"
value = "${aws_volume_attachment.this_ec2.*.instance_id}"
}
8 changes: 4 additions & 4 deletions main.tf
Expand Up @@ -11,7 +11,7 @@ resource "aws_instance" "this" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
Expand All @@ -34,7 +34,7 @@ resource "aws_instance" "this" {
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"

tags = "${merge(var.tags, map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name))}"
tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"

lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
Expand All @@ -50,7 +50,7 @@ resource "aws_instance" "this_t2" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
Expand All @@ -77,7 +77,7 @@ resource "aws_instance" "this_t2" {
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(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"

lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
Expand Down
6 changes: 0 additions & 6 deletions outputs.tf
Expand Up @@ -4,7 +4,6 @@ locals {
this_key_name = "${compact(concat(coalescelist(aws_instance.this.*.key_name, aws_instance.this_t2.*.key_name), list("")))}"
this_public_dns = "${compact(concat(coalescelist(aws_instance.this.*.public_dns, aws_instance.this_t2.*.public_dns), list("")))}"
this_public_ip = "${compact(concat(coalescelist(aws_instance.this.*.public_ip, aws_instance.this_t2.*.public_ip), list("")))}"
this_network_interface_id = "${compact(concat(coalescelist(aws_instance.this.*.network_interface_id, aws_instance.this_t2.*.network_interface_id), list("")))}"
this_primary_network_interface_id = "${compact(concat(coalescelist(aws_instance.this.*.primary_network_interface_id, aws_instance.this_t2.*.primary_network_interface_id), list("")))}"
this_private_dns = "${compact(concat(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns), list("")))}"
this_private_ip = "${compact(concat(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip), list("")))}"
Expand Down Expand Up @@ -46,11 +45,6 @@ output "public_ip" {
value = ["${local.this_public_ip}"]
}

output "network_interface_id" {
description = "List of IDs of the network interface of instances"
value = ["${local.this_network_interface_id}"]
}

output "primary_network_interface_id" {
description = "List of IDs of the primary network interface of instances"
value = ["${local.this_primary_network_interface_id}"]
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Expand Up @@ -57,6 +57,13 @@ variable "vpc_security_group_ids" {

variable "subnet_id" {
description = "The VPC Subnet ID to launch in"
default = ""
}

variable "subnet_ids" {
description = "A list of VPC Subnet IDs to launch in"
default = []
type = "list"
}

variable "associate_public_ip_address" {
Expand Down Expand Up @@ -128,3 +135,8 @@ variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)"
default = "standard"
}

variable "use_num_suffix" {
description = "Always append numerical suffix to instance name, even if instance_count is 1"
default = "false"
}

0 comments on commit 210f66d

Please sign in to comment.