Skip to content

Instantly share code, notes, and snippets.

@shouro
Forked from solarce/ec2.tf
Created May 4, 2018 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shouro/a711862163b7f57fca1013bc11869174 to your computer and use it in GitHub Desktop.
Save shouro/a711862163b7f57fca1013bc11869174 to your computer and use it in GitHub Desktop.
terraform.io example template for ec2 instance with tags
# The various ${var.foo} come from variables.tf
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
}
resource "aws_instance" "web" {
# The connection block tells our provisioner how to
# communicate with the resource (instance)
connection {
# The default username for our AMI
user = "ubuntu"
# The path to your keyfile
key_file = "${var.key_path}"
}
# subnet ID for our VPC
subnet_id = "${var.subnet_id}"
# the instance type we want, comes from rundeck
instance_type = "${var.instance_type}"
# Lookup the correct AMI based on the region
# we specified
ami = "${lookup(var.aws_amis, var.aws_region)}"
# The name of our SSH keypair you've created and downloaded
# from the AWS console.
#
# https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:
#
key_name = "${var.key_name}"
# We set the name as a tag
tags {
"Name" = "${var.instance_name"
}
}
variable "key_name" {
description = "Name of the SSH keypair to use in AWS."
}
variable "key_path" {
description = "Path to the private portion of the SSH key specified."
}
variable "aws_region" {
description = "AWS region to launch servers."
}
variable "aws_access_key" {
decscription = "AWS Access Key"
}
variable "aws_secret_key" {
description = "AWS Secret Key"
}
variable "subnet_id" {
description = "Subnet ID to use in VPC"
}
variable "instance_type" {
description = "Instance type"
}
variable "instance_name" {
description = "Instance Name"
}
# Ubuntu Precise 12.04 LTS (x64)
variable "aws_amis" {
default = {
"eu-west-1": "ami-b1cf19c6",
"us-east-1": "ami-de7ab6b6",
"us-west-1": "ami-3f75767a",
"us-west-2": "ami-21f78e11"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment