Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c1d01d3
Code after end of class
topfunky Dec 2, 2017
aae9fd8
Add variable declarations for all values
topfunky Dec 2, 2017
a6ba40e
Default to creating one instance
topfunky Dec 4, 2017
c52e9e6
Bundle Go app and deploy with terraform
topfunky Dec 4, 2017
ad5e892
Remove echo module
topfunky Dec 4, 2017
ccb623a
Fix whitespace and trailing comma
topfunky Dec 4, 2017
1e705ca
Refactor to a module
topfunky Dec 4, 2017
3ef4e52
Set version for AWS provider
topfunky Dec 5, 2017
87f612b
Revert to `num_webs` instead of `total_webs`
topfunky Dec 6, 2017
b6cc88e
Refactor variable names to match lab
topfunky Dec 6, 2017
65309e1
Simplify server setup with a script
topfunky Dec 7, 2017
4bcfac4
Rename variables to match attribute names
topfunky Dec 7, 2017
967c69e
Fix path to script
topfunky Dec 7, 2017
586713b
Cleanup unused code. Remove redundant default.
topfunky Dec 13, 2017
f05db9e
Merge from `master`
topfunky Dec 19, 2017
07caf8e
Ensure that webapp starts on reboot
topfunky Jan 25, 2018
fab53b0
Remove 'foo' and 'bar' tags in favor of something more realistic
topfunky Jan 31, 2018
5cf2589
Formatting
topfunky Jan 31, 2018
b52dd53
Update main.tf
usmc686 Aug 7, 2018
d2daafd
Update main.tf
usmc686 Aug 7, 2018
bd2a35d
Update main.tf
usmc686 Aug 7, 2018
338639f
Update main.tf
usmc686 Aug 7, 2018
8490eed
Merge pull request #2 from usmc686/usmc686-patch-2
usmc686 Aug 7, 2018
eb7eb24
Update main.tf
usmc686 Aug 7, 2018
96b7aff
Merge pull request #1 from usmc686/usmc686-patch-1-1
usmc686 Aug 7, 2018
4806545
Update main.tf
usmc686 Aug 7, 2018
eb1e6d8
Update main.tf
usmc686 Aug 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/setup-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ cp /tmp/assets/webapp /usr/local/bin/
chmod +x /usr/local/bin/*
cp /tmp/assets/webapp.service /lib/systemd/system/webapp.service
service webapp start
systemctl enable webapp

4 changes: 4 additions & 0 deletions assets/webapp.service
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[Install]
WantedBy=multi-user.target

[Unit]
Description=Demo web app

[Service]
ExecStart=/usr/local/bin/webapp >> /var/log/webapp.log
IgnoreSIGPIPE=false
KillMode=process
Restart=on-failure

49 changes: 44 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
terraform {
required_version = ">= 0.11.0"
}

variable "access_key" {}
variable "secret_key" {}
variable "public_key" {}
variable "private_key" {}

variable "region" {
default = "us-east-1"
}

variable "ami" {}
variable "subnet_id" {}
variable "vpc_security_group_id" {}
variable "identity" {}

variable "num_webs" {
default = "1"
}

provider "aws" {
access_key = ""
secret_key = ""
region = ""
version = "~> 1.5"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}

module "server" {
source = "./server"

num_webs = "${var.num_webs}"
ami = "${var.ami}"
subnet_id = "${var.subnet_id}"
vpc_security_group_id = "${var.vpc_security_group_id}"
identity = "${var.identity}"
public_key = "${var.public_key}"
private_key = "${var.private_key}"
}

output "public_ip" {
value = "${module.server.public_ip}"
}

resource "aws_instance" "web" {
# ...
output "public_dns" {
value = "${module.server.public_dns}"
}
39 changes: 39 additions & 0 deletions server/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "ami" {}

variable "num_webs" {}

variable "subnet_id" {}
variable "vpc_security_group_id" {}
variable "identity" {}
variable "public_key" {}
variable "private_key" {}

resource "aws_key_pair" "training" {
key_name = "${var.identity}-key"
public_key = "${var.public_key}"
}

resource "aws_instance" "web" {
ami = "${var.ami}"
instance_type = "t2.nano"
count = "${var.num_webs}"

subnet_id = "${var.subnet_id}"
vpc_security_group_ids = ["${var.vpc_security_group_id}"]

key_name = "${aws_key_pair.training.id}"

tags {
"Name" = "web ${count.index+1}/${var.num_webs}"
"Identity" = "${var.identity}"
"Created by" = "Terraform"
}
}

output "public_ip" {
value = ["${aws_instance.web.*.public_ip}"]
}

output "public_dns" {
value = ["${aws_instance.web.*.public_dns}"]
}