Skip to content

LaunchRack/terraform-aws-ec2-instance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaunchRack logo

We are huge followers of the Cloud-Native DevOps movement and are firm believers in the power of treating Infrastructure as Code using immutable architecture & GitOps style deployments. We adhere to a strict automation mindset (automation first, as opposed to manual first with automation later) and strive to provide the best technical acumen that will enable organizations improve Cloud Security Posture, Release More Often, Scale with Demand, Brace Agility, Operate within Budget and focus on value derived by the time saved on the execution of a task rather than having to spend cycles on design & tool selection.

Our consistent and automated processes can help you improve:

✔ Better utilization of cloud resources by 40%
✔ Self-service infrastructure provisioning by 35%
Security and governance by 30%
✔ Return on value/investment by 20%
✔ Team management & governance by 15%
✔ Earlier detection of bugs by 32%
✔ Response to issues/events by 23%

Chat more? Email | Contact us

linkedin logo twitter logo facebook logo


Terraform AWS EC2 instance

GitHub license GitHub release (latest by date)

Creates an EC2 instance on AWS

Features

Creates an EC2 instance with static EIP and an EBS volume

Usage

module "aws_ec2_instance" {
  source        = "git::https://github.com/LaunchRack/terraform-aws-ec2-instance.git"

  ami                       = ["ami-xxxxxxxxxxxxxxxxx"]
  virtualization_type       = ["hvm"]
  ami_owner                 = ["amazon"]
  role_name                 = "my-instance-role"
  iam_instance_profile_name = "my-instance-profile"
  instance_type             = "t2.micro"
  key_name                  = "my-keypair"
  subnet_id                 = "subnet-xxxxxxxxxxxxxxxx"
  vpc_security_group_ids    = ["sg-xxxxxxxxxxxxxxxxx"]
  root_block_device = [  
      {
        delete_on_termination = false
        encrypted             = false
        volume_size           = 20
        volume_type           = "gp2"
      }
  ]
  ebs_volume_size       = 20
  ebs_volume_type       = "gp2"
  ebs_volume_encrypted  = false 
  ebs_device_name       = "/dev/xvdb"

  tags = {
    BusinessUnit = "tools"
    Application  = "cicd"
  }
}

Setup Instructions

terraform init

terraform plan # use -var-file=terraform.tfvars if you plan to use a different file for the value overrides. See examples folder

terraform apply -auto-approve # use -var-file=terraform.tfvars if you plan to use a different file for the value overrides. See examples folder

Note: The terraform.tfvars file will need to be created in the root directory with value overrides

Requirements

Name Version
terraform ~> 1.0
aws ~> 4.0
local ~> 2.0
null ~> 3.0

Providers

Name Version
aws ~> 4.0

Resources

Name Type
aws_ebs_volume.default resource
aws_eip.default resource
aws_iam_instance_profile.default resource
aws_iam_role.default resource
aws_instance.default resource
aws_volume_attachment.default resource
aws_ami.default data source
aws_iam_policy_document.default data source
aws_subnet.selected data source

Inputs

Name Description Type Default Required
ami The AMI to use for the instance. list(string) [] yes
ami_owner Owner of the given AMI. list(string) [] yes
associate_public_ip_address Whether to associate a public IP address with the instance. bool true no
cpu_credits The credit option for CPU usage. Can be standard or unlimited. T3 instances are launched as unlimited by default. T2 instances are launched as standard by default. string "standard" no
disable_api_termination Whether to enable EC2 instance termination protection. bool false no
ebs_device_name The device name to expose to the instance. string "" no
ebs_iops Amount of provisioned IOPS. This must be set with a volume_type of io1, io2 or gp3. number 0 no
ebs_optimized Whether the launched EC2 instance will need to be EBS-optimized. bool true no
ebs_volume_encrypted Whether to encrypt the additional EBS volumes. bool true no
ebs_volume_size Size of the additional EBS volumes in gigabytes. number 10 no
ebs_volume_type The type of the additional EBS volumes. Can be standard, gp2, gp3, io1, i02, sc1, or st1. string "gp2" no
ephemeral_block_device Configuration block to customize details about instance Store volumes on the instance. list(any) [] no
iam_instance_profile_name The name of the IAM Instance Profile to launch the instance with. string "" yes
instance_initiated_shutdown_behavior Shutdown behavior for the instance. string "terminate" no
instance_type The instance type to use for the instance. string "" yes
ipv6_address_count A number of IPv6 addresses to associate with the primary network interface. number 0 no
ipv6_addresses List of IPv6 addresses from the range of the subnet to associate with the primary network interface. list(any) [] no
key_name The key name of the key pair to use for the instance. string "" no
kms_key_id The ARN for the KMS encryption key. When specifying kms_key_id, encrypted needs to be set to true. string "" no
metadata_http_endpoint_enabled Whether the metadata service is available. Valid values include enabled or disabled. Defaults to enabled. string "enabled" no
metadata_http_put_response_hop_limit The desired HTTP PUT response hop limit (between 1 and 64) for instance metadata requests. number 2 no
metadata_http_tokens_required Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Valid values include optional or required. Defaults to optional. string "optional" no
monitoring Whether to enable detailed monitoring for the launched EC2 instance. bool true no
network_interface Configuration block to customize network interfaces to be attached at instance boot time. list(map(string)) [] no
placement_group The Placement Group to start the instance in. string "" no
role_name The role name for the IAM instance profile. string "" yes
root_block_device Configuration block to customize details about the root block device of the instance. list(any) [] 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. bool true no
subnet_id VPC Subnet ID the instance is launched in. string null yes
tags A map of tags for the resources. map(string) {} no
tenancy The tenancy of the instance. An instance with a tenancy of dedicated runs on single-tenant hardware. The host tenancy is not supported for the import-instance command. string "default" no
virtualization_type The type of virtualization of the AMI. list(string) ["hvm"] no
vpc_security_group_ids A list of security group IDs to associate with the instance. list(string) [] no

Outputs

Name Description
arn ARN of the instance.
ebs_ids The EBS volumes Id.
id The ID of the instance.
private_dns Private DNS of instance.
private_ip Private IP of instance.
public_dns Public DNS of instance.
public_ip Public IP of instance.

Authors

This module is maintained by our awsome platform engineering team. Here are our contributors

License

See LICENSE for full details

Trademarks

All other trademarks referenced herein are the property of their respective owners