Skip to content

Commit 0aaee8c

Browse files
committed
v0.0.3
1 parent 4b26e44 commit 0aaee8c

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

README.md

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ You can sign up with my referral link <https://m.do.co/c/0d2d40f6a8a1> and get $
1515
- [For Google Cloud Platform](#for-google-cloud-platform)
1616
- [For Digital Ocean](#for-digital-ocean)
1717
- [SSH Private and Public keys](#ssh-private-and-public-keys)
18-
- [3.- Terraform](#3--terraform)
18+
- [3.- Full Automation: Terraform and Ansible](#3--full-automation-terraform-and-ansible)
1919
- [Google Cloud Platform](#google-cloud-platform)
2020
- [Digital Ocean](#digital-ocean)
21-
- [4.- Ansible](#4--ansible)
22-
- [5.- Access to VPS](#5--access-to-vps)
23-
- [6.- Destroy the VPS](#6--destroy-the-vps)
21+
- [4.- Access to VPS](#4--access-to-vps)
22+
- [5.- Destroy the VPS](#5--destroy-the-vps)
2423
- [:shield: Security](#shield-security)
2524
- [:coffee: Donations](#coffee-donations)
2625
- [Contributing](#contributing)
@@ -29,7 +28,7 @@ You can sign up with my referral link <https://m.do.co/c/0d2d40f6a8a1> and get $
2928

3029
### Requirements
3130

32-
- Terraform installed (Version used: v0.13.0)
31+
- Terraform installed (Version used: v0.13.2)
3332
- Ansible installed (Version used: 2.9.12)
3433
- SSH private and public keys
3534
- Google Cloud Platform or Digital Ocean account.
@@ -67,7 +66,7 @@ cd vps
6766
- Inside credentials folder run `ssh-keygen -t rsa -f offensive` in the terminal. Empty passphrase is ok.
6867
- It creates two files: private and public key.
6968

70-
#### 3.- Terraform
69+
#### 3.- Full Automation: Terraform and Ansible
7170

7271
##### Google Cloud Platform
7372

@@ -82,7 +81,7 @@ Terraform has been successfully initialized!
8281

8382
# Create the resources
8483
$ terraform apply -auto-approve
85-
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
84+
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
8685
Outputs:
8786
external_ip = x.x.x.x
8887
```
@@ -92,7 +91,7 @@ external_ip = x.x.x.x
9291
**Note:** The instance type and the region used are: n1-standard-1 and us-central1. You can change the values on server.tf and main.tf
9392

9493
**Demo**
95-
[![asciicast](https://asciinema.org/a/352900.png)](https://asciinema.org/a/352900)
94+
[![asciicast](https://asciinema.org/a/359398.png)](https://asciinema.org/a/359398)
9695

9796
##### Digital Ocean
9897

@@ -107,7 +106,7 @@ Terraform has been successfully initialized!
107106

108107
# Create the resources
109108
$ terraform apply -auto-approve
110-
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
109+
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
111110
Outputs:
112111
external_ip = x.x.x.x
113112
```
@@ -117,26 +116,9 @@ external_ip = x.x.x.x
117116
**Note:** The droplet type and the region used are: s-2vcpu-4gb and nyc3. You can change the values on server.tf and variables.tf
118117

119118
**Demo**
120-
[![asciicast](https://asciinema.org/a/352901.png)](https://asciinema.org/a/352901)
119+
[![asciicast](https://asciinema.org/a/359408.png)](https://asciinema.org/a/359408)
121120

122-
#### 4.- Ansible
123-
124-
- Enter to ansible folder
125-
- In hosts.yaml change the x.x.x.x by external_ip value copied.
126-
- Run the next command:
127-
128-
```console
129-
$ ansible-playbook playbook.yaml
130-
TASK [Configuration finished] *******************************************************
131-
ok: [x.x.x.x] => {
132-
"msg": "System configured correctly."
133-
}
134-
```
135-
136-
**Demo**
137-
[![asciicast](https://asciinema.org/a/352903.png)](https://asciinema.org/a/352903)
138-
139-
#### 5.- Access to VPS
121+
#### 4.- Access to VPS
140122

141123
- In gcp or digital-ocean folder run the next command. Change x.x.x.x by external_ip value copied.
142124

@@ -148,7 +130,7 @@ $ ssh [email protected] -i ../credentials/offensive
148130
**Demo**
149131
[![asciicast](https://asciinema.org/a/352904.png)](https://asciinema.org/a/352904)
150132

151-
#### 6.- Destroy the VPS
133+
#### 5.- Destroy the VPS
152134

153135
- In gcp or digital-ocean folder run the next command.
154136

@@ -167,7 +149,7 @@ The service fail2ban has been installed to avoid brute force and block non-autho
167149

168150
Thanks for your donations, are always appreciated.
169151

170-
<a href="https://www.buymeacoffee.com/aaaguirrep" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 23px !important; width: 100px !important;" ></a>
152+
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/aaaguirrep)
171153

172154
### Contributing
173155

digital-ocean/server.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ data "template_file" "dev_hosts" {
3838
}
3939
}
4040

41-
4241
resource "null_resource" "sleep-before-ansible" {
43-
triggers= {
42+
triggers = {
4443
template_rendered = data.template_file.dev_hosts.rendered
4544
}
4645

gcp/server.tf

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,36 @@ resource "google_compute_instance" "vm_instance" {
2929
metadata = {
3030
ssh-keys = "${var.username}:${file(var.ssh_public_key)}"
3131
}
32-
}
32+
}
33+
34+
data "template_file" "dev_hosts" {
35+
template = "${file("${path.module}/templates/host.cfg")}"
36+
depends_on = [
37+
google_compute_instance.vm_instance,
38+
]
39+
vars= {
40+
externalIP = join("\n", google_compute_instance.vm_instance.*.network_interface.0.access_config.0.nat_ip)
41+
}
42+
}
43+
44+
resource "null_resource" "sleep-before-ansible" {
45+
triggers = {
46+
template_rendered = data.template_file.dev_hosts.rendered
47+
}
48+
49+
provisioner "local-exec" {
50+
command = "sleep 60"
51+
}
52+
}
53+
54+
resource "null_resource" "dev-hosts" {
55+
depends_on = [
56+
null_resource.sleep-before-ansible,
57+
]
58+
provisioner "local-exec" {
59+
command = "echo '${data.template_file.dev_hosts.rendered}' > ../ansible/hosts.yaml"
60+
}
61+
provisioner "local-exec" {
62+
command = "cd ../ansible && ansible-playbook playbook.yaml "
63+
}
64+
}

gcp/templates/host.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[lab]
2+
${externalIP}

0 commit comments

Comments
 (0)