From c9a4adb3b8fc032d3b55e47e08488846eff5e604 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Fri, 21 Oct 2016 14:54:46 -0600 Subject: [PATCH 1/2] Add directory-specific .gitignore file Add .gitignore file to ignore Terraform state and state backup files. Signed-off-by: Scott S. Lowe --- terraform-aws/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 terraform-aws/.gitignore diff --git a/terraform-aws/.gitignore b/terraform-aws/.gitignore new file mode 100644 index 0000000..e2bf8bc --- /dev/null +++ b/terraform-aws/.gitignore @@ -0,0 +1,2 @@ +*.tfstate +*.tfstate.backup From 3279b2e3900cd192bc0257a965d16f571ed7825f Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Fri, 21 Oct 2016 15:29:32 -0600 Subject: [PATCH 2/2] Add Terraform configuration for simple EC2 instance Add a simple Terraform configuration to spin up an Ubuntu 14.04 EC2 instance in the default VPC using the default security group. Signed-off-by: Scott S. Lowe --- terraform-aws/README.md | 19 ++++++++++++++++ terraform-aws/simple-ec2/data.tf | 34 ++++++++++++++++++++++++++++ terraform-aws/simple-ec2/main.tf | 11 +++++++++ terraform-aws/simple-ec2/provider.tf | 3 +++ terraform-aws/simple-ec2/vars.tf | 17 ++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 terraform-aws/README.md create mode 100644 terraform-aws/simple-ec2/data.tf create mode 100644 terraform-aws/simple-ec2/main.tf create mode 100644 terraform-aws/simple-ec2/provider.tf create mode 100644 terraform-aws/simple-ec2/vars.tf diff --git a/terraform-aws/README.md b/terraform-aws/README.md new file mode 100644 index 0000000..e1d0afd --- /dev/null +++ b/terraform-aws/README.md @@ -0,0 +1,19 @@ +# Using Terraform with AWS + +This directory contains a number of subdirectories with example configurations intended to help users understand how to use Terraform ([http://terraform.io](http://terraform.io)) with AWS. All of these example configurations require a working Terraform installation and access to a valid AWS account. + +## Contents + +* **README.md**: This file you're currently reading. + +* **simple-ec2**: This directory contains a simple Terraform configuration for spinning up an Ubuntu 14.04 EC2 instance in an account's default VPC. + +## Prerequisites + +These instructions assume you've already installed Terraform and that you have access to a valid AWS account. Installing Terraform and/or working with AWS accounts are not covered in any of these materials. + +These environments were tested with Terraform 0.7.7. Earlier versions may or may not work; I recommend upgrading your version of Terraform to 0.7.7. + +## License + +This material is licensed under the MIT License. diff --git a/terraform-aws/simple-ec2/data.tf b/terraform-aws/simple-ec2/data.tf new file mode 100644 index 0000000..b7aa9c8 --- /dev/null +++ b/terraform-aws/simple-ec2/data.tf @@ -0,0 +1,34 @@ +data "aws_ami" "ubuntu-1404-ami" { + most_recent = true + owners = ["099720109477"] + filter { + name = "root-device-type" + values = ["ebs"] + } + filter { + name = "architecture" + values = ["x86_64"] + } + filter { + name = "virtualization-type" + values = ["hvm"] + } + filter { + name = "name" + values = ["*ubuntu-trusty-14.04*"] + } +} + +data "aws_vpc" "default-vpc" { + filter { + name = "isDefault" + values = ["true"] + } +} + +data "aws_subnet" "default-subnet" { + filter { + name = "cidrBlock" + values = ["172.31.16.0/20"] + } +} diff --git a/terraform-aws/simple-ec2/main.tf b/terraform-aws/simple-ec2/main.tf new file mode 100644 index 0000000..b8fe61a --- /dev/null +++ b/terraform-aws/simple-ec2/main.tf @@ -0,0 +1,11 @@ +# Create a new Ubuntu 14.04 instance using values from vars.tf and data.tf +resource "aws_instance" "test-01" { + ami = "${data.aws_ami.ubuntu-1404-ami.id}" + instance_type = "${var.flavor}" + key_name = "${var.keypair}" + vpc_security_group_ids = ["${var.sec-group}"] + subnet_id = "${data.aws_subnet.default-subnet.id}" + tags { + Name = "terraform" + } +} diff --git a/terraform-aws/simple-ec2/provider.tf b/terraform-aws/simple-ec2/provider.tf new file mode 100644 index 0000000..0c28776 --- /dev/null +++ b/terraform-aws/simple-ec2/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-west-2" +} diff --git a/terraform-aws/simple-ec2/vars.tf b/terraform-aws/simple-ec2/vars.tf new file mode 100644 index 0000000..c5aa2ec --- /dev/null +++ b/terraform-aws/simple-ec2/vars.tf @@ -0,0 +1,17 @@ +variable "keypair" { + type = "string" + description = "AWS SSH keypair to use to connect to instances" + default = "aws_rsa" +} + +variable "flavor" { + type = "string" + description = "AWS type to use when creating instances" + default = "t2.micro" +} + +variable "sec-group" { + type = "string" + description = "AWS security group to apply to instances" + default = "sg-7099b514" +}