2.0.2 • Published 6 years ago

@terrastack/terraform-aws-ec2-instance v2.0.2

Weekly downloads
-
License
MPL-2.0
Repository
-
Last release
6 years ago

AWS EC2 Instance Terraform module

Terraform module which creates EC2 instance(s) on AWS.

These types of resources are supported:

Usage

module "ec2_cluster" {
  source = "terraform-aws-modules/ec2-instance/aws"

  name           = "my-cluster"
  instance_count = 5
  
  ami                    = "ami-ebd02392"
  instance_type          = "t2.micro"
  key_name               = "user1"
  monitoring             = true
  vpc_security_group_ids = ["sg-12345678"]
  subnet_id              = "subnet-eddcdzz4"

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}

Examples

Make an encrypted AMI for use

This module does not sopport encrypted AMI's out of the box however it is easy enough for you to generate one for use

This example creates an encrypted image from the latest ubuntu 16.04 base image.

resource "aws_ami_copy" "ubuntu-xenial-encrypted-ami" {
  name              = "ubuntu-xenial-encrypted-ami"
  description       = "An encrypted root ami based off ${data.aws_ami.ubuntu-xenial.id}"
  source_ami_id     = "${data.aws_ami.ubuntu-xenial.id}"
  source_ami_region = "eu-west-2"
  encrypted         = "true"

  tags {
    Name = "ubuntu-xenial-encrypted-ami"
  }
}

data "aws_ami" "encrypted-ami" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu-xenial-encrypted"]
  }

  owners = ["self"]
}

data "aws_ami" "ubuntu-xenial" {
  most_recent = true
  owners      = ["099720109477"]

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
  }
}

Notes

  • 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 resource to attach and detach volumes from AWS EC2 instances. See this example.

Inputs

NameDescriptionTypeDefaultRequired
amiID of AMI to use for the instancestring-yes
associate_public_ip_addressIf true, the EC2 instance will have associated public IP addressstringfalseno
cpu_creditsThe credit option for CPU usage (unlimited or standard)stringstandardno
disable_api_terminationIf true, enables EC2 Instance Termination Protectionstringfalseno
ebs_block_deviceAdditional EBS block devices to attach to the instancestring<list>no
ebs_optimizedIf true, the launched EC2 instance will be EBS-optimizedstringfalseno
ephemeral_block_deviceCustomize Ephemeral (also known as Instance Store) volumes on the instancestring<list>no
iam_instance_profileThe IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile.string | no
instance_countNumber of instances to launchstring1no
instance_initiated_shutdown_behaviorShutdown behavior for the instancestring | no
instance_typeThe type of instance to startstring-yes
ipv6_address_countA number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet.string0no
ipv6_addressesSpecify one or more IPv6 addresses from the range of the subnet to associate with the primary network interfacestring<list>no
key_nameThe key name to use for the instancestring | no
monitoringIf true, the launched EC2 instance will have detailed monitoring enabledstringfalseno
nameName to be used on all resources as prefixstring-yes
network_interfaceCustomize network interfaces to be attached at instance boot timestring<list>no
placement_groupThe Placement Group to start the instance instring | no
private_ipPrivate IP address to associate with the instance in a VPCstring | no
root_block_deviceCustomize details about the root block device of the instance. See Block Devices below for detailsstring<list>no
source_dest_checkControls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs.stringtrueno
subnet_idThe VPC Subnet ID to launch instring-yes
tagsA mapping of tags to assign to the resourcestring<map>no
tenancyThe tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host.stringdefaultno
user_dataThe user data to provide when launching the instancestring | no
volume_tagsA mapping of tags to assign to the devices created by the instance at launch timestring<map>no
vpc_security_group_idsA list of security group IDs to associate withlist-yes

Outputs

NameDescription
availability_zoneList of availability zones of instances
credit_specificationList of credit specification of instances
idList of IDs of instances
key_nameList of key names of instances
network_interface_idList of IDs of the network interface of instances
primary_network_interface_idList of IDs of the primary network interface of instances
private_dnsList 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_ipList of private IP addresses assigned to the instances
public_dnsList 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_ipList of public IP addresses assigned to the instances, if applicable
security_groupsList of associated security groups of instances
subnet_idList of IDs of VPC subnets of instances
tagsList of tags of instances
vpc_security_group_idsList of associated security groups of instances, if running in non-default VPC

Authors

Module managed by Anton Babenko.

License

Apache 2 Licensed. See LICENSE for full details.

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago