Created
June 1, 2019 15:44
-
-
Save AnthonyLaw/0738a40d9f7e46111f6d670aa7684fdc to your computer and use it in GitHub Desktop.
aws-instance-terraform-example
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
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