├── outputs.tf ├── LICENSE ├── main.tf ├── variables.tf └── README.md /outputs.tf: -------------------------------------------------------------------------------- 1 | // Output the ID of the EC2 instance created 2 | output "ec2_instance_id" { 3 | value = "${aws_instance.ec2_instance.id}" 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Author:: Brandon Burton () 2 | 3 | Copyright 2015 Brandon Burton 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | // Provider specific configs 2 | provider "aws" { 3 | access_key = "${var.aws_access_key}" 4 | secret_key = "${var.aws_secret_key}" 5 | region = "${var.aws_region}" 6 | } 7 | 8 | // EC2 Instance Resource for Module 9 | resource "aws_instance" "ec2_instance" { 10 | ami = "${var.ami_id}" 11 | count = "${var.number_of_instances}" 12 | subnet_id = "${var.subnet_id}" 13 | instance_type = "${var.instance_type}" 14 | user_data = "${file(var.user_data)}" 15 | tags { 16 | created_by = "${lookup(var.tags,"created_by")}" 17 | // Takes the instance_name input variable and adds 18 | // the count.index to the name., e.g. 19 | // "example-host-web-1" 20 | Name = "${var.instance_name}-${count.index}" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | // Module specific variables 2 | 3 | variable "instance_name" { 4 | description = "Used to populate the Name tag. This is done in main.tf" 5 | } 6 | 7 | variable "instance_type" {} 8 | 9 | variable "subnet_id" { 10 | description = "The VPC subnet the instance(s) will go in" 11 | } 12 | 13 | variable "ami_id" { 14 | description = "The AMI to use" 15 | } 16 | 17 | variable "number_of_instances" { 18 | description = "number of instances to make" 19 | default = 1 20 | } 21 | 22 | variable "user_data" { 23 | description = "The path to a file with user_data for the instances" 24 | } 25 | 26 | variable "tags" { 27 | default = { 28 | created_by = "terraform" 29 | } 30 | } 31 | 32 | // Variables for providers used in this module 33 | variable "aws_access_key" {} 34 | variable "aws_secret_key" {} 35 | variable "aws_region" {} 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ec2_instance terraform module 2 | ======================= 3 | 4 | # This module is deprecated and [terraform-aws-modules/terraform-aws-ec2-instance module](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance) published on [the Terraform registry](https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws) should be used instead. 5 | 6 | ## This repository will not have active support any more. 7 | 8 | --- 9 | 10 | A terraform module for making ec2 instances. 11 | * Assumes you're making your instances in a VPC. 12 | * Does not do any block device configuration (yet) 13 | 14 | Module Input Variables 15 | ---------------------- 16 | 17 | - `ami_id` - The AMI to use 18 | - `number_of_instances` - The number of instances you want made 19 | - `subnet_id` - The VPC subnet to place the instance in 20 | - `instance_type` - The EC2 instance type, e.g. m1.small 21 | - `instance_name` - The instance name you want, this is used to populate 22 | the Name tag. 23 | - `user_data` - The path to the user_data file. Terraform will include the contents of this file while launching the instance 24 | - `tags` - A map for setting AWS tags. 25 | 26 | Usage 27 | ----- 28 | 29 | You can use this in your terraform template with the following steps. 30 | 31 | 1. Adding a module resource to your template, e.g. `main.tf` 32 | 33 | ``` 34 | module "ec2_instance" { 35 | source = "github.com/terraform-community-modules/tf_aws_ec2_instance" 36 | instance_type = "${var.instance_type}" 37 | instance_name = "${var.instance_name}" 38 | ami_id = "${var.ami_id}" 39 | aws_access_key = "${var.aws_access_key}" 40 | aws_secret_key = "${var.aws_secret_key}" 41 | aws_region = "${var.aws_region}" 42 | subnet_id = "${var.subnet_id}" 43 | number_of_instances = "${var.number_of_instances}" 44 | user_data = "${var.user_data}" 45 | } 46 | ``` 47 | 48 | 2. Setting values for the following variables, either through `terraform.tfvars` or `-var` arguments on the CLI 49 | 50 | - aws_access_key 51 | - aws_secret_key 52 | - aws_region 53 | - instance_name 54 | - instance_type 55 | - subnet_id 56 | - ami_id 57 | - number_of_instances 58 | 59 | Authors 60 | ======= 61 | 62 | Created and maintained by [Brandon Burton](https://github.com/solarce) 63 | (brandon@inatree.org). 64 | 65 | License 66 | ======= 67 | 68 | Apache 2 Licensed. See LICENSE for full details. 69 | --------------------------------------------------------------------------------