Skip to content

Commit 660ccce

Browse files
authored
Merge pull request #3 from digitalocean/use-tf-module-library
Refactor to use Terrafrom Module Library
2 parents aacb781 + 8c542b3 commit 660ccce

36 files changed

+1240
-555
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: globally-load-balanced-web-servers Apply-Destroy
2+
on:
3+
schedule:
4+
- cron: "*/15 * * * *"
5+
workflow_dispatch:
6+
7+
jobs:
8+
call-common:
9+
uses: ./.github/workflows/globally-load-balanced-integration-test.yaml
10+
with:
11+
module_path: reference-architectures/globally-load-balanced-web-servers
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: globally-load-balanced-web-servers PR Check
2+
on:
3+
pull_request:
4+
paths:
5+
- 'reference-architectures/globally-load-balanced-web-servers/**/*.tf'
6+
- 'reference-architectures/globally-load-balanced-web-servers/test/**/*'
7+
8+
jobs:
9+
call-common:
10+
uses: ./.github/workflows/workflow-terraform-pr-check.yaml
11+
with:
12+
module_path: reference-architectures/globally-load-balanced-web-servers
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is a reusable workflow called from the other workflows.
2+
# Centralizing in this way allows us to have one place to configure our tests.
3+
on:
4+
workflow_call:
5+
inputs:
6+
module_path:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
integration-test:
12+
runs-on: ubuntu-latest
13+
env:
14+
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.TEST_DIGITALOCEAN_ACCESS_TOKEN }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-go@v5
18+
with:
19+
go-version: "1.24"
20+
- name: Install Terraform
21+
run: |
22+
TF_VERSION="1.11.4"; apt-get update && sudo apt-get install -y wget unzip
23+
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
24+
unzip terraform_${TF_VERSION}_linux_amd64.zip && sudo mv terraform /usr/local/bin
25+
- name: Run tests
26+
working-directory: ${{ inputs.module_path }}/test/integration
27+
run: |
28+
if [ -d "." ]; then go test ./...; else echo "No tests"; fi
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This is a reusable workflow called from the other workflows.
2+
# Centralizing in this way allows us to have one place to configure our tests.
3+
on:
4+
workflow_call:
5+
inputs:
6+
module_path:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
validate:
12+
runs-on: ubuntu-latest
13+
container: hashicorp/terraform:1.11
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Init & Validate
17+
working-directory: ${{ inputs.module_path }}
18+
run: |
19+
terraform init -backend=false
20+
terraform validate
21+
terraform fmt -check -recursive
22+
23+
tflint:
24+
runs-on: ubuntu-latest
25+
container: ghcr.io/terraform-linters/tflint
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Write TFLint config
29+
working-directory: ${{ inputs.module_path }}
30+
run: |
31+
cat <<EOF > .tflint.hcl
32+
plugin "terraform" {
33+
enabled = true
34+
preset = "all"
35+
}
36+
EOF
37+
38+
- name: Run TFLint
39+
working-directory: ${{ inputs.module_path }}
40+
run: |
41+
tflint --init
42+
tflint
43+
44+
terratest:
45+
needs: validate
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: actions/setup-go@v5
50+
with:
51+
go-version: "1.24"
52+
- name: Install Terraform
53+
run: |
54+
TF_VERSION="1.11.4"; apt-get update && sudo apt-get install -y wget unzip
55+
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
56+
unzip terraform_${TF_VERSION}_linux_amd64.zip && sudo mv terraform /usr/local/bin
57+
- name: Run tests
58+
working-directory: ${{ inputs.module_path }}/test/unit
59+
run: |
60+
if [ -d "." ]; then go test ./...; else echo "No tests"; fi

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
crash.log
1010
crash.*.log
1111

12-
# Exclude all .tfvars files, which are likely to contain sensitive data
13-
*.tfvars
14-
*.tfvars.json
15-
1612
# Ignore override files as they are usually used for local development
1713
override.tf
1814
override.tf.json

README.md

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,26 @@
1-
# Scale with Simplicity on DigitalOcean
1+
# Scale With Simplicty
2+
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.
23

3-
Reference architectures to showcase how users can leverage DigitalOcean's robust cloud platform to build resilient, distributed systems at scale.
4+
**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.
45

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

7-
## Prerequisites
8+
| Name | Use Case |
9+
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
10+
| [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. |
811

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

13-
## Setup
14-
15-
1. Clone this repository
16-
17-
```bash
18-
git clone https://github.com/digitalocean/scale-with-simplicity.git
19-
cd infrastructure
20-
```
21-
22-
2. Create a `project.tfvars` file with your DigitalOcean API token:
23-
24-
```bash
25-
cp project.tfvars.example project.tfvars
26-
# Add your DO TOKEN
27-
do_token = "your-digitalocean-api-token"
28-
```
29-
30-
Note: Never commit this file to version control!
31-
32-
## Usage
33-
34-
1. Initialize Terraform:
35-
36-
```bash
37-
terraform init
38-
```
39-
40-
2. Review the planned changes:
41-
42-
```bash
43-
terraform plan -var-file=project.tfvars -out project.out
44-
```
45-
46-
3. Apply the changes:
47-
48-
```bash
49-
terraform apply "project.out"
50-
```
51-
52-
4. To destroy the infrastructure:
53-
54-
```bash
55-
terraform destroy -var-file="project.tfvars"
56-
```
57-
58-
## Project Structure
59-
60-
```bash
61-
├── infrastructure/ # Terraform infrastructure code
62-
│ ├── main.tf # Main architecture configuration
63-
│ ├── variables.tf # Architecture variables
64-
│ ├── outputs.tf # Terraform outputs
65-
│ ├── provider.tf # Provider configuration (DigitalOcean)
66-
│ ├── vpc.tf # VPC configuration
67-
│ ├── postgres.tf # PostgreSQL database configuration
68-
│ ├── spaces.tf # DigitalOcean Spaces configuration
69-
│ └── project.tfvars.example # Example project variables file
70-
```
71-
72-
## Security Notes
73-
74-
- Never commit your `project.tfvars` file or any files containing sensitive information
75-
- Keep your DigitalOcean API token secure.
76-
- Review the planned infrasture changes before applying them.
15+
- 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.
16+
- Clone the repo
17+
- cd into the `terraform` directory within the reference architecture you want to test
18+
- Create a `tfvars` file with the inputs needed for the reference architecture module.
19+
- run `terrafrom init`
20+
- run `terrafrom plan -var-file <path to tfvars file>`
21+
- run `terrafrom apply -var-file <path to tfvars file>`
22+
- Test
23+
- run `terrafrom destroy -var-file <path to tfvars file>`
7724

25+
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.
7826

TERRAFORM-MODULE-LIBRARY.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Terraform Module Library
2+
The Reference Architectures included in this repo leverage the reusable Terraform Modules published as part of our Terraform Module Library.
3+
4+
See README in each repo for how to use the module.
5+
6+
| Name | Description | Repo URL |
7+
|-------------------------------------------------|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
8+
| 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 |
9+
| terraform-digitalocean-glb-stack | Terraform module to create a GLB and one or more RLBs | https://github.com/digitalocean/terraform-digitalocean-glb-stack |
10+
| 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 |

docs/scale-with-simplicity.png

-1.15 MB
Binary file not shown.

infrastructure/README.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)