Skip to content

Commit f404290

Browse files
committed
Initial documentation
1 parent 111073e commit f404290

File tree

5 files changed

+280
-0
lines changed

5 files changed

+280
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Destruindo todos recursos
2+
3+
Lembre-se que executando o passo abaixo, TUDO será excluído.
4+
5+
Para destruir todos os recursos simplemente faça:
6+
7+
```
8+
terraform destroy -auto-approve
9+
```
10+
11+
Com a seguitne saída:
12+
13+
```
14+
module.droplet-web-1.digitalocean_droplet.this: Refreshing state... [id=158144214]
15+
module.project-web-1.digitalocean_project.this: Refreshing state... [id=eb05bbee-3ccc-4a82-941d-35bc3286f5fa]
16+
module.project-web-1.digitalocean_project.this: Destroying... [id=eb05bbee-3ccc-4a82-941d-35bc3286f5fa]
17+
module.project-web-1.digitalocean_project.this: Destruction complete after 2s
18+
module.droplet-web-1.digitalocean_droplet.this: Destroying... [id=158144214]
19+
module.droplet-web-1.digitalocean_droplet.this: Still destroying... [id=158144214, 10s elapsed]
20+
module.droplet-web-1.digitalocean_droplet.this: Still destroying... [id=158144214, 20s elapsed]
21+
module.droplet-web-1.digitalocean_droplet.this: Destruction complete after 23s
22+
23+
Destroy complete! Resources: 2 destroyed.
24+
```
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
## Droplets (Máquinas virtuais)
2+
3+
No exemplo abaixo será criado os seguintes recursos:
4+
5+
* Máquina Virtual.
6+
7+
Arquivo [droplet.tf](/providers/digital-ocean/with-modules/droplet.tf)
8+
9+
Antes é necessário criar o primeiro `Workspace` do projeto.
10+
11+
```
12+
terraform workspace new dev
13+
```
14+
A saída do comando será a seguinte:
15+
16+
```
17+
Created and switched to workspace "dev"!
18+
19+
You're now on a new, empty workspace. Workspaces isolate their state,
20+
so if you run "terraform plan" Terraform will not see any existing state
21+
for this configuration.
22+
```
23+
24+
Executando o comando do Terraform para verificar o que será criado.
25+
26+
```
27+
terraform plan -target=module.droplet-web-1
28+
```
29+
30+
A saída será a seguinte:
31+
32+
```
33+
Refreshing Terraform state in-memory prior to plan...
34+
The refreshed state will be used to calculate this plan, but will not be
35+
persisted to local or remote state storage.
36+
37+
38+
------------------------------------------------------------------------
39+
40+
An execution plan has been generated and is shown below.
41+
Resource actions are indicated with the following symbols:
42+
+ create
43+
44+
Terraform will perform the following actions:
45+
46+
# module.droplet-web-1.digitalocean_droplet.this will be created
47+
+ resource "digitalocean_droplet" "this" {
48+
+ backups = false
49+
+ created_at = (known after apply)
50+
+ disk = (known after apply)
51+
+ id = (known after apply)
52+
+ image = "ubuntu-18-04-x64"
53+
+ ipv4_address = (known after apply)
54+
+ ipv4_address_private = (known after apply)
55+
+ ipv6 = false
56+
+ ipv6_address = (known after apply)
57+
+ ipv6_address_private = (known after apply)
58+
+ locked = (known after apply)
59+
+ memory = (known after apply)
60+
+ monitoring = false
61+
+ name = "web-dev"
62+
+ price_hourly = (known after apply)
63+
+ price_monthly = (known after apply)
64+
+ private_networking = false
65+
+ region = "nyc3"
66+
+ resize_disk = true
67+
+ size = "512mb"
68+
+ status = (known after apply)
69+
+ tags = [
70+
+ "environment:dev",
71+
+ "project:dev-web-app",
72+
+ "team-web-app",
73+
]
74+
+ urn = (known after apply)
75+
+ vcpus = (known after apply)
76+
+ volume_ids = (known after apply)
77+
}
78+
79+
Plan: 1 to add, 0 to change, 0 to destroy.
80+
81+
------------------------------------------------------------------------
82+
83+
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
84+
can't guarantee that exactly these actions will be performed if
85+
"terraform apply" is subsequently run.
86+
```
87+
88+
Criando de fato o primeiro Droplet:
89+
90+
```
91+
terraform apply -target=module.droplet-web-1 -auto-approve
92+
```
93+
94+
A saída do comando será a seguinte:
95+
96+
```
97+
module.droplet-web-1.digitalocean_droplet.this: Creating...
98+
module.droplet-web-1.digitalocean_droplet.this: Still creating... [10s elapsed]
99+
module.droplet-web-1.digitalocean_droplet.this: Creation complete after 18s [id=158144214]
100+
101+
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
102+
```
103+
104+
[Criando Projeto](project.md)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Inicializando Terraform
2+
3+
O primeiro passo de todos é inicializar os módulos que estão sendo utilizados pelo seu projeto e é necessário que esteja dentro do diretório onde está seus recursos.
4+
5+
Executando com o binário.
6+
7+
```
8+
terraform init
9+
```
10+
11+
A saída será mais ou menos a seguinte:
12+
13+
```
14+
Initializing modules...
15+
Downloading raffaeldutra/droplet/digitalocean 1.0.4 for droplet-web-1...
16+
- droplet-web-1 in .terraform/modules/droplet-web-1/raffaeldutra-terraform-digitalocean-droplet-2192
17+
a71
18+
Downloading raffaeldutra/project/digitalocean 1.0.4 for project-web-1...
19+
- project-web-1 in .terraform/modules/project-web-1/raffaeldutra-terraform-digitalocean-project-986a5af
20+
21+
Initializing the backend...
22+
23+
Initializing provider plugins...
24+
- Checking for available provider plugins...
25+
- Downloading plugin for provider "digitalocean" (terraform-providers/digitalocean) 1.7.0...
26+
27+
The following providers do not have any version constraints in configuration,
28+
so the latest version was installed.
29+
30+
To prevent automatic upgrades to new major versions that may contain breaking
31+
changes, it is recommended to add version = "..." constraints to the
32+
corresponding provider blocks in configuration, with the constraint strings
33+
suggested below.
34+
35+
* provider.digitalocean: version = "~> 1.7"
36+
37+
Terraform has been successfully initialized!
38+
39+
You may now begin working with Terraform. Try running "terraform plan" to see
40+
any changes that are required for your infrastructure. All Terraform commands
41+
should now work.
42+
43+
If you ever set or change modules or backend configuration for Terraform,
44+
rerun this command to reinitialize your working directory. If you forget, other
45+
commands will detect it and remind you to do so if necessary.
46+
```
47+
48+
[Criando Máquina Virtual](droplet.md)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
## Criando projetos
2+
3+
No exemplo abaixo será criado os seguintes recursos:
4+
5+
* Projetos. Projetos são utilizados para melhor organização de recursos que são criados dentro de sua conta
6+
7+
Arquivo [project.tf](/providers/digital-ocean/with-modules/project.tf)
8+
9+
Executando o comando do Terraform para verificar o que será criado.
10+
11+
```
12+
terraform plan -target=module.project-web-1
13+
```
14+
15+
A saída será a seguinte:
16+
17+
```
18+
Refreshing Terraform state in-memory prior to plan...
19+
The refreshed state will be used to calculate this plan, but will not be
20+
persisted to local or remote state storage.
21+
22+
module.droplet-web-1.digitalocean_droplet.this: Refreshing state... [id=158144214]
23+
24+
------------------------------------------------------------------------
25+
26+
An execution plan has been generated and is shown below.
27+
Resource actions are indicated with the following symbols:
28+
+ create
29+
30+
Terraform will perform the following actions:
31+
32+
# module.project-web-1.digitalocean_project.this will be created
33+
+ resource "digitalocean_project" "this" {
34+
+ created_at = (known after apply)
35+
+ description = "Project description"
36+
+ environment = "Development"
37+
+ id = (known after apply)
38+
+ name = "dev"
39+
+ owner_id = (known after apply)
40+
+ owner_uuid = (known after apply)
41+
+ purpose = "Project purpose"
42+
+ resources = [
43+
+ "do:droplet:158144214",
44+
]
45+
+ updated_at = (known after apply)
46+
}
47+
48+
Plan: 1 to add, 0 to change, 0 to destroy.
49+
50+
------------------------------------------------------------------------
51+
52+
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
53+
can't guarantee that exactly these actions will be performed if
54+
"terraform apply" is subsequently run.
55+
```
56+
57+
Criando o projeto e inserindo o Droplet anteriomente criado a este projeto:
58+
59+
```
60+
terraform apply -target=module.project-web-1 -auto-approve
61+
```
62+
63+
A saída do comando será a seguinte:
64+
65+
```
66+
module.droplet-web-1.digitalocean_droplet.this: Refreshing state... [id=158144214]
67+
module.project-web-1.digitalocean_project.this: Creating...
68+
module.project-web-1.digitalocean_project.this: Creation complete after 3s [id=eb05bbee-3ccc-4a82-94
69+
1d-35bc3286f5fa]
70+
71+
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
72+
```
73+
74+
[Destruindo tudo](destroy.md)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Digital Ocean
2+
3+
Documentação de como executar a Infraestrutura de forma incremental na Digital Ocean.
4+
5+
## Pré requisitos
6+
7+
Sempre será demonstrado como executar os passos de forma tradicional.
8+
9+
* Para este projeto, foi utilizada versão `0.12.0` do `Terraform`.
10+
* É necessário configurar suas credenciais da Digital Ocean.
11+
12+
Neste exemplo será utilizado variável de ambiente export `TF_VAR_token`.
13+
14+
Esta variável é consumida internamente pelo Terraform conforme visto [aqui na documentação oficial](https://www.terraform.io/docs/commands/environment-variables.html).
15+
16+
Para encontrar o token, vá até a página para geração de token, encontrada em [https://cloud.digitalocean.com/account/api/tokens](https://cloud.digitalocean.com/account/api/tokens)
17+
18+
Exemplo de utlização da variável:
19+
20+
```
21+
export TF_VAR_token=XXXXYYYYYBBBBB
22+
```
23+
24+
## Objetivo
25+
26+
Objetivo principal desta documentação é criar infraestrutura de forma incremental utilizando Digital Ocean como Cloud Provider, da mesma forma como naturalmente sua infra iria crescer de maneira tradicional, mas sem utilizar Infraestrutura como códifo (Infrastructure as Code / IaC).
27+
28+
## Sumário
29+
30+
[Inicializando Terraform](init.md)

0 commit comments

Comments
 (0)