Skip to content

Refactor to use Terrafrom Module Library #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/globally-load-balanced-apply-destroy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: globally-load-balanced-web-servers Apply-Destroy
on:
schedule:
- cron: "*/15 * * * *"
workflow_dispatch:

jobs:
apply-destroy:
runs-on: ubuntu-latest
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.TEST_DIGITALOCEAN_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
ref: use-tf-module-library
- uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Install Terraform
run: |
TF_VERSION="1.11.4"; apt-get update && sudo apt-get install -y wget unzip
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
unzip terraform_${TF_VERSION}_linux_amd64.zip && sudo mv terraform /usr/local/bin
- name: Run tests
working-directory: ${{ inputs.module_path }}/test/integration
run: |
if [ -d "." ]; then go test ./...; else echo "No tests"; fi
12 changes: 12 additions & 0 deletions .github/workflows/globally-load-balanced-web-servers-pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: globally-load-balanced-web-servers PR Check
on:
pull_request:
paths:
- 'reference-architectures/globally-load-balanced-web-servers/**/*.tf'
- 'reference-architectures/globally-load-balanced-web-servers/test/**/*'

jobs:
call-common:
uses: ./.github/workflows/workflow-terraform-pr-check.yaml
with:
module_path: reference-architectures/globally-load-balanced-web-servers
60 changes: 60 additions & 0 deletions .github/workflows/workflow-terraform-pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This is a reusable workflow called from the other workflows.
# Centralizing in this way allows us to have one place to configure our tests.
on:
workflow_call:
inputs:
module_path:
required: true
type: string

jobs:
validate:
runs-on: ubuntu-latest
container: hashicorp/terraform:1.11
steps:
- uses: actions/checkout@v4
- name: Init & Validate
working-directory: ${{ inputs.module_path }}
run: |
terraform init -backend=false
terraform validate
terraform fmt -check -recursive

tflint:
runs-on: ubuntu-latest
container: ghcr.io/terraform-linters/tflint
steps:
- uses: actions/checkout@v4
- name: Write TFLint config
working-directory: ${{ inputs.module_path }}
run: |
cat <<EOF > .tflint.hcl
plugin "terraform" {
enabled = true
preset = "all"
}
EOF

- name: Run TFLint
working-directory: ${{ inputs.module_path }}
run: |
tflint --init
tflint

terratest:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Install Terraform
run: |
TF_VERSION="1.11.4"; apt-get update && sudo apt-get install -y wget unzip
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
unzip terraform_${TF_VERSION}_linux_amd64.zip && sudo mv terraform /usr/local/bin
- name: Run tests
working-directory: ${{ inputs.module_path }}/test/unit
run: |
if [ -d "." ]; then go test ./...; else echo "No tests"; fi
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used for local development
override.tf
override.tf.json
Expand Down
90 changes: 19 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,26 @@
# Scale with Simplicity on DigitalOcean
# Scale With Simplicty
This repo contains reference architectures developed by DigitalOcean to allow our users to be able to understand how to leverage DigitalOcean Services to support specific use cases. Each reference architecture is provided as a Terraform module allowing you to deploy and test to facilitate learning and rapid development. These reference architecture modules leverage our [Terraform Module Library](./TERRAFORM-MODULE-LIBRARY.md) which contain reusable Terraform Modules addressing specific components of the architectures.

Reference architectures to showcase how users can leverage DigitalOcean's robust cloud platform to build resilient, distributed systems at scale.
**Note**: While these reference architectures are fully functional, they are intended to be used as a reference. Please make sure you validate any of the configuration for your own use case.

<img src="./docs/scale-with-simplicity.png" width="900" height="700" alt="Scale With Simplicity">
## Reference Architectures

## Prerequisites
| Name | Use Case |
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| [Globally Load Balanced Web Servers](./reference-architectures/globally-load-balanced-web-servers) | Load balanced web servers deployed into multiple regions with a global load balancer directing users to the region closest to them. |

- [Terraform](https://www.terraform.io/downloads.html) installed on your machine
- [DigitalOcean Account](https://cloud.digitalocean.com/registrations/new) - Sign up here
- [DigitalOcean API Token](https://cloud.digitalocean.com/account/api/tokens)
## How to Deploy
A typical way to deploy for testing purposes would be to:

## Setup

1. Clone this repository

```bash
git clone https://github.com/digitalocean/scale-with-simplicity.git
cd infrastructure
```

2. Create a `project.tfvars` file with your DigitalOcean API token:

```bash
cp project.tfvars.example project.tfvars
# Add your DO TOKEN
do_token = "your-digitalocean-api-token"
```

Note: Never commit this file to version control!

## Usage

1. Initialize Terraform:

```bash
terraform init
```

2. Review the planned changes:

```bash
terraform plan -var-file=project.tfvars -out project.out
```

3. Apply the changes:

```bash
terraform apply "project.out"
```

4. To destroy the infrastructure:

```bash
terraform destroy -var-file="project.tfvars"
```

## Project Structure

```bash
├── infrastructure/ # Terraform infrastructure code
│ ├── main.tf # Main architecture configuration
│ ├── variables.tf # Architecture variables
│ ├── outputs.tf # Terraform outputs
│ ├── provider.tf # Provider configuration (DigitalOcean)
│ ├── vpc.tf # VPC configuration
│ ├── postgres.tf # PostgreSQL database configuration
│ ├── spaces.tf # DigitalOcean Spaces configuration
│ └── project.tfvars.example # Example project variables file
```

## Security Notes

- Never commit your `project.tfvars` file or any files containing sensitive information
- Keep your DigitalOcean API token secure.
- Review the planned infrasture changes before applying them.
- Ensure you have your DigitalOcean [Personal Access Token](https://docs.digitalocean.com/reference/api/create-personal-access-token/) set in the `DIGITALOCEAN_TOKEN` environment variable.
- Clone the repo
- cd into the `terraform` directory within the reference architecture you want to test
- Create a `tfvars` file with the inputs needed for the reference architecture module.
- run `terrafrom init`
- run `terrafrom plan -var-file <path to tfvars file>`
- run `terrafrom apply -var-file <path to tfvars file>`
- Test
- run `terrafrom destroy -var-file <path to tfvars file>`

If you wish to use the reference architecture as a basis for your own deployment, it's recommended to copy the Terraform files to your own repo and customize them for your needs.

10 changes: 10 additions & 0 deletions TERRAFORM-MODULE-LIBRARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Terraform Module Library
The Reference Architectures included in this repo leverage the reusable Terraform Modules published as part of our Terraform Module Library.

See README in each repo for how to use the module.

| Name | Description | Repo URL |
|-------------------------------------------------|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| terraform-digitalocean-droplet-internet-gateway | Terraform module to create IGW droplets and optional configure DOKS cluster with default route | https://github.com/digitalocean/terraform-digitalocean-droplet-internet-gateway |
| terraform-digitalocean-glb-stack | Terraform module to create a GLB and one or more RLBs | https://github.com/digitalocean/terraform-digitalocean-glb-stack |
| terraform-digitalocean-multi-region-vpc | Terraform module to create two or more VPCs in a fully-meshed peering configuration | https://github.com/digitalocean/terraform-digitalocean-multi-region-vpc |
Binary file removed docs/scale-with-simplicity.png
Binary file not shown.
75 changes: 0 additions & 75 deletions infrastructure/README.md

This file was deleted.

Loading
Loading