-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- mv to module aws_instance and provisioner(null_resource) - change their names as `this` - pass common vars - change root var placeholder as array - pass network and ssh vars as required ones
- Loading branch information
1 parent
9291c66
commit e96e931
Showing
6 changed files
with
156 additions
and
76 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
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,71 @@ | ||
data "aws_ami" "ubuntu" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "name" | ||
#values = ["ubuntu/images/hvm-ssd/ubuntu-disco-19.04-amd64-server-*"] | ||
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
owners = ["099720109477"] # Canonical | ||
} | ||
|
||
resource "aws_instance" "this" { | ||
ami = data.aws_ami.ubuntu.id | ||
instance_type = var.instance_type | ||
key_name = var.key_name | ||
associate_public_ip_address = true | ||
subnet_id = var.subnet_id | ||
vpc_security_group_ids = [var.vpc_segurity_group_id] | ||
|
||
tags = { | ||
Name = "${var.prefix}-this-instance" | ||
} | ||
} | ||
|
||
resource "null_resource" "configure-cat-app" { | ||
depends_on = [aws_instance.this] | ||
|
||
// triggers = { | ||
// build_number = timestamp() | ||
// } | ||
|
||
provisioner "file" { | ||
source = "files/" | ||
destination = "/home/ubuntu/" | ||
|
||
connection { | ||
type = "ssh" | ||
user = "ubuntu" | ||
private_key = var.private_key | ||
host = aws_instance.this.public_ip | ||
} | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo apt -y update", | ||
"sleep 15", | ||
"sudo apt -y update", | ||
"sudo apt -y install apache2", | ||
"sudo systemctl start apache2", | ||
"sudo chown -R ubuntu:ubuntu /var/www/html", | ||
"chmod +x *.sh", | ||
"PLACEHOLDER=${var.placeholder} WIDTH=${var.width} HEIGHT=${var.height} PREFIX=${var.prefix} ./deploy_app.sh", | ||
"sudo apt -y install cowsay", | ||
"cowsay Mooooooooooo!", | ||
] | ||
|
||
connection { | ||
type = "ssh" | ||
user = "ubuntu" | ||
private_key = var.private_key | ||
host = aws_instance.this.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,7 @@ | ||
output "catapp_url" { | ||
value = "http://${aws_instance.this.public_dns}" | ||
} | ||
|
||
output "catapp_ip" { | ||
value = "http://${aws_instance.this.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,42 @@ | ||
variable "prefix" { | ||
description = "This prefix will be included in the name of most resources." | ||
} | ||
|
||
variable "instance_type" { | ||
description = "Specifies the AWS instance type." | ||
default = "t3.micro" | ||
} | ||
|
||
variable "height" { | ||
default = "400" | ||
description = "Image height in pixels." | ||
} | ||
|
||
variable "width" { | ||
default = "600" | ||
description = "Image width in pixels." | ||
} | ||
|
||
variable "placeholder" { | ||
type = string | ||
description = "Image-as-a-service URL. Some other fun ones to try are fillmurray.com, placecage.com, placebeard.it, loremflickr.com, baconmockup.com, placeimg.com, placebear.com, placeskull.com, stevensegallery.com, placedog.net" | ||
} | ||
|
||
# Network | ||
variable "subnet_id" { | ||
description = "id of the subnet" | ||
} | ||
|
||
variable "vpc_segurity_group_id" { | ||
description = "id of the security group" | ||
} | ||
|
||
# SSH | ||
variable "key_name" { | ||
description = "Name of the SSH keypair to use in AWS" | ||
} | ||
|
||
|
||
variable "private_key" { | ||
description = "SSH private key" | ||
} |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
output "catapp_url" { | ||
value = "http://${aws_instance.hashicat.public_dns}" | ||
value = [ | ||
for hashicat in module.hashicats : | ||
hashicat.catapp_url | ||
] | ||
} | ||
|
||
output "catapp_ip" { | ||
value = "http://${aws_instance.hashicat.public_ip}" | ||
value = [ | ||
for instance in module.hashicats : | ||
instance.catapp_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