generated from mentoriaiac/template-modulo-terraform
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4fc1f88
Showing
12 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: "Terraform Valida Modulo" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
terraform: | ||
uses: "mentoriaiac/cicd_centralizado/.github/workflows/terraform_valida_modulo.yaml@v1" | ||
secrets: | ||
token: ${{ secrets.TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
.terraform* | ||
|
||
#terraform inc files | ||
terraform.inc | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
|
||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most | ||
# .tfvars files are managed as part of configuration and so should be included in | ||
# version control. | ||
# | ||
# example.tfvars | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
tfplan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 | | ||
| <a name="requirement_hashicups"></a> [hashicups](#requirement\_hashicups) | ~> 0.3.1 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_hashicups"></a> [hashicups](#provider\_hashicups) | 0.3.1 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [hashicups_order.order](https://registry.terraform.io/providers/hashicorp/hashicups/latest/docs/resources/order) | resource | | ||
| [hashicups_coffees.all](https://registry.terraform.io/providers/hashicorp/hashicups/latest/docs/data-sources/coffees) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_order"></a> [order](#input\_order) | Mapa de cafe e quantidade | `map(number)` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_order_id"></a> [order\_id](#output\_order\_id) | n/a | | ||
|
||
## Como usar esse módulo | ||
[Acesse o passo-a-passo](how-to-use-this-module/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
INCLUDE_MAKEFILE=terraform.inc | ||
VERSION_MAKEFILE=v1.0.0 | ||
REMOTE_MAKEFILE=https://raw.githubusercontent.com/mentoriaiac/Makefiles/${VERSION_MAKEFILE}/${INCLUDE_MAKEFILE} | ||
TARGET_FOLDER=how-to-use-this-module | ||
TARGET_ENV=.target.env | ||
TERRAFORM_VERSION=1.0.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
SHELL = /bin/bash | ||
|
||
cnf ?= .env | ||
ifneq ($(shell test -e $(cnf) && echo -n yes),yes) | ||
ERROR := $(error $(cnf) file not defined in current directory) | ||
endif | ||
|
||
include $(cnf) | ||
export $(shell sed 's/=.*//' $(cnf)) | ||
|
||
ifneq ($(shell test -e $(INCLUDE_MAKEFILE) && echo -n yes),yes) | ||
ifdef REMOTE_MAKEFILE | ||
REMOTE_MAKEFILE_RESULT := $(shell curl ${REMOTE_MAKEFILE} -o ${INCLUDE_MAKEFILE}) | ||
else | ||
ERROR := $(error REMOTE_MAKEFILE not provided, look for your .env file) | ||
endif | ||
endif | ||
|
||
ifdef INCLUDE_MAKEFILE | ||
include ${INCLUDE_MAKEFILE} | ||
endif | ||
|
||
build: plan | ||
deploy: apply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Template de módulo Terraform | ||
|
||
## Dependências | ||
|
||
Para realizar os testes localmente é necessário: | ||
|
||
| Ferramentas | Versão | Instalação | | ||
| ----------- | ------ | ---------- | | ||
| Terraform | >= 1.0.0 | [Acesse](https://learn.hashicorp.com/tutorials/terraform/install-cli) | | ||
| Docker | >= 20.10 | [Acesse](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04-pt) | | ||
| Shipyard.run | >= 0.3.36 | [Acesse](https://shipyard.run/docs/install) | | ||
| Git | >= 2.30.2 | [Acesse](https://git-scm.com/downloads) | | ||
|
||
# Criando o ambiente para a API do Hashicups | ||
|
||
Instalação do Shipyard.run | ||
|
||
``` | ||
curl https://shipyard.run/install | bash | ||
``` | ||
|
||
Clone o repositório e acesse a pasta blueprint | ||
|
||
``` | ||
git clone https://github.com/hashicorp-demoapp/product-api-go | ||
cd product-api-go/blueprint/ | ||
``` | ||
|
||
Inicie a aplicação executando o comando a baixo | ||
|
||
``` | ||
shipyard run | ||
``` | ||
|
||
Saída Esperada | ||
|
||
```bash | ||
|
||
The API can be accessed at | ||
[http://localhost:19090/coffees](http://localhost:19090/coffees) | ||
|
||
``` | ||
|
||
Crie um usuário para a aplicação | ||
|
||
``` | ||
curl -X POST localhost:19090/signup -d '{"username":"mentoriaiac", "password":"2021@mentoria"}' | ||
``` | ||
|
||
# Utilizando o módulo | ||
|
||
### Primeiro Passo: | ||
|
||
Acesse o repósitorio do módulo : | ||
|
||
<pre> | ||
|
||
├── product-api-go | ||
│ ├── blueprint | ||
│ ├── client | ||
│ ├── config | ||
│ ├── data | ||
│ │ └── model | ||
│ ├── database | ||
│ ├── docker_compose | ||
│ ├── functional_tests | ||
│ │ └── features | ||
│ ├── handlers | ||
│ └── telemetry | ||
<b>└── template-modulo-terraform </b> | ||
└── how-to-use-this-module | ||
|
||
</pre> | ||
|
||
Depois acesse a pasta how-to-use-this-module | ||
|
||
``` | ||
cd ./how-to-use-this-module/ | ||
``` | ||
|
||
Inicialize o Terraform | ||
|
||
``` | ||
terraform init | ||
``` | ||
|
||
### Segundo Passo: | ||
|
||
Personalize o `terrafile.tf`: | ||
|
||
``` | ||
order = { | ||
Terraspresso = 4, | ||
Nomadicano = 10, | ||
"Vagrante espresso" = 4, | ||
Packer Spiced Latte = 6, | ||
Vaulatte = 8, | ||
Connectaccino = 2 | ||
} | ||
``` | ||
|
||
Tente criar o primeiro plan: | ||
``` | ||
terraform plan | ||
``` | ||
|
||
Obs.: Caso retorne erro 401, verifique o usuário e a senha. | ||
|
||
### Terceiro Passo: | ||
|
||
Aplique suas mudanças: | ||
|
||
``` | ||
terraform apply | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
provider "hashicups" { | ||
username = "mentoriaiac" | ||
password = "2021@mentoria" | ||
} | ||
|
||
module "hashicups_order" { | ||
source = "../" | ||
order = { | ||
Terraspresso = 4, | ||
Nomadicano = 10 | ||
} | ||
} | ||
|
||
output "hashicups_order_id" { | ||
value = module.hashicups_order.order_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
data "hashicups_coffees" "all" {} | ||
|
||
locals { | ||
coffee_name_id_map = { for coffee in data.hashicups_coffees.all.coffees : coffee.name => coffee.id } | ||
} | ||
|
||
resource "hashicups_order" "order" { | ||
dynamic "items" { | ||
for_each = var.order | ||
content { | ||
coffee { | ||
id = local.coffee_name_id_map[items.key] | ||
} | ||
quantity = items.value | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "order_id" { | ||
value = resource.hashicups_order.order.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variable "order" { | ||
description = "Mapa de cafe e quantidade" | ||
type = map(number) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
required_providers { | ||
hashicups = { | ||
version = "~> 0.3.1" | ||
} | ||
} | ||
} | ||
|