Skip to content

Instantly share code, notes, and snippets.

@AnthonyLaw
Created June 1, 2019 15:44
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 AnthonyLaw/0738a40d9f7e46111f6d670aa7684fdc to your computer and use it in GitHub Desktop.
Save AnthonyLaw/0738a40d9f7e46111f6d670aa7684fdc to your computer and use it in GitHub Desktop.
aws-instance-terraform-example
provider "aws" {
region = "ap-southeast-1"
access_key = ""
secret_key = ""
resource "aws_instance" "ec2" { # I called name "ec2", you can change your own name
ami = "ami-0dad20bd1b9c8c004" # Image: Ubuntu Server 18.04 LTS (HVM), SSD Volume Type
instance_type = "t2.micro" # VM Spec
security_groups = ["${aws_security_group.allow_ssh.name}"]
key_name = "aws-anthony"
}
resource "aws_security_group" "allow_ssh" {
name = "allow ssh"
description = "only ssh"
ingress {
from_port = 22
to_port = 22
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
output "showPublicIP" {
value = "${aws_instance.ec2.*.public_dns}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment