Skip to content

Commit

Permalink
Test terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
ledongthuc committed Jul 15, 2020
1 parent 89c8b95 commit 390d544
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform
terraform.tfstate
terraform.tfstate.backup
56 changes: 56 additions & 0 deletions terraform/aws/ec2/main.tf
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"
]
}
}
3 changes: 3 additions & 0 deletions terraform/aws/ec2/out.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "ip" {
value = aws_instance.example.public_ip
}
3 changes: 3 additions & 0 deletions terraform/aws/ec2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "region" {
default = "us-west-2"
}
20 changes: 20 additions & 0 deletions terraform/docker/main.tf
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
}
}

0 comments on commit 390d544

Please sign in to comment.