Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaguirrep committed Sep 13, 2020
1 parent 4b26e44 commit 0aaee8c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
42 changes: 12 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ You can sign up with my referral link <https://m.do.co/c/0d2d40f6a8a1> and get $
- [For Google Cloud Platform](#for-google-cloud-platform)
- [For Digital Ocean](#for-digital-ocean)
- [SSH Private and Public keys](#ssh-private-and-public-keys)
- [3.- Terraform](#3--terraform)
- [3.- Full Automation: Terraform and Ansible](#3--full-automation-terraform-and-ansible)
- [Google Cloud Platform](#google-cloud-platform)
- [Digital Ocean](#digital-ocean)
- [4.- Ansible](#4--ansible)
- [5.- Access to VPS](#5--access-to-vps)
- [6.- Destroy the VPS](#6--destroy-the-vps)
- [4.- Access to VPS](#4--access-to-vps)
- [5.- Destroy the VPS](#5--destroy-the-vps)
- [:shield: Security](#shield-security)
- [:coffee: Donations](#coffee-donations)
- [Contributing](#contributing)
Expand All @@ -29,7 +28,7 @@ You can sign up with my referral link <https://m.do.co/c/0d2d40f6a8a1> and get $

### Requirements

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

#### 3.- Terraform
#### 3.- Full Automation: Terraform and Ansible

##### Google Cloud Platform

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

# Create the resources
$ terraform apply -auto-approve
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
Outputs:
external_ip = x.x.x.x
```
Expand All @@ -92,7 +91,7 @@ external_ip = x.x.x.x
**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

**Demo**
[![asciicast](https://asciinema.org/a/352900.png)](https://asciinema.org/a/352900)
[![asciicast](https://asciinema.org/a/359398.png)](https://asciinema.org/a/359398)

##### Digital Ocean

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

# Create the resources
$ terraform apply -auto-approve
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
Outputs:
external_ip = x.x.x.x
```
Expand All @@ -117,26 +116,9 @@ external_ip = x.x.x.x
**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

**Demo**
[![asciicast](https://asciinema.org/a/352901.png)](https://asciinema.org/a/352901)
[![asciicast](https://asciinema.org/a/359408.png)](https://asciinema.org/a/359408)

#### 4.- Ansible

- Enter to ansible folder
- In hosts.yaml change the x.x.x.x by external_ip value copied.
- Run the next command:

```console
$ ansible-playbook playbook.yaml
TASK [Configuration finished] *******************************************************
ok: [x.x.x.x] => {
"msg": "System configured correctly."
}
```

**Demo**
[![asciicast](https://asciinema.org/a/352903.png)](https://asciinema.org/a/352903)

#### 5.- Access to VPS
#### 4.- Access to VPS

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

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

#### 6.- Destroy the VPS
#### 5.- Destroy the VPS

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

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

Thanks for your donations, are always appreciated.

<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>
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/aaaguirrep)

### Contributing

Expand Down
3 changes: 1 addition & 2 deletions digital-ocean/server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ data "template_file" "dev_hosts" {
}
}


resource "null_resource" "sleep-before-ansible" {
triggers= {
triggers = {
template_rendered = data.template_file.dev_hosts.rendered
}

Expand Down
34 changes: 33 additions & 1 deletion gcp/server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@ resource "google_compute_instance" "vm_instance" {
metadata = {
ssh-keys = "${var.username}:${file(var.ssh_public_key)}"
}
}
}

data "template_file" "dev_hosts" {
template = "${file("${path.module}/templates/host.cfg")}"
depends_on = [
google_compute_instance.vm_instance,
]
vars= {
externalIP = join("\n", google_compute_instance.vm_instance.*.network_interface.0.access_config.0.nat_ip)
}
}

resource "null_resource" "sleep-before-ansible" {
triggers = {
template_rendered = data.template_file.dev_hosts.rendered
}

provisioner "local-exec" {
command = "sleep 60"
}
}

resource "null_resource" "dev-hosts" {
depends_on = [
null_resource.sleep-before-ansible,
]
provisioner "local-exec" {
command = "echo '${data.template_file.dev_hosts.rendered}' > ../ansible/hosts.yaml"
}
provisioner "local-exec" {
command = "cd ../ansible && ansible-playbook playbook.yaml "
}
}
2 changes: 2 additions & 0 deletions gcp/templates/host.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[lab]
${externalIP}

0 comments on commit 0aaee8c

Please sign in to comment.