Last active
February 4, 2022 04:04
-
-
Save solarce/ec87ac9ce10ccb92b0b5 to your computer and use it in GitHub Desktop.
terraform.io example template for ec2 instance with tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} | |
tags {
"Name" = "${var.instance_name}"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
variable "aws_access_key" {
decscription = "AWS Access Key"
}
Typo mistake "description = AWS Access Key"