Skip to content

Latest commit

 

History

History
80 lines (66 loc) · 4.35 KB

README.md

File metadata and controls

80 lines (66 loc) · 4.35 KB

AWS EC2 Instance Module

This module creates AWS EC2 Instance and IAM Role attached to it.

Example

# main.tf
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "this" {
  name        = "SG EC2 - ${local.name}"
  vpc_id      = local.vpc_id

  lifecycle {
    create_before_destroy = true
  }
}

module "ec2_instance" {
  source = "git::https://github.com/lpavliuk/Terraform-Modules.git//aws_ec2_instance"

  name              = local.name
  type              = local.instance_type
  ami               = local.ami_id
  vpc_id            = local.vpc_id
  subnet_id         = local.subnet_group_subnet_id
  has_elastic_ip    = false
  security_group_id = aws_security_group.this.id
  extra_sg_ids      = [ local.vpc_sg_id ]
}

Requirements

Name Version
terraform < 2.0.0, >= 1.6.6
aws < 6.0, >= 5.22

Inputs

Name Description Type Default Required
name Name of the Instance string n/a yes
ami AMI ID the Instance will be created from string n/a yes
type Type of the Instance. Available Instance Types string "t2.small" no
vpc_id VPC ID where the Instance will be launched in string n/a yes
subnet_id Subnet ID where the Instance will be launched in string n/a yes
security_group_id Default Security Group ID of the Instance string n/a yes
extra_sg_ids Extra Security Groups IDs except for default one list(string) [] no
user_data The script that will be executed after the instance is created string "" no
has_elastic_ip Reserve static Public IP Address for the Instance bool false no

Outputs

Name Description
id Instance ID
name Instance Name
private_ip Instance's Private IP Address
root_volume_id Instance's EBS Volume ID (Root)
type Instance Type
security_group_id Instance's default Security Group ID
vpc_security_group_ids Security Group IDs attached to the Instance
availability_zone Availability Zone the Instance launched in
iam_role_name IAM Role attached to the Instance
iam_profile IAM Profile attached to the Instance

Resources

Name Type
aws_eip.this resource
aws_iam_instance_profile.this_instance resource
aws_iam_role.this_instance resource
aws_instance.this resource
aws_iam_policy_document.this_instance data source