subspace / infra

7 stars 4 forks source link

Subspace Infrastructure.

This project declares the infrastructure currently used by Subspace Network.

We use Terraform and DigitalOcean. Any project, droplet, volume, attachment must be defined in this repository to be reviewed and deployed using IAC.

Terraform projects folder structure:

└──  resources
    └── aries-dev/
    └── aries-test-a/
    └── aries-test-b/
    └── polkadot-archive/
    └── status-page/
    └── telemetry/
    └── common.tf 

To apply any updates or new definitions you must always work in a separate branch and create a Pull Request to the main branch.

Pre requisites.

Install Terraform cli:

Getting started.

Start by defining your personal DigitalOcean access token as an env variable, so you won’t have to set your token each time you run Terraform. You can find your API token in your DigitalOcean account.

export DO_TOKEN=9999999999999999aaaaaaaaaaaaaaa

Go to resources/PROJECT_NAME directory and run the following commands to init terraform:

terraform init

You are ready to run the plan and apply command with this.

Deploy resources.

In the resources/PROJECT_NAME directory, run the following commands:

  1. Run the plan command with the variable values passed in to see Terraform's steps to deploy your project resources.
terraform plan -var "do_token=${DO_TOKEN}" -out current-plan.tfplan
# DO NOT FORGET TO EXPORT DO_TOKEN before running this command. 
  1. Run the apply command with the generated current-plan.tfplan.
terraform apply "current-plan.tfplan"

Terraform will apply changes and generate/update the .tfstate file. Be aware that state files can contain sensitive information. Do not expose it to the public repository.

Note: When creating a new workspace for a project, ensure to change plan execution from remote to local from the workspace->settings->Execution Mode. Choose local so only the state is store and tracked and execution can be done from the local instead of terraform cloud.