-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89c8b95
commit 390d544
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.terraform | ||
terraform.tfstate | ||
terraform.tfstate.backup |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
provider "aws" { | ||
profile = "default" | ||
region = var.region | ||
} | ||
|
||
resource "aws_security_group" "allow_ssh" { | ||
name = "allow_ssh" | ||
description = "Allow ssh inbound traffic" | ||
|
||
ingress { | ||
description = "TLS from VPC" | ||
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"] | ||
} | ||
|
||
tags = { | ||
Name = "allow_ssh" | ||
} | ||
} | ||
|
||
|
||
resource "aws_key_pair" "example" { | ||
key_name = "examplekey" | ||
public_key = file("~/.ssh/example.pub") | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
key_name = aws_key_pair.example.key_name | ||
ami = "ami-04590e7389a6e577c" | ||
instance_type = "t2.micro" | ||
vpc_security_group_ids = ["${aws_security_group.allow_ssh.id}"] | ||
|
||
connection { | ||
type = "ssh" | ||
user = "ec2-user" | ||
private_key = file("~/.ssh/example") | ||
host = self.public_ip | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo amazon-linux-extras enable nginx1.12", | ||
"sudo yum -y install nginx", | ||
"sudo systemctl start nginx" | ||
] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "ip" { | ||
value = aws_instance.example.public_ip | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "region" { | ||
default = "us-west-2" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Read metadata registry | ||
data "docker_registry_image" "nginx" { | ||
name = "nginx:latest" | ||
} | ||
|
||
# Pull image | ||
resource "docker_image" "nginx" { | ||
name = "${data.docker_registry_image.nginx.name}" | ||
keep_locally = false # Delete image from docker local storage on destroy opration | ||
pull_triggers = ["${data.docker_registry_image.nginx.sha256_digest}"] | ||
} | ||
|
||
resource "docker_container" "nginx" { | ||
image = docker_image.nginx.latest | ||
name = "tutorial" | ||
ports { | ||
internal = 80 | ||
external = 8000 | ||
} | ||
} |