mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Merge pull request #60 from lowescott/tf-aws
Add Terraform-AWS learning environments
This commit is contained in:
commit
ebddc4b7da
6 changed files with 86 additions and 0 deletions
2
terraform-aws/.gitignore
vendored
Normal file
2
terraform-aws/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
*.tfstate
|
||||||
|
*.tfstate.backup
|
||||||
19
terraform-aws/README.md
Normal file
19
terraform-aws/README.md
Normal file
|
|
@ -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.
|
||||||
34
terraform-aws/simple-ec2/data.tf
Normal file
34
terraform-aws/simple-ec2/data.tf
Normal file
|
|
@ -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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
terraform-aws/simple-ec2/main.tf
Normal file
11
terraform-aws/simple-ec2/main.tf
Normal file
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
terraform-aws/simple-ec2/provider.tf
Normal file
3
terraform-aws/simple-ec2/provider.tf
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
provider "aws" {
|
||||||
|
region = "us-west-2"
|
||||||
|
}
|
||||||
17
terraform-aws/simple-ec2/vars.tf
Normal file
17
terraform-aws/simple-ec2/vars.tf
Normal file
|
|
@ -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"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue