Skip to content

Commit 14ca4cd

Browse files
committed
workshop01
0 parents  commit 14ca4cd

File tree

9 files changed

+205
-0
lines changed

9 files changed

+205
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform.tfvars
2+
*.tfvars
3+
*.tfstate
4+
*.tfstate.backup
5+
.terraform/

.terraform.lock.hcl

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/hello.gif

1.06 MB
Loading

assets/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<h1>hello, world</h1>
11+
12+
<h2>My IP address is <code style="color: red;">178.128.222.46</code></h2>
13+
14+
<div>
15+
<img src="hello.gif" >
16+
</div>
17+
18+
</body>
19+
</html>

assets/index.html.tftpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<h1>hello, world</h1>
11+
12+
<h2>My IP address is <code style="color: red;">${droplet_ip}</code></h2>
13+
14+
<div>
15+
<img src="hello.gif" >
16+
</div>
17+
18+
</body>
19+
</html>

nginx-178.128.222.46.nip.io

Whitespace-only changes.

providers.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
terraform {
2+
required_providers {
3+
local = {
4+
source = "hashicorp/local"
5+
version = "2.5.2"
6+
}
7+
digitalocean = {
8+
source = "digitalocean/digitalocean"
9+
version = "2.48.2"
10+
}
11+
}
12+
}
13+
14+
provider "local" {
15+
}
16+
17+
provider "digitalocean" {
18+
token = var.DO_key
19+
}

resources.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
resource "digitalocean_ssh_key" "workshop01" {
2+
name = "workshop01"
3+
public_key = file(var.public_key)
4+
}
5+
6+
resource "digitalocean_droplet" "nginx" {
7+
name = "nginx"
8+
image = var.droplet_image
9+
size = var.droplet_size
10+
region = var.droplet_region
11+
ssh_keys = [ digitalocean_ssh_key.workshop01.id ]
12+
13+
connection {
14+
type = "ssh"
15+
user = "root"
16+
private_key = file(var.private_key)
17+
host = self.ipv4_address
18+
}
19+
20+
provisioner "remote-exec" {
21+
inline = [
22+
"apt update",
23+
"apt install -y nginx",
24+
"systemctl start nginx",
25+
"systemctl enable nginx"
26+
27+
]
28+
}
29+
provisioner file {
30+
source = "/root/terraform/nginx/assets/"
31+
destination = "/var/www/html/"
32+
}
33+
}
34+
35+
resource "local_file" "index_html" {
36+
filename = "/root/terraform/nginx/assets/index.html"
37+
file_permission = "0644"
38+
content = templatefile("/root/terraform/nginx/assets/index.html.tftpl", {
39+
droplet_ip = digitalocean_droplet.nginx.ipv4_address
40+
}
41+
)
42+
}
43+
44+
resource "local_file" "nginx_dns" {
45+
filename = "nginx-${digitalocean_droplet.nginx.ipv4_address}.nip.io"
46+
content = ""
47+
file_permission = "0444"
48+
}
49+
50+
output "coursekey_fingerprint" {
51+
description = "Fingerprint of public key"
52+
value = digitalocean_ssh_key.workshop01.fingerprint
53+
}
54+
55+
output "nginx_ip" {
56+
description = "ip of nginx"
57+
value = digitalocean_droplet.nginx.ipv4_address
58+
}

variables.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "DO_key" {
2+
type = string
3+
description = "DO Key"
4+
default = "set this"
5+
sensitive = true
6+
}
7+
8+
variable "public_key_name" {
9+
type = string
10+
default = "ravi-digital-ocean"
11+
}
12+
13+
variable "droplet_size" {
14+
type = string
15+
default =" s-1vcpu-1gb"
16+
}
17+
18+
variable "droplet_image" {
19+
type = string
20+
default = "ubuntu-24-04-x64"
21+
}
22+
23+
variable "droplet_region" {
24+
type = string
25+
default = "sgp1"
26+
}
27+
28+
variable "ssh_keys" {
29+
type = string
30+
default = "workshop01"
31+
}
32+
33+
variable "public_key" {
34+
type = string
35+
}
36+
37+
variable "private_key" {
38+
type = string
39+
}

0 commit comments

Comments
 (0)