Skip to content

Commit

Permalink
Merge pull request #100 from lucascanero/master
Browse files Browse the repository at this point in the history
Add and update the documentation
  • Loading branch information
MiguelNdeCarvalho authored Nov 29, 2022
2 parents eedc376 + a05552b commit 0533221
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
## 📖 Documentation

All the documentation can be found [here](https://docs.solidangle.eu/terrabutler).

## 📋 Project Template

A project template can be found [here](https://github.com/lucascanero/terrabutler-aws-template).
149 changes: 149 additions & 0 deletions docs/create-project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Create a new project

Before proceeding make sure that you have followed the [Installation](installation.md).

## Configure direnv

For direnv to work properly it needs to be hooked into the shell.
Check direnv docs to know more: https://direnv.net/docs/hook.html

Make sure that you have followed direnv documentation before proceeding.


## Configure Terrabutler

### Create your project folder

```shell
mkdir <project_name>
```

### Download Template

Start by downloading the Terrabutler Template Project from the repository source below:

[![Version-shield]](https://github.com/lucascanero/terrabutler-template/archive/refs/heads/example-template.zip)

Copy the files inside `./terrabutler-template/` to the root of your project folder.

```shell
$ cp -a /terrabutler-template/. /<project_name>/
```

### Create a new workspace

Before configuring terrabutler, inside `<project_name>/site_inception` folder, you will need to create a Terraform Workspace:
For example, we are gonna call it "staging"

```shell
$ cd site_inception
$ terraform workspace new staging
```

### Change Variables

Run the script `./<project_name>/config_template.sh`, with the following arguments, located inside the project folder root:

```shell
$ ./config_template.sh -d <domain> -e <environment_name> -p <project_name>

USAGE:
./config_template [FLAG] [STRING]

FLAGS:
-o <organization_name> The name for your organization.
Example: -o example

-d <domain> The domain of your organization.
Example: -d example.com

-e <environment_name> The environment name of your organization.
Example: -e staging
```


???+ danger
This script only works with the template folder! Don't use it in another project folders!
`./terrabutler-template/config_template.sh`

## Terraform

Start by installing Terraform with tfenv:

```shell
$ tfenv install
```

### Initialize the Project

Perform an Terraform Initialization inside site_inception:

```shell
$ cd /site_inception/
$ terraform init
```
Perform an Terraform Apply with the `.tfvars` inside `/config/variables/`:

`./configs/variables/global.tfvars` </br>
`./configs/variables/<project_name>-<environment_name>.tfvars"` </br>
`./configs/variables/<project_name>-<environment_name>-inception.tfvars"`</br>

```shell
$ terraform apply -var-file="../configs/variables/global.tfvars" -var-file="../configs/variables/<project_name>-<environment_name>.tfvars" -var-file="../configs/variables/<project_name>-<environment_name>-inception.tfvars"
```

### Change local to remote backend

#### Uncomment the remote backend line
Remove the commented line as below, in the `terrabutler-template` in the path `./site-inception/terraform.tf` to change from local to remote.

```
backend "s3" {}
```

Perform an Terraform initialization with the backend config file,located in `/configs/backend/` to update the new changes:

```shell
$ terraform init -backend-config=<inception_backend_path>
```

???+ tip
Example:
$ terraform init -backend-config="./configs/backends/<project_name>-<environment_name>-inception.tfvars"

#### Delete the local state

Delete the local state in `/site_inception`, as it is not necessary:

```shell
$ rm -rf terraform.tfstate.d/ terraform.tfstate terraform.tfstate.backup
```

### Terrabutler commands

#### Terrabutler Plan

Perform an Terrabutler Plan to ensure everything is ok, and plan any changes:

```shell
$ terrabutler tf -site inception plan
```
#### Terrabutler Apply

Perform an Terrabutler Apply to apply the planned changes:

```shell
$ terrabutler tf -site inception apply
```
#### Terrabutler Destroy

Perform an Terrabutler Destroy to delete or undo any changes made in the provider:

```shell
$ terrabutler tf -site inception destroy
```


[Version-shield]: https://img.shields.io/badge/terrabutler_Template-Download-%23121011.svg?style=for-the-badge&logo=github&colorA=273133&colorB=0093ee "Latest version"


89 changes: 89 additions & 0 deletions docs/new-site.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Add a new site

## Create a new directory

In the project folder root, create a new diretory called `site_<site-name>`:

```shell
$ mkdir site_<site-name>
```
???+ tip
Replace `<site-name>` with your new site name!

## Configure the new site


### Add the new site to `site_inception` variables file

Add `<site-name>` to the following file, in `inception_projects = []` line:

```
./configs/variables/<project>-<env>-inception.tfvars
```

### Add the new site to Terrabutler settings

Add `<site-name>` to the following file, in `sites: ordered: - <site-name>` line:

```
./configs/settings.yml
```

### Add a new variable file to the Variables Folder

Create a new file called `<project-name>-<env>-<site-name>.tfvars` to the following directory:

```
./configs/variables/<project-name>-<env>-<site-name>.tfvars
```

### Perform an apply in `site_inception`

Run the following command, to update the new configuration on `site_inception`:

```shell
$ terrabutler tf -site inception apply
```

## Add files to the new site

### Add terraform files

Run the following commands to copy the following Terraform files to the site_`<site-name>`:

```shell
$ cd site_<site-name>
```

```shell
$ cp ../site_inception/terraform.tf .
```

```shell
$ cp ../site_inception/provider.tf .
```

### Create Symbolic Links

Run the following commands to create the Symbolic Links:

```shell
$ cd site_<site-name>
```

```shell
$ ln -s ../globals/data.tf ./data_global.tf
```
```shell
$ ln -s ../globals/locals.tf ./locals_globals.tf
```
```shell
$ ln -s ../globals/variables.tf ./variables_globals.tf
```
### Perform an init in the new site

Run the following command:

```shell
$ terrabutler tf -site data init
```
5 changes: 4 additions & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Before you start using you will need to have some tools installed.

These tools are required to be installed for a **Terrabutler** to work properly.

???+ danger
This repository only works on Intel based Processors (x86/x64). Arm/Arm64 or another processor architectures are incompatible!

## Installing requirements

In the list below you have the install instruction for each tool:
Expand All @@ -16,4 +19,4 @@ In the list below you have the install instruction for each tool:

## After checking requirements

You can now proceed to the [installation](installation.md) process of **Terrabutler**.
You can now proceed to the [installation](installation.md) process of **Terrabutler**.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ nav:
- Requirements: requirements.md
- Installation: installation.md
- Basic Usage: usage.md
- Create New Project: create-project.md
- Add New Site : new-site.md

0 comments on commit 0533221

Please sign in to comment.