https://github.com/basher83/do_test
Repo to test TF and DO
https://github.com/basher83/do_test
Last synced: 4 months ago
JSON representation
Repo to test TF and DO
- Host: GitHub
- URL: https://github.com/basher83/do_test
- Owner: basher83
- Created: 2025-05-02T16:49:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-02T18:26:14.000Z (about 1 year ago)
- Last Synced: 2025-05-02T18:31:00.358Z (about 1 year ago)
- Language: HCL
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# do_test
An example repo for use with env0. This repository contains a Terraform project to provision a DigitalOcean droplet with a secure firewall and initial configuration using cloud-init. Additionally, Ansible will be used to automate the configuration and management of a Jenkins docker image to the droplet.
## Features
- Deploys a single DigitalOcean droplet with Ubuntu 24.04.
- Sets up a custom `ansible` user with SSH key authentication.
- Installs Python 3, pip, and Docker via cloud-init.
- Configures a firewall to allow only SSH (22), HTTP (80), HTTPS (443), and ICMP.
- Automates the deployment and management of a Jenkins docker image.
## Prerequisites
- [Terraform](https://www.terraform.io/downloads.html) >= 1.0
- A [DigitalOcean API token](https://cloud.digitalocean.com/account/api/tokens)
- Your SSH key added to your DigitalOcean account
## Usage
1. **Clone the repository:**
```sh
git clone https://github.com/yourusername/do_test.git
cd do_test/terraform
```
2. **Set your variables:**
- Copy `terraform.tfvars.example` to `terraform.tfvars` (if present) or set variables via environment or CLI.
- Required variables:
- `do_token` (DigitalOcean API token)
- `ssh_fingerprint` (Your SSH key fingerprint from DigitalOcean)
3. **Initialize Terraform:**
```sh
terraform init
```
4. **Plan the deployment:**
```sh
terraform plan
```
5. **Apply the configuration:**
```sh
terraform apply
```
6. **Access your droplet:**
- Find the public IP in the Terraform output or DigitalOcean dashboard.
- SSH as the default user (e.g., `root` or `ubuntu`) or as `ansible`:
```sh
ssh ansible@
```
## File Structure
```
terraform/
main.tf # Main Terraform configuration
variables.tf # Input variables
outputs.tf # Output values (e.g., droplet IP)
digitalocean.tftpl # cloud-init template for droplet provisioning
README.md # This file
```
## Notes
- The public SSH key in the repo is for demonstration. Replace it with your own for real deployments.
- For production, restrict SSH access in the firewall to your IP.
- Destroy resources when done to avoid charges:
```sh
terraform destroy
```
## Resources
- [Terraform DigitalOcean Provider Docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs)
- [DigitalOcean Cloud-Init Docs](https://docs.digitalocean.com/products/droplets/how-to/use-cloud-init/
---