You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this session, we are going to be creating a VM or two VMs using terraform inside VirtualBox. This is not normal, VirtualBox is a workstation virtualisation option and this would not be a use case for Terraform but I am currently 36,000ft in the air and as much as I have deployed public cloud resources this high in the clouds it is much faster to do this locally on my laptop.
3
+
En esta sesión, vamos a crear una o dos VMs utilizando Terraform dentro de VirtualBox. Esto no es lo habitual, ya que VirtualBox es una opción de virtualización de estaciones de trabajo y este no sería un caso de uso típico para Terraform, pero actualmente estoy a 36,000 pies de altura y, aunque he implementado recursos de la nube pública a esta altitud en las nubes, es mucho más rápido hacerlo localmente en mi computadora portátil.
4
4
5
-
Purely for demo purposes but the concept is the same we are going to have our desired state configuration code and then we are going to run that against the VirtualBox provider. In the past, we have used vagrant here and I covered the differences between vagrant and terraform at the beginning of the section.
5
+
Solo con fines de demostración, pero el concepto es el mismo: vamos a tener nuestro código de configuración de estado deseado y luego lo ejecutaremos con el proveedor de VirtualBox. En el pasado, hemos utilizado Vagrant aquí y ya he cubierto las diferencias entre Vagrant y Terraform al principio de la sección.
6
+
Crear una máquina virtual en VirtualBox
6
7
7
-
### Create a virtual machine in VirtualBox
8
+
##Lo primero que vamos a hacer es crear una nueva carpeta llamada VirtualBox. Luego podemos crear un archivo VirtualBox.tf y ahí es donde definiremos nuestros recursos. El siguiente código, que se encuentra en la carpeta VirtualBox como VirtualBox.tf, creará 2 VMs en VirtualBox.
8
9
9
-
The first thing we are going to do is create a new folder called VirtualBox, we can then create a VirtualBox.tf file and this is going to be where we define our resources. The code below which can be found in the VirtualBox folder as VirtualBox.tf is going to create 2 VMs in Virtualbox.
10
+
Puedes encontrar más información sobre el proveedor de VirtualBox de la comunidad aquí[here](https://registry.terraform.io/providers/terra-farm/virtualbox/latest/docs/resources/vm)
10
11
11
-
You can find more about the community VirtualBox provider [here](https://registry.terraform.io/providers/terra-farm/virtualbox/latest/docs/resources/vm)
12
-
13
-
```
12
+
```terraform
14
13
terraform {
15
14
required_providers {
16
15
virtualbox = {
@@ -20,7 +19,7 @@ terraform {
20
19
}
21
20
}
22
21
23
-
# There are currently no configuration options for the provider itself.
22
+
# Actualmente no hay opciones de configuración para el propio proveedor.
24
23
25
24
resource "virtualbox_vm" "node" {
26
25
count = 2
@@ -45,53 +44,48 @@ output "IPAddr_2" {
45
44
46
45
```
47
46
48
-
Now that we have our code defined we can now perform the `terraform init`on our folder to download the provider for Virtualbox.
47
+
Ahora que hemos definido nuestro código, podemos ejecutar `terraform init`en nuestra carpeta para descargar el proveedor de VirtualBox.
49
48
50
49

51
50
52
-
You will also need to have VirtualBox installed on your system as well. We can then next run `terraform plan` to see what our code will create for us. Followed by`terraform apply` the below image shows your completed process.
51
+
También necesitarás tener VirtualBox instalado en tu sistema. A continuación, podemos ejecutar terraform plan para ver qué creará nuestro código. Luego, ejecutamos`terraform apply`. La siguiente imagen muestra el proceso completo.
53
52
54
53

55
54
56
-
In Virtualbox, you will now see your 2 virtual machines.
55
+
En VirtualBox, ahora verás tus 2 máquinas virtuales.
57
56
58
57

59
58
60
-
### Change configuration
59
+
### Cambiar la configuración
61
60
62
-
Let's add another node to our deployment. We can simply change the count line to show our new desired number of nodes. When we run our `terraform apply` it will look something like the below.
61
+
Agreguemos otro nodo a nuestra implementación. Simplemente podemos cambiar la línea de conteo para indicar nuestro nuevo número deseado de nodos. Cuando ejecutemos `terraform apply`, se verá algo como lo siguiente.
63
62
64
63

65
64
66
-
Once complete in VirtualBox you can see we now have 3 nodes up and running.
65
+
Una vez que se complete, en VirtualBox verás que ahora tenemos 3 nodos en funcionamiento.
67
66
68
67

69
68
70
-
When we are finished we can clear this up using the `terraform destroy`and our machines will be removed.
69
+
Cuando hayamos terminado, podemos limpiar esto utilizando `terraform destroy`y nuestras máquinas serán eliminadas.
71
70
72
71

73
72
74
-
### Variables & Outputs
75
-
76
-
We did mention outputs when we ran our hello-world example in the last session. But we can get into more detail here.
77
-
78
-
But there are many other variables that we can use here as well, there are also a few different ways in which we can define variables.
79
-
80
-
- We can manually enter our variables with the `terraform plan` or `terraform apply` command
81
-
82
-
- We can define them in the .tf file within the block
83
-
84
-
- We can use environment variables within our system using `TF_VAR_NAME` as the format.
73
+
### Variables y Salidas
85
74
86
-
- My preference is to use a terraform.tfvars file in our project folder.
75
+
Mencionamos las salidas cuando ejecutamos nuestro ejemplo de "hola mundo" en la última sesión. Pero aquí podemos entrar en más detalle.
87
76
88
-
- There is an \*auto.tfvars file option
77
+
Pero hay muchas otras variables que podemos utilizar aquí, también hay algunas formas diferentes en las que podemos definir variables.
89
78
90
-
- or we can define when we run the `terraform plan` or `terraform apply` with the `-var` or `-var-file`.
79
+
- Podemos ingresar manualmente nuestras variables con el comando `terraform plan` o `terraform apply`.
80
+
- Podemos definirlas en el archivo .tf dentro del bloque correspondiente.
81
+
- Podemos utilizar variables de entorno en nuestro sistema utilizando el formato `TF_VAR_NOMBRE`.
82
+
- Mi preferencia es usar un archivo terraform.tfvars en la carpeta de nuestro proyecto.
83
+
- Existe la opción de utilizar un archivo \*auto.tfvars.
84
+
- También podemos definir las variables al ejecutar `terraform plan` o `terraform apply` con las opciones `-var` o `-var-file`.
91
85
92
-
Starting from the bottom moving up would be the order in which the variables are defined.
86
+
Comenzando desde abajo y avanzando hacia arriba, así se define el orden en el que se definen las variables.
93
87
94
-
We have also mentioned that the state file will contain sensitive information. We can define our sensitive information as a variable and we can define this as being sensitive.
88
+
También hemos mencionado que el archivo de estado contendrá información confidencial. Podemos definir nuestra información confidencial como una variable y especificar que es confidencial.
95
89
96
90
```
97
91
variable "some resource" {
@@ -102,9 +96,9 @@ variable "some resource" {
102
96
}
103
97
```
104
98
105
-
## Resources
99
+
## Recursos
106
100
107
-
I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
101
+
He enumerado muchos recursos a continuación y creo que este tema ha sido cubierto tantas veces, si tienes recursos adicionales, asegúrate de enviar una solicitud de extracción (PR) con tus recursos y estaré encantado de revisarlos y agregarlos a la lista.
108
102
109
103
-[What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
Copy file name to clipboardExpand all lines: 2022/es/Days/day60.md
+31-30Lines changed: 31 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
## Docker Containers, Provisioners & Modules
1
+
## Contenedores de Docker, provisionadores y módulos
2
2
3
-
On [Day 59](day59.md)we provisioned a virtual machine using Terraform to our local FREE VirtualBox environment. In this section, we are going to deploy a Docker container with some configuration to our local Docker environment.
3
+
En el [Dí 59](day59.md)provisionamos una máquina virtual utilizando Terraform en nuestro entorno local de VirtualBox GRATIS. En esta sección, vamos a implementar un contenedor de Docker con alguna configuración en nuestro entorno local de Docker.
4
4
5
-
### Docker Demo
5
+
### Demostración de Docker
6
6
7
-
First up we are going to use the code block below, the outcome of the below is that we would like a simple web app to be deployed into docker and to publish this so that it is available to our network. We will be using nginx and we will make this available externally on our laptop over localhost and port 8000. We are using a docker provider from the community and you can see the docker image we are using also stated in our configuration.
7
+
Primero, vamos a utilizar el bloque de código a continuación. El resultado de esto es que queremos desplegar una aplicación web simple en Docker y publicarla para que esté disponible en nuestra red. Vamos a utilizar nginx y lo haremos disponible externamente en nuestro portátil a través de localhost y el puerto 8000. Estamos utilizando un proveedor de Docker de la comunidad y también puedes ver la imagen de Docker que estamos utilizando en nuestra configuración.
The first task is to use `terraform init`command to download the provider to our local machine.
36
+
La primera tarea es utilizar el comando `terraform init`para descargar el proveedor en nuestra máquina local.
37
37
38
38

39
39
40
-
We then run our `terraform apply`followed by`docker ps`and you can see we have a running container.
40
+
Luego ejecutamos `terraform apply`seguido de`docker ps`y puedes ver que tenemos un contenedor en ejecución.
41
41
42
42

43
43
44
-
If we then open a browser we can navigate to `http://localhost:8000/` and you will see we have access to our NGINX container.
44
+
Si abrimos un navegador y navegamos a `http://localhost:8000/`, verás que tenemos acceso a nuestro contenedor NGINX.
45
45
46
46

47
47
48
-
You can find out more information on the[Docker Provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container)
48
+
Puedes encontrar más información sobre[Docker Provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container)
49
49
50
-
The above is a very simple demo of what can be done with Terraform plus Docker and how we can now manage this under the Terraform state. We covered docker-compose in the containers section and there is a little crossover in a way between this, infrastructure as code as well as then Kubernetes.
50
+
Lo anterior es una demostración muy sencilla de lo que se puede hacer con Terraform y Docker, y cómo podemos administrarlo ahora bajo el estado de Terraform. Cubrimos docker-compose en la sección de contenedores y hay un poco de superposición en cierto sentido entre esto, la infraestructura como código y luego Kubernetes.
51
51
52
-
To show this and how Terraform can handle a little more complexity, we are going to take the docker-compose file for WordPress and MySQL that we created with docker-compose and we will put this to Terraform. You can find the[docker-wordpress.tf](2022/Days/IaC/Docker-WordPress/docker-WordPress.tf)
52
+
Para mostrar esto y cómo Terraform puede manejar un poco más de complejidad, vamos a tomar el archivo docker-compose de WordPress y MySQL que creamos con docker-compose y lo vamos a poner en Terraform. Puedes encontrar el[docker-wordpress.tf](2022/Days/IaC/Docker-WordPress/docker-WordPress.tf)
We again put this in a new folder and then run our`terraform init`command to pull down our provisioners required.
114
+
Nuevamente, colocamos esto en una nueva carpeta y luego ejecutamos el comando`terraform init`para descargar los provisionadores requeridos.
115
115
116
116

117
117
118
-
We then run our`terraform apply`command and then take a look at our docker ps output we should see our newly created containers.
118
+
Luego ejecutamos el comando`terraform apply`y luego echamos un vistazo a la salida de `docker ps` y deberíamos ver nuestros contenedores recién creados.
119
119
120
120

121
121
122
-
We can then also navigate to our WordPress front end. Much like when we went through this process with docker-compose in the containers section we can now run through the setup and our WordPress posts would be living in our MySQL database.
122
+
También podemos navegar a nuestra interfaz de WordPress. Al igual que cuando pasamos por este proceso con docker-compose en la sección de contenedores, ahora podemos realizar la configuración y nuestras publicaciones de WordPress estarían en nuestra base de datos de MySQL.
123
123
124
124

125
125
126
-
Now we have covered containers and Kubernetes in some detail, we probably know that this is ok for testing but if you were going to be running a website you would not do this with containers alone and you would look at using Kubernetes to achieve this, Next up we are going to take a look using Terraform with Kubernetes.
126
+
Ahora que hemos cubierto los contenedores y Kubernetes en detalle, probablemente sepamos que esto está bien para pruebas, pero si vamos a ejecutar un sitio web, no lo haríamos solo con contenedores y consideraríamos utilizar Kubernetes para lograr esto. A continuación, vamos a echar un vistazo a cómo utilizar Terraform con Kubernetes.
127
127
128
-
### Provisioners
128
+
### Provisionadores
129
129
130
-
Provisioners are there so that if something cannot be declarative we have a way in which to parse this to our deployment.
130
+
Los provisionadores están ahí para que, si algo no puede ser declarativo, tengamos una forma de enviar esto a nuestra implementación.
131
131
132
-
If you have no other alternative and adding this complexity to your code is the place to go then you can do this by running something similar to the following block of code.
132
+
Si no tienes otra alternativa y agregar esta complejidad a tu código es el camino a seguir, puedes hacerlo ejecutando algo similar al siguiente bloque de código.
The remote-exec provisioner invokes a script on a remote resource after it is created. This could be used for something OS-specific or it could be used to wrap in a configuration management tool. Although notice that we have some of these covered in their provisioners.
145
+
El provisionador `remote-exec` invoca un script en un recurso remoto después de que se crea. Esto podría usarse para algo específico del sistema operativo o podría usarse para envolver en una herramienta de gestión de configuración. Aunque debes tener en cuenta que algunos de estos ya están cubiertos en sus propios provisionadores.
146
146
147
-
[More details on provisioners](https://www.terraform.io/language/resources/provisioners/syntax)
147
+
[Más detalles de provisionadores](https://www.terraform.io/language/resources/provisioners/syntax)
148
148
149
149
- file
150
150
- local-exec
@@ -154,21 +154,21 @@ The remote-exec provisioner invokes a script on a remote resource after it is cr
154
154
- chef
155
155
- puppet
156
156
157
-
### Modules
157
+
### Módulos
158
158
159
-
Modules are containers for multiple resources that are used together. A module consists of a collection of .tf files in the same directory.
159
+
Los módulos son contenedores para múltiples recursos que se utilizan juntos. Un módulo consiste en una colección de archivos .tf en el mismo directorio.
160
160
161
-
Modules are a good way to separate your infrastructure resources as well as be able to pull in third-party modules that have already been created so you do not have to reinvent the wheel.
161
+
Los módulos son una buena forma de separar tus recursos de infraestructura, así como de poder utilizar módulos de terceros que ya han sido creados para no tener que reinventar la rueda.
162
162
163
-
For example, if we wanted to use the same project to build out some VMs, VPCs, Security Groups and then also a Kubernetes cluster we would likely want to split our resources out into modules to better define our resources and where they are grouped.
163
+
Por ejemplo, si queremos utilizar el mismo proyecto para crear algunas VM, VPC, grupos de seguridad y también un clúster de Kubernetes, probablemente querríamos dividir nuestros recursos en módulos para definir mejor nuestros recursos y dónde se agrupan.
164
164
165
-
Another benefit to modules is that you can take these modules and use them on other projects or share them publicly to help the community.
165
+
Otra ventaja de los módulos es que puedes tomar estos módulos y usarlos en otros proyectos o compartirlos públicamente para ayudar a la comunidad.
166
166
167
-
We are breaking down our infrastructure into components, components are known here as modules.
167
+
Estamos dividiendo nuestra infraestructura en componentes, y esos componentes se conocen aquí como módulos.
168
168
169
-
## Resources
169
+
## Recursos
170
170
171
-
I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
171
+
He enumerado muchos recursos a continuación y creo que este tema ha sido cubierto muchas veces, así que si tienes recursos adicionales, asegúrate de enviar una solicitud de extracción (PR) con tus recursos y estaré encantado de revisarlos y agregarlos a la lista.
172
172
173
173
-[What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
0 commit comments