scripts for launch instance
# main.tf
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "instance_type" {}
provider "aws" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
profile = "default"
region = "us-east-2"
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "elvis_test" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = var.instance_type
// name of instance
tags = {
Name = "test_name"
}
}
// add elasticIP to instance
resource "aws_eip" "ip" {
vpc = true
instance = aws_instance.elvis_test.id
}
output "image_id" {
value = "${data.aws_ami.ubuntu.id}"
}
# terraform.tfvars
aws_access_key = "YOUR_AWS_ACCESS_KEY"
aws_secret_key = "YOUR_AWS_SECRET_KEY"
instance_type = "type_of_aws_instance" # t2.micro etc
# versions.tf
terraform {
required_version = ">= 0.12"
}
terraform init
terraform apply