|
| 1 | +# Desplegando la configuración base |
| 2 | + |
| 3 | +## AWS account |
| 4 | + |
| 5 | +Crear una nueva cuenta AWS |
| 6 | + |
| 7 | +## Pasos |
| 8 | + |
| 9 | +### Paso 1. Crear directory de trabajo |
| 10 | + |
| 11 | +Creamos los nuevos drirectorios `lab/lc_web_app` y dentro añadimo el fichero `main.tf` |
| 12 | + |
| 13 | +```bash |
| 14 | +mkdir -p lab/lc_web_app |
| 15 | +cp ./.start-app/main.tf ./lab/lc_web_app |
| 16 | +``` |
| 17 | + |
| 18 | +Cambiamos el directorio de trabajo a `lab/lc_web_app` |
| 19 | + |
| 20 | +```bash |
| 21 | +cd ./lab/lc_web_app |
| 22 | +``` |
| 23 | + |
| 24 | +### Paso 2. Actualizamos las crednciales |
| 25 | + |
| 26 | +Actualizar `access_key` y `secret_key` |
| 27 | + |
| 28 | +```diff |
| 29 | +provider "aws" { |
| 30 | ++ access_key = "ACCESS_KEY" |
| 31 | ++ secret_key = "SECRET_KEY" |
| 32 | + region = "eu-west-3" |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### Paso 3. Comenzar la inicialización |
| 37 | + |
| 38 | +```bash |
| 39 | +terraform init |
| 40 | +``` |
| 41 | + |
| 42 | +Obtendremos un output similar a este: |
| 43 | + |
| 44 | +``` |
| 45 | +Initializing the backend... |
| 46 | +
|
| 47 | +Initializing provider plugins... |
| 48 | +- Finding latest version of hashicorp/aws... |
| 49 | +- Installing hashicorp/aws v3.70.0... |
| 50 | +- Installed hashicorp/aws v3.70.0 (signed by HashiCorp) |
| 51 | +
|
| 52 | +Terraform has created a lock file .terraform.lock.hcl to record the provider |
| 53 | +selections it made above. Include this file in your version control repository |
| 54 | +so that Terraform can guarantee to make the same selections by default when |
| 55 | +you run "terraform init" in the future. |
| 56 | +
|
| 57 | +Terraform has been successfully initialized! |
| 58 | +
|
| 59 | +You may now begin working with Terraform. Try running "terraform plan" to see |
| 60 | +any changes that are required for your infrastructure. All Terraform commands |
| 61 | +should now work. |
| 62 | +
|
| 63 | +If you ever set or change modules or backend configuration for Terraform, |
| 64 | +rerun this command to reinitialize your working directory. If you forget, other |
| 65 | +commands will detect it and remind you to do so if necessary. |
| 66 | +``` |
| 67 | + |
| 68 | +### Paso 4. Obtener un Plan |
| 69 | + |
| 70 | +Ahora que nuestra configuración ha sido inicializada, podemos obtener un plan: |
| 71 | + |
| 72 | +```bash |
| 73 | +terraform plan -out d1.tfplan |
| 74 | +``` |
| 75 | + |
| 76 | +> Con este comando, estamos indicando que queremos el `plan` volcado sobre el fichero `d1.tfpplan` |
| 77 | +
|
| 78 | +Terraform nos indica las acciones que va a relizar. |
| 79 | + |
| 80 | +``` |
| 81 | +Plan: 7 to add, 0 to change, 0 to destroy. |
| 82 | +
|
| 83 | +────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
| 84 | +
|
| 85 | +Saved the plan to: d1.tfplan |
| 86 | +
|
| 87 | +To perform exactly these actions, run the following command to apply: |
| 88 | + terraform apply "d1.tfplan" |
| 89 | +
|
| 90 | +``` |
| 91 | + |
| 92 | +### Paso 5. Aplica el Plan |
| 93 | + |
| 94 | +```bash |
| 95 | +terraform apply "d1.tfplan" |
| 96 | +``` |
| 97 | + |
| 98 | +Si aplicamos este comando, sin alimentar un plan, nos mostrarán un diálogo de confirmación de plan previo. |
| 99 | + |
| 100 | +Después de unos minutos el despliegue finaliza, podemos acceder a la consola de AWS |
| 101 | + |
| 102 | +## Clean Up |
| 103 | + |
| 104 | +```bash |
| 105 | +terraform destroy |
| 106 | +``` |
0 commit comments